Skip to content

Commit

Permalink
support for launching command in frontend; fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Aug 23, 2016
1 parent 848947f commit f0fccbf
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-debugadapter",
"description": "Debug adapter implementation for node",
"version": "1.11.0",
"version": "1.12.0-pre.1",
"author": "Microsoft Corporation",
"license": "MIT",
"repository": {
Expand All @@ -14,7 +14,7 @@
"main": "./lib/main.js",
"typings": "./lib/main",
"dependencies": {
"vscode-debugprotocol": "^1.11.0"
"vscode-debugprotocol": "^1.12.0-pre.2"
},
"devDependencies": {
"typescript": "^1.8.5"
Expand Down
4 changes: 4 additions & 0 deletions adapter/src/debugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ export class DebugSession extends ProtocolServer {
this.sendResponse(response);
}

public runInTerminalRequest(args: DebugProtocol.RunInTerminalRequestArguments, timeout: number, cb: (response: DebugProtocol.RunInTerminalResponse) => void) {
this.sendRequest('runInTerminal', args, timeout, cb);
}

protected dispatchRequest(request: DebugProtocol.Request): void {

const response = new Response(request);
Expand Down
38 changes: 38 additions & 0 deletions adapter/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ProtocolServer extends ee.EventEmitter {
private _contentLength: number;
private _sequence: number;
private _writableStream: NodeJS.WritableStream;
private _pendingRequests = new Map<number, (response: DebugProtocol.Response) => void>();

constructor() {
super();
Expand Down Expand Up @@ -60,6 +61,36 @@ export class ProtocolServer extends ee.EventEmitter {
}
}

public sendRequest(command: string, args: any, timeout: number, cb: (response: DebugProtocol.Response) => void) : void {

const request: any = {
command: command
};
if (args && Object.keys(args).length > 0) {
request.arguments = args;
}

if (!this._writableStream) {
this._emitEvent(new Event('error'));
return;
}

this._send('request', request);

if (cb) {
this._pendingRequests.set(request.seq, cb);

const timer = setTimeout(() => {
clearTimeout(timer);
const clb = this._pendingRequests.get(request.seq);
if (clb) {
this._pendingRequests.delete(request.seq);
clb(new Response(request, 'timeout'));
}
}, timeout);
}
}

// ---- protected ----------------------------------------------------------

protected dispatchRequest(request: DebugProtocol.Request): void {
Expand Down Expand Up @@ -97,6 +128,13 @@ export class ProtocolServer extends ee.EventEmitter {
let msg: DebugProtocol.ProtocolMessage = JSON.parse(message);
if (msg.type === 'request') {
this.dispatchRequest(<DebugProtocol.Request> msg);
} else if (msg.type === 'response') {
const response = <DebugProtocol.Response> msg;
const clb = this._pendingRequests.get(response.request_seq);
if (clb) {
this._pendingRequests.delete(response.request_seq);
clb(response);
}
}
}
catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This npm module contains declarations for the json-based Visual Studio Code debu

## History

* 1.12.x:
* Adds a new optional attribute `frameId` to the `completionRequest`.
* Introduces a `runInTerminalRequest` so that a debug adapter can run a debuggee in a terminal managed by the frontend.

* 1.11.x:
* Adds a new optional attribute `mimeType` to the `SourceResponse`.
* Adds a new optional attribute `sourceModified` to the `SetBreakpointsArguments` that indicates that the underlying source has been modified which results in new breakpoint locations.
Expand Down
2 changes: 1 addition & 1 deletion protocol/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-debugprotocol",
"description": "Npm module with declarations for the Visual Studio Code debug protocol",
"version": "1.11.0",
"version": "1.12.0-pre.2",
"author": "Microsoft Corporation",
"license": "MIT",
"repository": {
Expand Down
35 changes: 34 additions & 1 deletion protocol/src/debugProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,36 @@ export module DebugProtocol {
}
}

//---- Requests
//---- Frontend Requests

/** runInTerminal request; value of command field is "runInTerminal".
With this request a debug adapter can run a command in a terminal.
*/
export interface RunInTerminalRequest extends Request {
arguments: RunInTerminalRequestArguments;
}
/** Arguments for "runInTerminal" request. */
export interface RunInTerminalRequestArguments {
/** What kind of terminal to launch. */
kind?: 'integrated' | 'external';
/** Optional title of the terminal. */
title?: string;
/** Working directory of the command. */
cwd: string;
/** List of arguments. The first argument is the command to run. */
args: string[];
/** Environment key-value pairs that are added to the default environment. */
env?: { [key: string]: string; }
}
/** Response to Initialize request. */
export interface RunInTerminalResponse extends Response {
body: {
/** The process ID */
processId?: number;
};
}

//---- Debug Adapter Requests

/** On error that is whenever 'success' is false, the body can provide more details.
*/
Expand Down Expand Up @@ -198,6 +227,8 @@ export module DebugProtocol {
supportsVariableType?: boolean;
/** Client supports the paging of variables. */
supportsVariablePaging?: boolean;
/** Client supports the runInTerminal request. */
supportsRunInTerminalRequest?: boolean;
}
/** Response to Initialize request. */
export interface InitializeResponse extends Response {
Expand Down Expand Up @@ -710,6 +741,8 @@ export module DebugProtocol {
}
/** Arguments for "completions" request. */
export interface CompletionsArguments {
/** Returns completions in the scope of this stack frame. If not specified, the completions are returned for the global scope. */
frameId?: number;
/** One or more source lines. Typically this is the text a user has typed into the debug console before he asked for completion. */
text: string;
/** The character position for which to determine the completion proposals. */
Expand Down
4 changes: 2 additions & 2 deletions testSupport/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-debugadapter-testsupport",
"description": "Npm module with mocha test support for Visual Studio Code debug adapters",
"version": "1.11.0",
"version": "1.12.0-pre.0",
"author": "Microsoft Corporation",
"license": "MIT",
"repository": {
Expand All @@ -14,7 +14,7 @@
"main": "./lib/main.js",
"typings": "./lib/main",
"dependencies": {
"vscode-debugprotocol": "^1.11.0"
"vscode-debugprotocol": "^1.12.0-pre.0"
},
"devDependencies": {
"typescript": "^1.8.5"
Expand Down

0 comments on commit f0fccbf

Please sign in to comment.