Skip to content

Commit 3a31d5b

Browse files
committed
Add support for passing a runsettings path to the server
1 parent 77c8b39 commit 3a31d5b

File tree

9 files changed

+77
-22
lines changed

9 files changed

+77
-22
lines changed

omnisharptest/omnisharpUnitTests/fakes/fakeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function getEmptyOptions(): Options {
1515
excludePaths: [],
1616
defaultSolution: '',
1717
unitTestDebuggingOptions: {},
18+
runSettingsPath: '',
1819
},
1920
{
2021
useModernNet: false,
@@ -40,7 +41,6 @@ export function getEmptyOptions(): Options {
4041
sdkPath: '',
4142
sdkVersion: '',
4243
sdkIncludePrereleases: false,
43-
testRunSettings: '',
4444
dotNetCliPaths: [],
4545
useFormatting: false,
4646
showReferencesCodeLens: false,

omnisharptest/omnisharpUnitTests/options.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ suite('Options tests', () => {
3838
options.omnisharpOptions.enableImportCompletion.should.equal(false);
3939
options.omnisharpOptions.enableAsyncCompletion.should.equal(false);
4040
options.omnisharpOptions.analyzeOpenDocumentsOnly.should.equal(true);
41-
options.omnisharpOptions.testRunSettings.should.equal('');
41+
options.commonOptions.runSettingsPath.should.equal('');
4242
});
4343

4444
test('Verify return no excluded paths when files.exclude empty', () => {
@@ -128,8 +128,6 @@ suite('Options tests', () => {
128128

129129
const options = Options.Read(vscode);
130130

131-
options.omnisharpOptions.testRunSettings.should.equal(
132-
'some_valid_path\\some_valid_runsettings_files.runsettings'
133-
);
131+
options.commonOptions.runSettingsPath.should.equal('some_valid_path\\some_valid_runsettings_files.runsettings');
134132
});
135133
});

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,6 @@
10811081
"default": false,
10821082
"description": "(EXPERIMENTAL) Enables support for resolving completion edits asynchronously. This can speed up time to show the completion list, particularly override and partial method completion lists, at the cost of slight delays after inserting a completion item. Most completion items will have no noticeable impact with this feature, but typing immediately after inserting an override or partial method completion, before the insert is completed, can have unpredictable results."
10831083
},
1084-
"omnisharp.testRunSettings": {
1085-
"type": "string",
1086-
"description": "Path to the .runsettings file which should be used when running unit tests."
1087-
},
10881084
"omnisharp.dotNetCliPaths": {
10891085
"type": "array",
10901086
"items": {
@@ -1358,6 +1354,10 @@
13581354
"description": "%configuration.dotnet.symbolSearch.searchReferenceAssemblies%",
13591355
"order": 80
13601356
},
1357+
"dotnet.unitTests.runSettingsPath": {
1358+
"type": "string",
1359+
"description": "Path to the .runsettings file which should be used when running unit tests."
1360+
},
13611361
"dotnet.unitTestDebuggingOptions": {
13621362
"type": "object",
13631363
"description": "%configuration.dotnet.unitTestDebuggingOptions%",

src/features/dotnetTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export default class TestManager extends AbstractProvider {
233233
}
234234

235235
private _getRunSettings(filename: string): string | undefined {
236-
const testSettingsPath = this.optionProvider.GetLatestOptions().omnisharpOptions.testRunSettings;
236+
const testSettingsPath = this.optionProvider.GetLatestOptions().commonOptions.runSettingsPath;
237237
if (testSettingsPath.length === 0) {
238238
return undefined;
239239
}

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export async function activateRoslynLanguageServer(
825825

826826
registerRazorCommands(context, _languageServer);
827827

828-
registerUnitTestingCommands(context, _languageServer, dotnetTestChannel);
828+
registerUnitTestingCommands(context, _languageServer, dotnetTestChannel, optionProvider);
829829

830830
// Register any needed debugger components that need to communicate with the language server.
831831
registerDebugger(context, _languageServer, platformInfo, optionProvider, _channel);

src/lsptoolshost/roslynProtocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface RunTestsParams extends lsp.WorkDoneProgressParams, lsp.PartialR
8383
* Whether the request should attempt to call back to the client to attach a debugger before running the tests.
8484
*/
8585
attachDebugger: boolean;
86+
87+
/**
88+
* The absolute path to a .runsettings file to configure the test run.
89+
*/
90+
runSettingsPath?: string;
8691
}
8792

8893
export interface TestProgress {

src/lsptoolshost/unitTesting.ts

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

6+
import * as fs from 'fs';
7+
import * as path from 'path';
68
import * as vscode from 'vscode';
79
import * as languageClient from 'vscode-languageclient/node';
810
import { RoslynLanguageServer } from './roslynLanguageServer';
911
import { RunTestsParams, RunTestsPartialResult, RunTestsRequest } from './roslynProtocol';
12+
import OptionProvider from '../shared/observers/optionProvider';
1013

1114
export function registerUnitTestingCommands(
1215
context: vscode.ExtensionContext,
1316
languageServer: RoslynLanguageServer,
14-
dotnetTestChannel: vscode.OutputChannel
17+
dotnetTestChannel: vscode.OutputChannel,
18+
optionProvider: OptionProvider
1519
) {
1620
context.subscriptions.push(
1721
vscode.commands.registerCommand('dotnet.test.run', async (request) =>
18-
runTests(request, languageServer, dotnetTestChannel)
22+
runTests(request, languageServer, dotnetTestChannel, optionProvider)
1923
)
2024
);
2125
context.subscriptions.push(
2226
vscode.commands.registerTextEditorCommand(
2327
'dotnet.test.runTestsInContext',
2428
async (textEditor: vscode.TextEditor) => {
25-
return runTestsInContext(false, textEditor, languageServer, dotnetTestChannel);
29+
return runTestsInContext(false, textEditor, languageServer, dotnetTestChannel, optionProvider);
2630
}
2731
)
2832
);
@@ -31,7 +35,7 @@ export function registerUnitTestingCommands(
3135
vscode.commands.registerTextEditorCommand(
3236
'dotnet.test.debugTestsInContext',
3337
async (textEditor: vscode.TextEditor) => {
34-
return runTestsInContext(true, textEditor, languageServer, dotnetTestChannel);
38+
return runTestsInContext(true, textEditor, languageServer, dotnetTestChannel, optionProvider);
3539
}
3640
)
3741
);
@@ -41,21 +45,29 @@ async function runTestsInContext(
4145
debug: boolean,
4246
textEditor: vscode.TextEditor,
4347
languageServer: RoslynLanguageServer,
44-
dotnetTestChannel: vscode.OutputChannel
48+
dotnetTestChannel: vscode.OutputChannel,
49+
optionProvider: OptionProvider
4550
) {
4651
const contextRange: languageClient.Range = { start: textEditor.selection.active, end: textEditor.selection.active };
4752
const textDocument: languageClient.TextDocumentIdentifier = { uri: textEditor.document.fileName };
48-
const request: RunTestsParams = { textDocument: textDocument, range: contextRange, attachDebugger: debug };
49-
await runTests(request, languageServer, dotnetTestChannel);
53+
const request: RunTestsParams = {
54+
textDocument: textDocument,
55+
range: contextRange,
56+
attachDebugger: debug,
57+
};
58+
await runTests(request, languageServer, dotnetTestChannel, optionProvider);
5059
}
5160

5261
let _testRunInProgress = false;
5362

5463
async function runTests(
5564
request: RunTestsParams,
5665
languageServer: RoslynLanguageServer,
57-
dotnetTestChannel: vscode.OutputChannel
66+
dotnetTestChannel: vscode.OutputChannel,
67+
optionProvider: OptionProvider
5868
) {
69+
request.runSettingsPath = getRunSettings(request.textDocument.uri, optionProvider, dotnetTestChannel);
70+
5971
if (_testRunInProgress) {
6072
vscode.window.showErrorMessage('Test run already in progress');
6173
return;
@@ -125,3 +137,34 @@ async function runTests(
125137
() => (_testRunInProgress = false)
126138
);
127139
}
140+
141+
function getRunSettings(
142+
documentUri: string,
143+
optionProvider: OptionProvider,
144+
dotnetTestChannel: vscode.OutputChannel
145+
): string | undefined {
146+
const runSettingsPathOption = optionProvider.GetLatestOptions().commonOptions.runSettingsPath;
147+
if (runSettingsPathOption.length === 0) {
148+
return undefined;
149+
}
150+
151+
let absolutePath = runSettingsPathOption;
152+
if (!path.isAbsolute(runSettingsPathOption)) {
153+
// Path is relative to the workspace. Create absolute path.
154+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(documentUri));
155+
if (workspaceFolder === undefined) {
156+
dotnetTestChannel.appendLine(
157+
`Warning: Unable to find workspace folder for ${documentUri}, cannot resolve run settings path ${runSettingsPathOption}.`
158+
);
159+
return undefined;
160+
}
161+
absolutePath = path.join(workspaceFolder.uri.fsPath, runSettingsPathOption);
162+
}
163+
164+
if (!fs.existsSync(absolutePath)) {
165+
dotnetTestChannel.appendLine(`Warning: Unable to find run settings file at ${absolutePath}.`);
166+
return undefined;
167+
}
168+
169+
return absolutePath;
170+
}

src/shared/migrateOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export const migrateOptions = [
7070
omnisharpOption: 'csharp.unitTestDebuggingOptions',
7171
roslynOption: 'dotnet.unitTestDebuggingOptions',
7272
},
73+
{
74+
omnisharpOption: 'omnisharp.testRunSettings',
75+
roslynOption: 'dotnet.unitTests.runSettingsPath',
76+
},
7377
];
7478

7579
export async function MigrateOptions(vscode: vscode): Promise<void> {

src/shared/options.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export class Options {
9797
{},
9898
'csharp.unitTestDebuggingOptions'
9999
);
100+
const runSettingsPath = Options.readOption<string>(
101+
config,
102+
'dotnet.unitTests.runSettingsPath',
103+
'',
104+
'omnisharp.testRunSettings'
105+
);
100106

101107
// Omnisharp Server Options
102108

@@ -179,7 +185,6 @@ export class Options {
179185
'omnisharp.enableMsBuildLoadProjectsOnDemand',
180186
false
181187
);
182-
const testRunSettings = Options.readOption<string>(config, 'omnisharp.testRunSettings', '');
183188
const dotNetCliPaths = Options.readOption<string[]>(config, 'omnisharp.dotNetCliPaths', []);
184189

185190
const useFormatting = Options.readOption<boolean>(config, 'csharp.format.enable', true);
@@ -312,6 +317,7 @@ export class Options {
312317
excludePaths: excludePaths,
313318
defaultSolution: defaultSolution,
314319
unitTestDebuggingOptions: unitTestDebuggingOptions,
320+
runSettingsPath: runSettingsPath,
315321
},
316322
{
317323
useModernNet: useModernNet,
@@ -337,7 +343,6 @@ export class Options {
337343
sdkPath: sdkPath,
338344
sdkVersion: sdkVersion,
339345
sdkIncludePrereleases: sdkIncludePrereleases,
340-
testRunSettings: testRunSettings,
341346
dotNetCliPaths: dotNetCliPaths,
342347
useFormatting: useFormatting,
343348
showReferencesCodeLens: showReferencesCodeLens,
@@ -425,6 +430,7 @@ export interface CommonOptions {
425430
/** The default solution; this has been normalized to a full file path from the workspace folder it was configured in, or the string "disable" if that has been disabled */
426431
defaultSolution: string;
427432
unitTestDebuggingOptions: object;
433+
runSettingsPath: string;
428434
}
429435

430436
export const CommonOptionsThatTriggerReload: ReadonlyArray<keyof CommonOptions> = [
@@ -458,7 +464,6 @@ export interface OmnisharpServerOptions {
458464
sdkPath: string;
459465
sdkVersion: string;
460466
sdkIncludePrereleases: boolean;
461-
testRunSettings: string;
462467
dotNetCliPaths: string[];
463468
useFormatting: boolean;
464469
showReferencesCodeLens: boolean;

0 commit comments

Comments
 (0)