Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ src/**
tsconfig.json
gulpfile.js
.gitignore
images/**
images/docs/**
testprojects/**
TestPlan.md
.github/**
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
- `java.debug.settings.showQualifiedNames`: show fully qualified class names in "Variables" viewlet, defaults to `false`.
- `java.debug.settings.showLogicalStructure`: show the logical structure for the Collection and Map classes in "Variables" viewlet, defaults to `true`.
- `java.debug.settings.maxStringLength`: the maximum length of string displayed in "Variables" or "Debug Console" viewlet, the string longer than this length will be trimmed, defaults to `0` which means no trim is performed.
- `java.debug.settings.enableHotCodeReplace`: enable hot code replace for Java code. Make sure the auto build is not disabled for [VSCode Java](https://github.com/redhat-developer/vscode-java). See the [wiki page](https://github.com/Microsoft/vscode-java-debug/wiki/Hot-Code-Replace) for more information about usages and limitations.
- `java.debug.settings.hotCodeReplace`: Reload the changed Java classes during debugging, defaults to `manual`. Make sure `java.autobuild.enabled` is not disabled for [VSCode Java](https://github.com/redhat-developer/vscode-java). See the [wiki page](https://github.com/Microsoft/vscode-java-debug/wiki/Hot-Code-Replace) for more information about usages and limitations.
- manual - Click the toolbar to apply the changes.
- auto - Automatically apply the changes after compilation.
- never - Never apply the changes.
- `java.debug.settings.enableRunDebugCodeLens`: enable the code lens provider for the run and debug buttons over main entry points, defaults to `true`.
- `java.debug.settings.forceBuildBeforeLaunch`: force building the workspace before launching java program, defaults to `true`.

Expand Down
35 changes: 24 additions & 11 deletions TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,33 @@ anonymous

1. Open project `19.java9-app` in vscode.
2. Follow gif to verify step filters feature.
![stepfilter](images/33868694-673f14b0-df3f-11e7-9983-b3cff5842020.gif)
![stepfilter](images/docs/33868694-673f14b0-df3f-11e7-9983-b3cff5842020.gif)

The new gif:
![stepfilters](images/34507770-69597114-f074-11e7-8f32-027ad1d7a4fd.gif)
![stepfilters](images/docs/34507770-69597114-f074-11e7-8f32-027ad1d7a4fd.gif)

## Hot Code Replace

- Manually trigger hot code replace
1. Open project `24.hotCodeReplace` in vscode.
2. Set breakpoints: NameProvider.java line 12; Person.java line 13
2. Set breakpoints: NameProvider.java line 12; Person.java line 13.
3. Press `F5` to start debug.
4. The program stopped at the Person.java line 13
5. Change the value of the line "old" to "new"
5. Save the document to trigger HCR. Check the breakpoint will stop at line 12
6. Click F10 to step over, check the value of `res` on the debug view of local variable which should be `new`
4. The program stopped at the Person.java line 13.
5. Change the value of the line "old" to "new", and save the document.
6. Click the "Hot Code Replace" icon in the debug toolbar to trigger HCR. Check the breakpoint will stop at line 12 .
7. Click F10 to step over, check the value of `res` on the debug view of local variable which should be `new`.

- Automatically trigger hot code replace
1. Repeat step 1 ~ 4 above.
2. Change `java.debug.settings.hotCodeReplace` to `auto`.
3. Change the value of the line "old" to "new", and save the document.
4. HCR will be automatically triggered. Check the breakpoint will stop at line 12 .
5. Click F10 to step over, check the value of `res` on the debug view of local variable which should be `new`.

- Disable hot code replace
1. Repeat step 1 ~ 4 above.
2. Change `java.debug.settings.hotCodeReplace` to `never`.
3. Change the value of the line "old" to "new", and save the document.
4. Click F10 to step over, check the value of `res` on the debug view of local variable which should be `old`.

## Conditional Breakpoints

Expand Down Expand Up @@ -342,7 +355,7 @@ public class App

2. set conditional breakpoint on line 13 with condition `i ==1000`, F5 and wait the breakpoint to be hit

![java-conditional-bp-demo](images/37269785-0ffef8e6-2607-11e8-955f-93548ad5a0ad.gif)
![java-conditional-bp-demo](images/docs/37269785-0ffef8e6-2607-11e8-955f-93548ad5a0ad.gif)

3. verify i equals 1000 in variable window.
4. F5 and wait for program to exit.
Expand Down Expand Up @@ -406,7 +419,7 @@ Exception in thread "main" java.lang.IllegalStateException
2. Launch java debugger and continue your program.
3. When the logpoint code branch is hit, it just log the message to the console and doesn't stop your program.

![logpoint](images/41949312-77627a40-79f3-11e8-9fd2-def4fa06e28d.gif)
![logpoint](images/docs/41949312-77627a40-79f3-11e8-9fd2-def4fa06e28d.gif)


## Start without debugging
Expand Down Expand Up @@ -472,7 +485,7 @@ Exception in thread "main" java.lang.IllegalStateException
```
4. Press F5 to verify the variables should be like this:

![args](images/args.PNG)
![args](images/docs/args.PNG)

## Classpath shortener for long classpath project
1. Open `longclasspath` project in VS Code.
Expand Down
2 changes: 1 addition & 1 deletion Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This error indicates you are doing `Hot Code Replace`. The `Hot Code Replace` fe

### Try:
1. Restart your application to apply the new changes. Or ignore the message, and continue to debug.
2. You can disable the hot code replace feature by changing the user setting `"java.debug.settings.enableHotCodeReplace": false`.
2. You can disable the hot code replace feature by changing the user setting `"java.debug.settings.hotCodeReplace": "never"`.

## Please specify the host name and the port of the remote debuggee in the launch.json.
### Reason:
Expand Down
13 changes: 13 additions & 0 deletions images/commands/hot_code_replace.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
41 changes: 35 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"debugger"
],
"engines": {
"vscode": "^1.22.0"
"vscode": "^1.32.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the features introduced in vscode for additional icons in debug toolbar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, 1.32 add the support to extend the debug toolbar buttons.

},
"license": "SEE LICENSE IN LICENSE.txt",
"repository": {
Expand All @@ -41,7 +41,31 @@
"javaExtensions": [
"./server/com.microsoft.java.debug.plugin-0.18.0.jar"
],
"commands": [],
"commands": [
{
"command": "java.debug.hotCodeReplace",
"title": "Hot Code Replace",
"icon": {
"dark": "images/commands/hot_code_replace.svg",
"light": "images/commands/hot_code_replace.svg"
}
}
],
"menus": {
"debug/toolBar": [
{
"command": "java.debug.hotCodeReplace",
"group": "navigation@100",
"when": "inDebugMode && debugType == java && javaHotReload == 'manual'"
}
],
"commandPalette": [
{
"command": "java.debug.hotCodeReplace",
"when": "false"
}
]
},
"debuggers": [
{
"type": "java",
Expand Down Expand Up @@ -409,10 +433,15 @@
"description": "%java.debugger.configuration.maxStringLength.description%",
"default": 0
},
"java.debug.settings.enableHotCodeReplace": {
"type": "boolean",
"description": "%java.debugger.configuration.enableHotCodeReplace.description%",
"default": true
"java.debug.settings.hotCodeReplace": {
"type": "string",
"default": "manual",
"description": "%java.debugger.configuration.hotCodeReplace.description%",
"enum": [
"auto",
"manual",
"never"
]
},
"java.debug.settings.enableRunDebugCodeLens": {
"type": "boolean",
Expand Down
1 change: 0 additions & 1 deletion package.nls.it.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"java.debugger.configuration.showStaticVariables.description": "Mostra variabili statiche nella scheda \"variabili\".",
"java.debugger.configuration.showQualifiedNames.description": "Mostra nome completo delle classi nella scheda \"variabili\".",
"java.debugger.configuration.maxStringLength.description": "Lunghezza massima delle stringhe visualizzate nella scheda \"Variabili\" o \"Console di Debug\", stringhe più lunghe di questo numero verranno tagliate, se 0 nessun taglio viene eseguito.",
"java.debugger.configuration.enableHotCodeReplace.description": "Attiva sostituzione hotcode per codice Java.",
"java.debugger.configuration.enableRunDebugCodeLens.description": "Abilitare i provider di lenti di codice run e debug sui metodi principali."
}
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"java.debugger.configuration.showQualifiedNames.description": "Show fully qualified class names in \"Variables\" viewlet.",
"java.debugger.configuration.showLogicalStructure.description": "Show the logical structure for the Collection and Map classes in \"Variables\" viewlet.",
"java.debugger.configuration.maxStringLength.description": "The maximum length of strings displayed in \"Variables\" or \"Debug Console\" viewlet, strings longer than this length will be trimmed, if 0 no trim is performed.",
"java.debugger.configuration.enableHotCodeReplace.description": "Enable hot code replace for Java code.",
"java.debugger.configuration.hotCodeReplace.description": "Reload the changed Java classes during debugging. Make sure 'java.autobuild.enabled' is not disabled.",
"java.debugger.configuration.enableRunDebugCodeLens.description": "Enable the run and debug code lens providers over main methods.",
"java.debugger.configuration.forceBuildBeforeLaunch": "Force building the workspace before launching java program."
}
2 changes: 1 addition & 1 deletion package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"java.debugger.configuration.showQualifiedNames.description": "在“变量”视图中显示类的全名。",
"java.debugger.configuration.showLogicalStructure.description": "在“变量”视图中显示Collection和Map类的逻辑结构。",
"java.debugger.configuration.maxStringLength.description": "设定“变量”或“调试控制台”视图中显示的字符串最大长度,长度超过部分将被剪掉。如果值为0,则不执行修剪。",
"java.debugger.configuration.enableHotCodeReplace.description": "为Java代码启用热代码替换。",
"java.debugger.configuration.hotCodeReplace.description": "在调试期间重新加载已更改的Java类。确保未禁用'java.autobuild.enabled'。",
"java.debugger.configuration.enableRunDebugCodeLens.description": "在main方法上启用CodeLens标记。",
"java.debugger.configuration.forceBuildBeforeLaunch": "在启动java程序之前强制编译整个工作空间。"
}
24 changes: 23 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as path from "path";
import * as vscode from "vscode";
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
import * as commands from "./commands";
Expand Down Expand Up @@ -49,6 +48,29 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte
context.subscriptions.push(instrumentAndRegisterCommand("JavaDebug.SpecifyProgramArgs", async () => {
return specifyProgramArguments(context);
}));
context.subscriptions.push(instrumentAndRegisterCommand("java.debug.hotCodeReplace", async (args: any) => {
const autobuildConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("java.autobuild");
if (!autobuildConfig.enabled) {
const ans = await vscode.window.showWarningMessage(
"The hot code replace feature requires you to enable the autobuild flag, do you want to enable it?",
"Yes", "No");
if (ans === "Yes") {
await autobuildConfig.update("enabled", true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen after enable it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current hcr doesn't take effect, you need click again.

} else {
return;
}
}

const debugSession: vscode.DebugSession = vscode.debug.activeDebugSession;
if (!debugSession) {
return;
}

return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (progress) => {
progress.report({ message: "Applying code changes..." });
return await debugSession.customRequest("redefineClasses");
});
}));
initializeHotCodeReplace(context);
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((customEvent) => {
const t = customEvent.session ? customEvent.session.type : undefined;
Expand Down
22 changes: 17 additions & 5 deletions src/hotCodeReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as vscode from "vscode";

import * as anchor from "./anchor";
import { HCR_EVENT, JAVA_LANGID } from "./constants";
import { JAVA_LANGID } from "./constants";
import * as utility from "./utility";

const suppressedReasons: Set<string> = new Set();
Expand All @@ -24,6 +24,12 @@ enum HcrChangeType {
}

export function initializeHotCodeReplace(context: vscode.ExtensionContext) {
vscode.commands.executeCommand("setContext", "javaHotReload", getHotReloadFlag());
vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("java.debug.settings.hotCodeReplace")) {
vscode.commands.executeCommand("setContext", "javaHotReload", getHotReloadFlag());
}
});
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((session) => {
const t = session ? session.type : undefined;
if (t === JAVA_LANGID) {
Expand All @@ -34,10 +40,12 @@ export function initializeHotCodeReplace(context: vscode.ExtensionContext) {

export function handleHotCodeReplaceCustomEvent(hcrEvent) {
if (hcrEvent.body.changeType === HcrChangeType.BUILD_COMPLETE) {
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (progress) => {
progress.report({ message: "Applying code changes..." });
return hcrEvent.session.customRequest("redefineClasses");
});
if (getHotReloadFlag() === "auto") {
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (progress) => {
progress.report({ message: "Applying code changes..." });
return hcrEvent.session.customRequest("redefineClasses");
});
}
}

if (hcrEvent.body.changeType === HcrChangeType.ERROR || hcrEvent.body.changeType === HcrChangeType.WARNING) {
Expand All @@ -55,3 +63,7 @@ export function handleHotCodeReplaceCustomEvent(hcrEvent) {
}
}
}

function getHotReloadFlag(): string {
return vscode.workspace.getConfiguration("java.debug.settings").get("hotCodeReplace") || "manual";
}