Skip to content

Commit f0f0e4a

Browse files
authored
Merge pull request #6265 from dibarbet/runsettings
Add support for passing a runsettings path to the server
2 parents 097b7ed + 67425d6 commit f0f0e4a

File tree

11 files changed

+94
-28
lines changed

11 files changed

+94
-28
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@
88
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
99

1010
## Latest
11+
* Add support for specifying a .runsettings file when using Roslyn LSP (PR: [#6265](https://github.com/dotnet/vscode-csharp/pull/6265))
12+
* Update Roslyn version (PR: [#6265](https://github.com/dotnet/vscode-csharp/pull/6265))
13+
* Add server support for .runsettings in unit tests (PR: [#69792](https://github.com/dotnet/roslyn/pull/69792))
14+
* Log more information when we're unable to parse a URI (PR: [#69840](https://github.com/dotnet/roslyn/pull/69840))
15+
* Bump ICSharpCode.Decompiler to 8.1.0.745 (PR: [#69772](https://github.com/dotnet/roslyn/pull/69772))
16+
* Fix override completion erroring when framework assemblies are not found (PR: [#69795](https://github.com/dotnet/roslyn/pull/69795))
17+
* Fix override completion when drive letter casing does not match (PR: [#6315](https://github.com/dotnet/vscode-csharp/pull/6315))
18+
* Allow the server path to be specified by the `DOTNET_ROSLYN_SERVER_PATH` environment variable (PR: [#6316](https://github.com/dotnet/vscode-csharp/pull/6316))
19+
20+
## 2.1.10
1121
* Update Roslyn version
1222
* Includes better support for .NET 8 and .NET Framework-targeting projects (PR: [#69616](https://github.com/dotnet/roslyn/pull/69616))
1323
* This should fix a number of reports where projects don't have full IntelliSense. .NET Framework projects on Windows should load without errors. .NET Framework targeting projects on Mac and Linux which would use Mono are still processed as if they are .NET Core projects and may not load correctly; support for Mono is coming in a future update.
1424
* Fix issues where some projects fail to load being unable to find NuGet.Frameworks (PR: [#69824](https://github.com/dotnet/roslyn/pull/69824))
1525
* Update Razor to 7.0.0-preview.23455.5 (PR: [#6291](https://github.com/dotnet/vscode-csharp/pull/6291))
1626
* Fixes issue reading razor.format.enable and other options (PR: [dotnet/razor#9240](https://github.com/dotnet/razor/issues/9240))
27+
* Fix parsing of tasks.json with comments in certain locations (PR: [#6288](https://github.com/dotnet/vscode-csharp/pull/6288))
28+
* Fix Razor browser discovery issues on Mac and Linux `DOTNET_ROSLYN_SERVER_PATH` environment variable (PR: [#6269](https://github.com/dotnet/vscode-csharp/pull/6269))
1729

1830
## 2.0.448
1931
* Update Roslyn version (PR: [#6264](https://github.com/dotnet/vscode-csharp/pull/6264))

omnisharptest/omnisharpIntegrationTests/dotnetTest.integration.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () {
4747
});
4848

4949
test('Undefined runsettings path is unchanged', async function () {
50-
const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
51-
await omnisharpConfig.update('testRunSettings', undefined);
50+
const omnisharpConfig = vscode.workspace.getConfiguration('dotnet');
51+
await omnisharpConfig.update('unitTests.runSettingsPath', undefined);
5252

5353
const eventWaiter = testAssetWorkspace.waitForEvent<OmnisharpRequestMessage>(
5454
eventStream,
@@ -69,8 +69,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () {
6969
const relativeRunSettingsPath = `.\\settings\\TestSettings.runsettings`.replace('\\', path.sep);
7070
const absoluteRunSettingsPath = path.join(process.cwd(), relativeRunSettingsPath);
7171

72-
const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
73-
await omnisharpConfig.update('testRunSettings', absoluteRunSettingsPath);
72+
const omnisharpConfig = vscode.workspace.getConfiguration('dotnet');
73+
await omnisharpConfig.update('unitTests.runSettingsPath', absoluteRunSettingsPath);
7474

7575
const eventWaiter = testAssetWorkspace.waitForEvent<OmnisharpRequestMessage>(
7676
eventStream,
@@ -91,8 +91,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () {
9191
const endingPath = 'settings\\TestSettings.runsettings'.replace('\\', path.sep);
9292
const relativeRunSettingPath = `.\\${endingPath}`.replace('\\', path.sep);
9393

94-
const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp');
95-
await omnisharpConfig.update('testRunSettings', relativeRunSettingPath);
94+
const omnisharpConfig = vscode.workspace.getConfiguration('dotnet');
95+
await omnisharpConfig.update('unitTests.runSettingsPath', relativeRunSettingPath);
9696

9797
const eventWaiter = testAssetWorkspace.waitForEvent<OmnisharpRequestMessage>(
9898
eventStream,

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838
},
3939
"defaults": {
40-
"roslyn": "4.8.0-3.23455.11",
40+
"roslyn": "4.8.0-3.23458.4",
4141
"omniSharp": "1.39.7",
4242
"razor": "7.0.0-preview.23455.5",
4343
"razorOmnisharp": "7.0.0-preview.23363.1"
@@ -1087,10 +1087,6 @@
10871087
"default": false,
10881088
"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."
10891089
},
1090-
"omnisharp.testRunSettings": {
1091-
"type": "string",
1092-
"description": "Path to the .runsettings file which should be used when running unit tests."
1093-
},
10941090
"omnisharp.dotNetCliPaths": {
10951091
"type": "array",
10961092
"items": {
@@ -1364,6 +1360,10 @@
13641360
"description": "%configuration.dotnet.symbolSearch.searchReferenceAssemblies%",
13651361
"order": 80
13661362
},
1363+
"dotnet.unitTests.runSettingsPath": {
1364+
"type": "string",
1365+
"description": "Path to the .runsettings file which should be used when running unit tests. (Previously `omnisharp.testRunSettings`)"
1366+
},
13671367
"dotnet.unitTestDebuggingOptions": {
13681368
"type": "object",
13691369
"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
@@ -748,7 +748,7 @@ export async function activateRoslynLanguageServer(
748748

749749
registerRazorCommands(context, languageServer);
750750

751-
registerUnitTestingCommands(context, languageServer, dotnetTestChannel);
751+
registerUnitTestingCommands(context, languageServer, dotnetTestChannel, optionProvider);
752752

753753
// Register any needed debugger components that need to communicate with the language server.
754754
registerDebugger(context, languageServer, languageServerEvents, 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: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,51 @@
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, TestProgress } 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(
1822
'dotnet.test.run',
19-
async (request): Promise<TestProgress | undefined> => runTests(request, languageServer, dotnetTestChannel)
23+
async (request): Promise<TestProgress | undefined> =>
24+
runTests(request, languageServer, dotnetTestChannel, optionProvider)
2025
)
2126
);
2227
context.subscriptions.push(
2328
// We don't use registerTextEditorCommand because it is required to run synchronously and is not awaitable.
2429
// See https://github.com/microsoft/vscode/issues/16814 for more info.
2530
vscode.commands.registerCommand(
2631
'dotnet.test.runTestsInContext',
27-
async (): Promise<TestProgress | undefined> => runTestsInContext(false, languageServer, dotnetTestChannel)
32+
async (): Promise<TestProgress | undefined> =>
33+
runTestsInContext(false, languageServer, dotnetTestChannel, optionProvider)
2834
)
2935
);
3036

3137
context.subscriptions.push(
3238
vscode.commands.registerCommand(
3339
'dotnet.test.debugTestsInContext',
34-
async (): Promise<TestProgress | undefined> => runTestsInContext(true, languageServer, dotnetTestChannel)
40+
async (): Promise<TestProgress | undefined> =>
41+
runTestsInContext(true, languageServer, dotnetTestChannel, optionProvider)
3542
)
3643
);
3744
}
3845

3946
async function runTestsInContext(
4047
debug: boolean,
4148
languageServer: RoslynLanguageServer,
42-
dotnetTestChannel: vscode.OutputChannel
49+
dotnetTestChannel: vscode.OutputChannel,
50+
optionProvider: OptionProvider
4351
): Promise<TestProgress | undefined> {
4452
const activeEditor = vscode.window.activeTextEditor;
4553
if (!activeEditor) {
@@ -51,21 +59,24 @@ async function runTestsInContext(
5159
};
5260
const textDocument: languageClient.TextDocumentIdentifier = { uri: activeEditor.document.fileName };
5361
const request: RunTestsParams = { textDocument: textDocument, range: contextRange, attachDebugger: debug };
54-
return runTests(request, languageServer, dotnetTestChannel);
62+
return runTests(request, languageServer, dotnetTestChannel, optionProvider);
5563
}
5664

5765
let _testRunInProgress = false;
5866

5967
async function runTests(
6068
request: RunTestsParams,
6169
languageServer: RoslynLanguageServer,
62-
dotnetTestChannel: vscode.OutputChannel
70+
dotnetTestChannel: vscode.OutputChannel,
71+
optionProvider: OptionProvider
6372
): Promise<TestProgress | undefined> {
6473
if (_testRunInProgress) {
6574
vscode.window.showErrorMessage('Test run already in progress');
6675
return;
6776
}
6877

78+
request.runSettingsPath = getRunSettings(request.textDocument.uri, optionProvider, dotnetTestChannel);
79+
6980
_testRunInProgress = true;
7081

7182
dotnetTestChannel.show(true);
@@ -138,3 +149,34 @@ async function runTests(
138149

139150
return lastProgress;
140151
}
152+
153+
function getRunSettings(
154+
documentUri: string,
155+
optionProvider: OptionProvider,
156+
dotnetTestChannel: vscode.OutputChannel
157+
): string | undefined {
158+
const runSettingsPathOption = optionProvider.GetLatestOptions().commonOptions.runSettingsPath;
159+
if (runSettingsPathOption.length === 0) {
160+
return undefined;
161+
}
162+
163+
let absolutePath = runSettingsPathOption;
164+
if (!path.isAbsolute(runSettingsPathOption)) {
165+
// Path is relative to the workspace. Create absolute path.
166+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(documentUri));
167+
if (workspaceFolder === undefined) {
168+
dotnetTestChannel.appendLine(
169+
`Warning: Unable to find workspace folder for ${documentUri}, cannot resolve run settings path ${runSettingsPathOption}.`
170+
);
171+
return undefined;
172+
}
173+
absolutePath = path.join(workspaceFolder.uri.fsPath, runSettingsPathOption);
174+
}
175+
176+
if (!fs.existsSync(absolutePath)) {
177+
dotnetTestChannel.appendLine(`Warning: Unable to find run settings file at ${absolutePath}.`);
178+
return undefined;
179+
}
180+
181+
return absolutePath;
182+
}

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> {

0 commit comments

Comments
 (0)