Skip to content

Commit

Permalink
[GR-18036] VSCode: duplicated debug output in console.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalek committed Sep 9, 2019
1 parent ef4ac89 commit d20dbcf
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ public void testReturnValue() throws Exception {
"{\"method\":\"Debugger.resumed\"}\n"));
// And check the result value printed out
tester.receiveMessages(
"{\"method\":\"Runtime.consoleAPICalled\",\"params\":{\"args\":[{\"type\":\"string\",\"value\":\"30000000000\\n\"}],\"executionContextId\":" + id + ",\"type\":\"log\",\"timestamp\":",
"{\"method\":\"Runtime.consoleAPICalled\",\"params\":{\"args\":[{\"type\":\"string\",\"value\":\"30000000000\"}],\"executionContextId\":" + id + ",\"type\":\"log\",\"timestamp\":",
"}}\n");
tester.finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ private class ConsoleOutputListener implements OutputHandler.Listener {

@Override
public void outputText(String str) {
notifyConsoleAPICalled(type, str);
notifyConsoleAPICalled(type, str.endsWith("\n") ? str.substring(0, str.length() - 1) : str);
}

}
Expand Down
16 changes: 8 additions & 8 deletions vscode/graalvm/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"name": "Run Debug Adapter",
"program": "${workspaceFolder}/src/graalVMDebug.ts",
"runtimeExecutable": "${execPath}",
"args": [
"--server=4711"
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Run Extension",
"type": "extensionHost",
"type": "node",
"request": "launch",
"runtimeExecutable": "${execPath}",
"name": "Run Debug Adapter",
"program": "${workspaceFolder}/src/graalVMDebug.ts",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
"--server=4711"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
Expand Down
9 changes: 9 additions & 0 deletions vscode/graalvm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
"description": "Where to launch the debug target: internal console, or integrated terminal.",
"default": "internalConsole"
},
"outputCapture": {
"enum": [
"console",
"std"
],
"description": "From where to capture output messages: The debug API, or stdout/stderr streams.",
"default": "console"
},
"cwd": {
"type": "string",
"description": "Absolute path to the working directory of the program being debugged.",
Expand Down Expand Up @@ -212,6 +220,7 @@
"type": "graalvm",
"request": "launch",
"name": "Launch Node App",
"outputCapture": "std",
"program": "^\"\\${workspaceFolder}/${1:app.js}\""
}
},
Expand Down
22 changes: 16 additions & 6 deletions vscode/graalvm/src/graalVMDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/

import { ChromeDebugAdapter, ErrorWithMessage, logger } from 'vscode-chrome-debug-core';
import { ChromeDebugAdapter, Crdp, ErrorWithMessage, logger } from 'vscode-chrome-debug-core';
import { DebugProtocol } from 'vscode-debugprotocol';
import { OutputEvent } from 'vscode-debugadapter';

Expand All @@ -22,6 +22,8 @@ export class GraalVMDebugAdapter extends ChromeDebugAdapter {

private _childProcessId: number = 0;
private _supportsRunInTerminalRequest: boolean | undefined;
private _lastEarlyNodeMsgSeen: boolean | undefined;
private _captureStdOutput: boolean | undefined;

public initialize(args: DebugProtocol.InitializeRequestArguments): DebugProtocol.Capabilities {
this._supportsRunInTerminalRequest = args.supportsRunInTerminalRequest;
Expand Down Expand Up @@ -106,6 +108,8 @@ export class GraalVMDebugAdapter extends ChromeDebugAdapter {

launchArgs = runtimeArgs.concat(launchArgs, program ? [program] : [], programArgs);

this._captureStdOutput = args.outputCapture === 'std';

if (args.console === 'integratedTerminal' && this._supportsRunInTerminalRequest) {
const termArgs: DebugProtocol.RunInTerminalRequestArguments = {
kind: args.console === 'integratedTerminal' ? 'integrated' : 'external',
Expand Down Expand Up @@ -215,30 +219,36 @@ export class GraalVMDebugAdapter extends ChromeDebugAdapter {
});
const noDebugMode = (<ILaunchRequestArguments>this._launchAttachArgs).noDebug;
childProcess.stdout.on('data', (data: string) => {
if (!this._launchAttachArgs._suppressConsoleOutput) {
if ((noDebugMode || this._captureStdOutput) && !this._launchAttachArgs._suppressConsoleOutput) {
let msg = data.toString();
this._session.sendEvent(new OutputEvent(msg, 'stdout'));
}
});
childProcess.stderr.on('data', (data: string) => {
let msg = data.toString();
let lastEarlyNodeMsgSeen = noDebugMode;
if (!lastEarlyNodeMsgSeen) {
if (!this._lastEarlyNodeMsgSeen && !noDebugMode) {
msg = msg.replace(/^\s*To start debugging, open the following URL in Chrome:\s*$/m, '');
let regExp = /^\s*chrome-devtools:\/\/devtools\/bundled\/js_app\.html\?ws=\S*\s*$/m;
if (msg.match(regExp)) {
msg = msg.replace(regExp, '');
lastEarlyNodeMsgSeen = true;
this._lastEarlyNodeMsgSeen = true;
}
}
if (!this._launchAttachArgs._suppressConsoleOutput) {
if ((noDebugMode || this._captureStdOutput) && !this._launchAttachArgs._suppressConsoleOutput) {
this._session.sendEvent(new OutputEvent(msg, 'stderr'));
}
});
resolve();
});
}

protected onConsoleAPICalled(params: Crdp.Runtime.ConsoleAPICalledEvent): void {
this._lastEarlyNodeMsgSeen = true;
if (!this._captureStdOutput) {
super.onConsoleAPICalled(params);
}
}

private logLaunchCommand(executable: string, args: string[]) {
let cli = executable + ' ';
for (let a of args) {
Expand Down
3 changes: 3 additions & 0 deletions vscode/graalvm/src/graalVMDebugInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import * as Core from 'vscode-chrome-debug-core';

type ConsoleType = 'internalConsole' | 'integratedTerminal';
type OutputCaptureType = 'console' | 'std';

export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
/** TCP/IP address of process to be debugged. Default is 'localhost'. */
Expand All @@ -31,6 +32,8 @@ export interface ILaunchRequestArguments extends Core.ILaunchRequestArgs, ICommo
console?: ConsoleType;
/** Manually selected debugging port */
port?: number;
/** Source of the debug output */
outputCapture?: OutputCaptureType;
/** Optional path to GraalVM home directory. */
graalVMHome?: string;
}
Expand Down

0 comments on commit d20dbcf

Please sign in to comment.