Skip to content

Commit 05ca5e2

Browse files
committed
Implement client side of test debugging
1 parent 170e039 commit 05ca5e2

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ export class RoslynLanguageServer {
207207

208208
// Register Razor dynamic file info handling
209209
this.registerDynamicFileInfo(this._languageClient);
210+
211+
this.registerDebuggerAttach(this._languageClient);
210212
}
211213

212214
public async stop(): Promise<void> {
@@ -488,6 +490,25 @@ export class RoslynLanguageServer {
488490
);
489491
}
490492

493+
private registerDebuggerAttach(client: RoslynLanguageClient) {
494+
client.onRequest<RoslynProtocol.DebugAttachParams, RoslynProtocol.DebugAttachResult, void>(
495+
RoslynProtocol.DebugAttachRequest.type,
496+
async (request) => {
497+
const debugConfiguration: vscode.DebugConfiguration = {
498+
name: '.NET Core Attach',
499+
type: 'coreclr',
500+
request: 'attach',
501+
processId: request.processId,
502+
};
503+
504+
const result = await vscode.debug.startDebugging(undefined, debugConfiguration, undefined);
505+
return {
506+
didAttach: result,
507+
};
508+
}
509+
);
510+
}
511+
491512
private registerExtensionsChanged(languageClient: RoslynLanguageClient) {
492513
// subscribe to extension change events so that we can get notified if C# Dev Kit is added/removed later.
493514
languageClient.addDisposable(

src/lsptoolshost/roslynProtocol.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export interface RunTestsParams extends lsp.WorkDoneProgressParams, lsp.PartialR
7676
* Note that this does not have to only include tests, for example this could be a range representing a class.
7777
*/
7878
range: lsp.Range;
79+
80+
/**
81+
* Whether the request should attempt to call back to the client to attach a debugger before running the tests.
82+
*/
83+
attachDebugger: boolean;
7984
}
8085

8186
export interface TestProgress {
@@ -103,6 +108,14 @@ export interface RunTestsPartialResult {
103108
progress?: TestProgress;
104109
}
105110

111+
export interface DebugAttachParams {
112+
processId: number;
113+
}
114+
115+
export interface DebugAttachResult {
116+
didAttach: boolean;
117+
}
118+
106119
export namespace WorkspaceDebugConfigurationRequest {
107120
export const method = 'workspace/debugConfiguration';
108121
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
@@ -140,3 +153,9 @@ export namespace RunTestsRequest {
140153
void
141154
>(method);
142155
}
156+
157+
export namespace DebugAttachRequest {
158+
export const method = 'workspace/attachDebugger';
159+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
160+
export const type = new lsp.RequestType<DebugAttachParams, DebugAttachResult, void>(method);
161+
}

src/lsptoolshost/unitTesting.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,31 @@ export function registerUnitTestingCommands(
2121
context.subscriptions.push(
2222
vscode.commands.registerTextEditorCommand(
2323
'dotnet.test.runTestsInContext',
24-
async (textEditor: vscode.TextEditor) => runTestsInContext(textEditor, languageServer, dotnetTestChannel)
24+
async (textEditor: vscode.TextEditor) => {
25+
return runTestsInContext(false, textEditor, languageServer, dotnetTestChannel);
26+
}
27+
)
28+
);
29+
30+
context.subscriptions.push(
31+
vscode.commands.registerTextEditorCommand(
32+
'dotnet.test.debugTestsInContext',
33+
async (textEditor: vscode.TextEditor) => {
34+
return runTestsInContext(true, textEditor, languageServer, dotnetTestChannel);
35+
}
2536
)
2637
);
2738
}
2839

2940
async function runTestsInContext(
41+
debug: boolean,
3042
textEditor: vscode.TextEditor,
3143
languageServer: RoslynLanguageServer,
3244
dotnetTestChannel: vscode.OutputChannel
3345
) {
3446
const contextRange: languageClient.Range = { start: textEditor.selection.active, end: textEditor.selection.active };
3547
const textDocument: languageClient.TextDocumentIdentifier = { uri: textEditor.document.fileName };
36-
const request: RunTestsParams = { textDocument: textDocument, range: contextRange };
48+
const request: RunTestsParams = { textDocument: textDocument, range: contextRange, attachDebugger: debug };
3749
await runTests(request, languageServer, dotnetTestChannel);
3850
}
3951

0 commit comments

Comments
 (0)