Skip to content

Commit 2d1e6cb

Browse files
authored
Merge pull request #5897 from dibarbet/unit_testing
Implement client side code for run tests command
2 parents f62d8f1 + a1f4c9a commit 2d1e6cb

File tree

6 files changed

+233
-30
lines changed

6 files changed

+233
-30
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
},
3838
"defaults": {
39-
"roslyn": "4.8.0-1.23367.7",
39+
"roslyn": "4.8.0-1.23369.14",
4040
"omniSharp": "1.39.7",
4141
"razor": "7.0.0-preview.23328.2",
4242
"razorOmnisharp": "7.0.0-preview.23363.1"
@@ -92,6 +92,7 @@
9292
"strip-bom": "5.0.0",
9393
"strip-bom-buf": "2.0.0",
9494
"tmp": "0.0.33",
95+
"uuid": "^9.0.0",
9596
"vscode-html-languageservice": "^5.0.1",
9697
"vscode-js-debug-browsers": "^1.0.5",
9798
"vscode-jsonrpc": "8.2.0-next.0",
@@ -115,6 +116,7 @@
115116
"@types/node": "16.11.38",
116117
"@types/semver": "5.5.0",
117118
"@types/tmp": "0.0.33",
119+
"@types/uuid": "^9.0.1",
118120
"@types/unzipper": "^0.9.1",
119121
"@types/vscode": "1.69.0",
120122
"@types/yauzl": "2.10.0",

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
77
import * as fs from 'fs';
88
import * as path from 'path';
99
import * as cp from 'child_process';
10+
import * as uuid from 'uuid';
1011
import { registerCommands } from './commands';
1112
import { registerDebugger } from './debugger';
1213
import { UriConverter } from './uriConverter';
@@ -36,6 +37,8 @@ import {
3637
CompletionRequest,
3738
CompletionResolveRequest,
3839
CompletionItem,
40+
PartialResultParams,
41+
ProtocolRequestType,
3942
} from 'vscode-languageclient/node';
4043
import { PlatformInformation } from '../shared/platform';
4144
import { readConfigurations } from './configurationMiddleware';
@@ -57,6 +60,7 @@ import { randomUUID } from 'crypto';
5760
import { DotnetRuntimeExtensionResolver } from './dotnetRuntimeExtensionResolver';
5861
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
5962
import { RoslynLanguageClient } from './roslynLanguageClient';
63+
import { registerUnitTestingCommands } from './unitTesting';
6064

6165
let _languageServer: RoslynLanguageServer;
6266
let _channel: vscode.OutputChannel;
@@ -269,6 +273,28 @@ export class RoslynLanguageServer {
269273
return response;
270274
}
271275

276+
public async sendRequestWithProgress<P extends PartialResultParams, R, PR, E, RO>(
277+
type: ProtocolRequestType<P, R, PR, E, RO>,
278+
params: P,
279+
onProgress: (p: PR) => Promise<any>,
280+
cancellationToken?: vscode.CancellationToken
281+
): Promise<R> {
282+
if (!this._languageClient) {
283+
throw new Error('Tried to send request while server is not started.');
284+
}
285+
// Generate a UUID for our partial result token and apply it to our request.
286+
const partialResultToken: string = uuid.v4();
287+
params.partialResultToken = partialResultToken;
288+
// Register the callback for progress events.
289+
const disposable = this._languageClient.onProgress(type, partialResultToken, async (partialResult) => {
290+
await onProgress(partialResult);
291+
});
292+
const response = await this._languageClient
293+
.sendRequest(type, params, cancellationToken)
294+
.finally(() => disposable.dispose());
295+
return response;
296+
}
297+
272298
/**
273299
* Sends an LSP notification to the server with a given method and parameters.
274300
*/
@@ -425,6 +451,8 @@ export class RoslynLanguageServer {
425451
// shouldn't this arg only be set if it's running with CSDevKit?
426452
args.push('--telemetryLevel', this.telemetryReporter.telemetryLevel);
427453

454+
args.push('--extensionLogDirectory', this.context.logUri.fsPath);
455+
428456
let childProcess: cp.ChildProcessWithoutNullStreams;
429457
const cpOptions: cp.SpawnOptionsWithoutStdio = {
430458
detached: true,
@@ -591,6 +619,7 @@ export async function activateRoslynLanguageServer(
591619
platformInfo: PlatformInformation,
592620
optionProvider: OptionProvider,
593621
outputChannel: vscode.OutputChannel,
622+
dotnetTestChannel: vscode.OutputChannel,
594623
reporter: TelemetryReporter
595624
) {
596625
// Create a channel for outputting general logs from the language server.
@@ -606,6 +635,8 @@ export async function activateRoslynLanguageServer(
606635

607636
registerRazorCommands(context, _languageServer);
608637

638+
registerUnitTestingCommands(context, _languageServer, dotnetTestChannel);
639+
609640
// Register any needed debugger components that need to communicate with the language server.
610641
registerDebugger(context, _languageServer, platformInfo, optionProvider, _channel);
611642

src/lsptoolshost/roslynProtocol.ts

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import {
7-
FormattingOptions,
8-
InsertTextFormat,
9-
MessageDirection,
10-
NotificationType,
11-
Position,
12-
RequestType,
13-
RequestType0,
14-
TextDocumentIdentifier,
15-
TextEdit,
16-
URI,
17-
integer,
18-
} from 'vscode-languageserver-protocol';
6+
import * as lsp from 'vscode-languageserver-protocol';
197

208
export interface WorkspaceDebugConfigurationParams {
219
/**
2210
* Workspace path containing the solution/projects to get debug information for.
2311
* This will be important eventually for multi-workspace support.
2412
* If not provided, configurations are returned for the workspace the server was initialized for.
2513
*/
26-
workspacePath: URI | undefined;
14+
workspacePath: lsp.URI | undefined;
2715
}
2816

2917
export interface ProjectDebugConfiguration {
@@ -59,44 +47,96 @@ export interface ProjectDebugConfiguration {
5947
}
6048

6149
export interface OnAutoInsertParams {
62-
_vs_textDocument: TextDocumentIdentifier;
63-
_vs_position: Position;
50+
_vs_textDocument: lsp.TextDocumentIdentifier;
51+
_vs_position: lsp.Position;
6452
_vs_ch: string;
65-
_vs_options: FormattingOptions;
53+
_vs_options: lsp.FormattingOptions;
6654
}
6755

6856
export interface OnAutoInsertResponseItem {
69-
_vs_textEditFormat: InsertTextFormat;
70-
_vs_textEdit: TextEdit;
57+
_vs_textEditFormat: lsp.InsertTextFormat;
58+
_vs_textEdit: lsp.TextEdit;
7159
}
7260

7361
export interface RegisterSolutionSnapshotResponseItem {
7462
/**
7563
* Represents a solution snapshot.
7664
*/
77-
id: integer;
65+
id: lsp.integer;
66+
}
67+
68+
export interface RunTestsParams extends lsp.WorkDoneProgressParams, lsp.PartialResultParams {
69+
/**
70+
* The text document containing the tests to run.
71+
*/
72+
textDocument: lsp.TextDocumentIdentifier;
73+
74+
/**
75+
* The range encompasing the test methods to run.
76+
* Note that this does not have to only include tests, for example this could be a range representing a class.
77+
*/
78+
range: lsp.Range;
79+
}
80+
81+
export interface TestProgress {
82+
/**
83+
* The total number of tests passed at the time of the report.
84+
*/
85+
testsPassed: number;
86+
/**
87+
* The total number of tests failed at the time of the report.
88+
*/
89+
testsFailed: number;
90+
/**
91+
* The total number of tests skipped at the time of the report.
92+
*/
93+
testsSkipped: number;
94+
/**
95+
* The total number of tests that will eventually be run.
96+
*/
97+
totalTests: number;
98+
}
99+
100+
export interface RunTestsPartialResult {
101+
stage: string;
102+
message: string;
103+
progress?: TestProgress;
78104
}
79105

80106
export namespace WorkspaceDebugConfigurationRequest {
81107
export const method = 'workspace/debugConfiguration';
82-
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
83-
export const type = new RequestType<WorkspaceDebugConfigurationParams, ProjectDebugConfiguration[], void>(method);
108+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
109+
export const type = new lsp.RequestType<WorkspaceDebugConfigurationParams, ProjectDebugConfiguration[], void>(
110+
method
111+
);
84112
}
85113

86114
export namespace OnAutoInsertRequest {
87115
export const method = 'textDocument/_vs_onAutoInsert';
88-
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
89-
export const type = new RequestType<OnAutoInsertParams, OnAutoInsertResponseItem, void>(method);
116+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
117+
export const type = new lsp.RequestType<OnAutoInsertParams, OnAutoInsertResponseItem, void>(method);
90118
}
91119

92120
export namespace RegisterSolutionSnapshotRequest {
93121
export const method = 'workspace/_vs_registerSolutionSnapshot';
94-
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
95-
export const type = new RequestType0<RegisterSolutionSnapshotResponseItem, void>(method);
122+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
123+
export const type = new lsp.RequestType0<RegisterSolutionSnapshotResponseItem, void>(method);
96124
}
97125

98126
export namespace ProjectInitializationCompleteNotification {
99127
export const method = 'workspace/projectInitializationComplete';
100-
export const messageDirection: MessageDirection = MessageDirection.serverToClient;
101-
export const type = new NotificationType(method);
128+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
129+
export const type = new lsp.NotificationType(method);
130+
}
131+
132+
export namespace RunTestsRequest {
133+
export const method = 'textDocument/runTests';
134+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
135+
export const type = new lsp.ProtocolRequestType<
136+
RunTestsParams,
137+
RunTestsPartialResult[],
138+
RunTestsPartialResult,
139+
void,
140+
void
141+
>(method);
102142
}

0 commit comments

Comments
 (0)