Skip to content

Commit f92b9df

Browse files
Merge pull request #1397 from DustinCampbell/use-debugger-events
Consume debugger events and notify OmniSharp
2 parents a26c09b + 61d761d commit f92b9df

File tree

4 files changed

+75
-41
lines changed

4 files changed

+75
-41
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
},
124124
{
125125
"description": "OmniSharp (.NET 4.6 / x86)",
126-
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.14.0.1.zip",
126+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x86-1.14.0.2.zip",
127127
"installPath": "./bin/omnisharp",
128128
"platforms": [
129129
"win32"
@@ -135,7 +135,7 @@
135135
},
136136
{
137137
"description": "OmniSharp (.NET 4.6 / x64)",
138-
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.14.0.1.zip",
138+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.14.0.2.zip",
139139
"installPath": "./bin/omnisharp",
140140
"platforms": [
141141
"win32"
@@ -147,7 +147,7 @@
147147
},
148148
{
149149
"description": "OmniSharp (Mono 4.6)",
150-
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-mono-1.14.0.1.zip",
150+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-mono-1.14.0.2.zip",
151151
"installPath": "./bin/omnisharp",
152152
"platforms": [
153153
"darwin",

src/features/dotnetTest.ts

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
132132
let outputChannel = getTestOutputChannel();
133133
outputChannel.appendLine(`Debugging method '${testMethod}'.`);
134134

135-
return serverUtils.requestProjectInformation(server, { FileName: fileName} )
135+
return serverUtils.requestProjectInformation(server, { FileName: fileName })
136136
.then(projectInfo => {
137137
if (projectInfo.DotNetProject) {
138138
debugType = "legacy";
@@ -147,9 +147,7 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
147147
throw new Error();
148148
}
149149
})
150-
.then(() => {
151-
return getLaunchConfiguration(server, debugType, fileName, testMethod, testFrameworkName, debugEventListener);
152-
})
150+
.then(() => getLaunchConfiguration(server, debugType, fileName, testMethod, testFrameworkName, debugEventListener))
153151
.then(config => vscode.commands.executeCommand('vscode.startDebug', config))
154152
.catch(reason => {
155153
vscode.window.showErrorMessage(`Failed to start debugger: ${reason}`);
@@ -182,13 +180,13 @@ export function updateCodeLensForTest(bucket: vscode.CodeLens[], fileName: strin
182180
}
183181

184182
class DebugEventListener {
185-
static s_activeInstance : DebugEventListener = null;
183+
static s_activeInstance: DebugEventListener = null;
186184
_fileName: string;
187185
_server: OmniSharpServer;
188-
_outputChannel : vscode.OutputChannel;
189-
_pipePath : string;
186+
_outputChannel: vscode.OutputChannel;
187+
_pipePath: string;
190188

191-
_serverSocket : net.Server;
189+
_serverSocket: net.Server;
192190
_isClosed: boolean = false;
193191

194192
constructor(fileName: string, server: OmniSharpServer, outputChannel: vscode.OutputChannel) {
@@ -204,38 +202,41 @@ class DebugEventListener {
204202
}
205203
}
206204

207-
public start() : Promise<void> {
205+
public start(): Promise<void> {
208206

209207
// We use our process id as part of the pipe name, so if we still somehow have an old instance running, close it.
210208
if (DebugEventListener.s_activeInstance !== null) {
211209
DebugEventListener.s_activeInstance.close();
212210
}
213211
DebugEventListener.s_activeInstance = this;
214-
212+
215213
this._serverSocket = net.createServer((socket: net.Socket) => {
216214
socket.on('data', (buffer: Buffer) => {
217-
218215
let event: DebuggerEventsProtocol.DebuggerEvent;
219216
try {
220217
event = DebuggerEventsProtocol.decodePacket(buffer);
221-
} catch (e) {
218+
}
219+
catch (e) {
222220
this._outputChannel.appendLine("Warning: Invalid event received from debugger");
223221
return;
224222
}
225-
226-
if (event.eventType === DebuggerEventsProtocol.EventType.ProcessLaunched) {
227-
let processLaunchedEvent = <DebuggerEventsProtocol.ProcessLaunchedEvent>(event);
228-
this._outputChannel.appendLine(`Started debugging process #${processLaunchedEvent.targetProcessId}.`);
229-
// TODO: provide the process id to OmniSharp
230-
serverUtils.debugTestRun(this._server, { FileName: this._fileName });
231-
} else if (event.eventType === DebuggerEventsProtocol.EventType.DebuggingStopped) {
232-
this._outputChannel.appendLine("Debugging complete.");
233-
this.fireDebuggingStopped();
223+
224+
switch (event.eventType) {
225+
case DebuggerEventsProtocol.EventType.ProcessLaunched:
226+
let processLaunchedEvent = <DebuggerEventsProtocol.ProcessLaunchedEvent>(event);
227+
this._outputChannel.appendLine(`Started debugging process #${processLaunchedEvent.targetProcessId}.`);
228+
this.onProcessLaunched(processLaunchedEvent.targetProcessId);
229+
break;
230+
231+
case DebuggerEventsProtocol.EventType.DebuggingStopped:
232+
this._outputChannel.appendLine("Debugging complete.\n");
233+
this.onDebuggingStopped();
234+
break;
234235
}
235236
});
236237

237238
socket.on('end', () => {
238-
this.fireDebuggingStopped();
239+
this.onDebuggingStopped();
239240
});
240241
});
241242

@@ -257,39 +258,62 @@ class DebugEventListener {
257258
});
258259
}
259260

260-
public pipePath() : string {
261+
public pipePath(): string {
261262
return this._pipePath;
262263
}
263264

264265
public close() {
265266
if (this === DebugEventListener.s_activeInstance) {
266267
DebugEventListener.s_activeInstance = null;
267268
}
269+
268270
if (this._isClosed) {
269271
return;
270272
}
273+
271274
this._isClosed = true;
272275

273276
if (this._serverSocket !== null) {
274277
this._serverSocket.close();
275278
}
276279
}
277280

278-
private fireDebuggingStopped() : void {
281+
private onProcessLaunched(targetProcessId: number): void {
282+
let request: protocol.V2.DebugTestLaunchRequest = {
283+
FileName: this._fileName,
284+
TargetProcessId: targetProcessId
285+
};
286+
287+
const disposable = this._server.onTestMessage(e => {
288+
this._outputChannel.appendLine(e.Message);
289+
});
290+
291+
serverUtils.debugTestLaunch(this._server, request)
292+
.then(_ => {
293+
disposable.dispose();
294+
});
295+
}
296+
297+
private onDebuggingStopped(): void {
279298
if (this._isClosed) {
280299
return;
281300
}
282-
283-
// TODO: notify omniSharp
301+
302+
let request: protocol.V2.DebugTestStopRequest = {
303+
FileName: this._fileName
304+
};
305+
306+
serverUtils.debugTestStop(this._server, request);
284307

285308
this.close();
286309
}
287310

288-
private removeSocketFileIfExists() : Promise<void> {
311+
private removeSocketFileIfExists(): Promise<void> {
289312
if (os.platform() === 'win32') {
290313
// Win32 doesn't use the file system for pipe names
291314
return Promise.resolve();
292-
} else {
315+
}
316+
else {
293317
return utils.deleteIfExists(this._pipePath);
294318
}
295319
}

src/omnisharp/protocol.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ export interface Request {
6767
Changes?: LinePositionSpanTextChange[];
6868
}
6969

70-
export interface GoToDefinitionRequest extends Request
71-
{
70+
export interface GoToDefinitionRequest extends Request {
7271
WantMetadata?: boolean;
7372
}
7473

75-
export interface FindImplementationsRequest extends Request
76-
{
74+
export interface FindImplementationsRequest extends Request {
7775
}
7876

7977
export interface LinePositionSpanTextChange {
@@ -422,7 +420,8 @@ export namespace V2 {
422420
export const GetTestStartInfo = '/v2/getteststartinfo';
423421
export const RunTest = '/v2/runtest';
424422
export const DebugTestGetStartInfo = '/v2/debugtest/getstartinfo';
425-
export const DebugTestRun = '/v2/debugtest/run';
423+
export const DebugTestLaunch = '/v2/debugtest/launch';
424+
export const DebugTestStop = '/v2/debugtest/stop';
426425
}
427426

428427
export interface Point {
@@ -510,10 +509,17 @@ export namespace V2 {
510509
EnvironmentVariables: Map<string, string>;
511510
}
512511

513-
export interface DebugTestRunRequest extends Request {
512+
export interface DebugTestLaunchRequest extends Request {
513+
TargetProcessId: number;
514514
}
515515

516-
export interface DebugTestRunResponse {
516+
export interface DebugTestLaunchResponse {
517+
}
518+
519+
export interface DebugTestStopRequest extends Request {
520+
}
521+
522+
export interface DebugTestStopResponse {
517523
}
518524

519525
export interface GetTestStartInfoRequest extends Request {

src/omnisharp/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import {OmniSharpServer} from './server';
8+
import { OmniSharpServer } from './server';
99
import * as protocol from './protocol';
1010
import * as vscode from 'vscode';
1111

@@ -97,8 +97,12 @@ export function debugTestGetStartInfo(server: OmniSharpServer, request: protocol
9797
return server.makeRequest<protocol.V2.DebugTestGetStartInfoResponse>(protocol.V2.Requests.DebugTestGetStartInfo, request);
9898
}
9999

100-
export function debugTestRun(server: OmniSharpServer, request: protocol.V2.DebugTestRunRequest) {
101-
return server.makeRequest<protocol.V2.DebugTestRunResponse>(protocol.V2.Requests.DebugTestRun, request);
100+
export function debugTestLaunch(server: OmniSharpServer, request: protocol.V2.DebugTestLaunchRequest) {
101+
return server.makeRequest<protocol.V2.DebugTestLaunchResponse>(protocol.V2.Requests.DebugTestLaunch, request);
102+
}
103+
104+
export function debugTestStop(server: OmniSharpServer, request: protocol.V2.DebugTestStopRequest) {
105+
return server.makeRequest<protocol.V2.DebugTestStopResponse>(protocol.V2.Requests.DebugTestStop, request);
102106
}
103107

104108
export function isNetCoreProject(project: protocol.MSBuildProject) {

0 commit comments

Comments
 (0)