From 3a31d5b9ffd350d9bdd9e8e3770f38db8e69a364 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 31 Aug 2023 15:52:45 -0700 Subject: [PATCH 1/4] Add support for passing a runsettings path to the server --- .../omnisharpUnitTests/fakes/fakeOptions.ts | 2 +- .../omnisharpUnitTests/options.test.ts | 6 +- package.json | 8 +-- src/features/dotnetTest.ts | 2 +- src/lsptoolshost/roslynLanguageServer.ts | 2 +- src/lsptoolshost/roslynProtocol.ts | 5 ++ src/lsptoolshost/unitTesting.ts | 59 ++++++++++++++++--- src/shared/migrateOptions.ts | 4 ++ src/shared/options.ts | 11 +++- 9 files changed, 77 insertions(+), 22 deletions(-) diff --git a/omnisharptest/omnisharpUnitTests/fakes/fakeOptions.ts b/omnisharptest/omnisharpUnitTests/fakes/fakeOptions.ts index 0c42a9837..0d3c02d48 100644 --- a/omnisharptest/omnisharpUnitTests/fakes/fakeOptions.ts +++ b/omnisharptest/omnisharpUnitTests/fakes/fakeOptions.ts @@ -15,6 +15,7 @@ export function getEmptyOptions(): Options { excludePaths: [], defaultSolution: '', unitTestDebuggingOptions: {}, + runSettingsPath: '', }, { useModernNet: false, @@ -40,7 +41,6 @@ export function getEmptyOptions(): Options { sdkPath: '', sdkVersion: '', sdkIncludePrereleases: false, - testRunSettings: '', dotNetCliPaths: [], useFormatting: false, showReferencesCodeLens: false, diff --git a/omnisharptest/omnisharpUnitTests/options.test.ts b/omnisharptest/omnisharpUnitTests/options.test.ts index 1d7e37e48..b06787575 100644 --- a/omnisharptest/omnisharpUnitTests/options.test.ts +++ b/omnisharptest/omnisharpUnitTests/options.test.ts @@ -38,7 +38,7 @@ suite('Options tests', () => { options.omnisharpOptions.enableImportCompletion.should.equal(false); options.omnisharpOptions.enableAsyncCompletion.should.equal(false); options.omnisharpOptions.analyzeOpenDocumentsOnly.should.equal(true); - options.omnisharpOptions.testRunSettings.should.equal(''); + options.commonOptions.runSettingsPath.should.equal(''); }); test('Verify return no excluded paths when files.exclude empty', () => { @@ -128,8 +128,6 @@ suite('Options tests', () => { const options = Options.Read(vscode); - options.omnisharpOptions.testRunSettings.should.equal( - 'some_valid_path\\some_valid_runsettings_files.runsettings' - ); + options.commonOptions.runSettingsPath.should.equal('some_valid_path\\some_valid_runsettings_files.runsettings'); }); }); diff --git a/package.json b/package.json index c510ffc91..6bed9aeb5 100644 --- a/package.json +++ b/package.json @@ -1081,10 +1081,6 @@ "default": false, "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." }, - "omnisharp.testRunSettings": { - "type": "string", - "description": "Path to the .runsettings file which should be used when running unit tests." - }, "omnisharp.dotNetCliPaths": { "type": "array", "items": { @@ -1358,6 +1354,10 @@ "description": "%configuration.dotnet.symbolSearch.searchReferenceAssemblies%", "order": 80 }, + "dotnet.unitTests.runSettingsPath": { + "type": "string", + "description": "Path to the .runsettings file which should be used when running unit tests." + }, "dotnet.unitTestDebuggingOptions": { "type": "object", "description": "%configuration.dotnet.unitTestDebuggingOptions%", diff --git a/src/features/dotnetTest.ts b/src/features/dotnetTest.ts index 7872333db..848a2aaa2 100644 --- a/src/features/dotnetTest.ts +++ b/src/features/dotnetTest.ts @@ -233,7 +233,7 @@ export default class TestManager extends AbstractProvider { } private _getRunSettings(filename: string): string | undefined { - const testSettingsPath = this.optionProvider.GetLatestOptions().omnisharpOptions.testRunSettings; + const testSettingsPath = this.optionProvider.GetLatestOptions().commonOptions.runSettingsPath; if (testSettingsPath.length === 0) { return undefined; } diff --git a/src/lsptoolshost/roslynLanguageServer.ts b/src/lsptoolshost/roslynLanguageServer.ts index 0837eca73..79c8237fd 100644 --- a/src/lsptoolshost/roslynLanguageServer.ts +++ b/src/lsptoolshost/roslynLanguageServer.ts @@ -825,7 +825,7 @@ export async function activateRoslynLanguageServer( registerRazorCommands(context, _languageServer); - registerUnitTestingCommands(context, _languageServer, dotnetTestChannel); + registerUnitTestingCommands(context, _languageServer, dotnetTestChannel, optionProvider); // Register any needed debugger components that need to communicate with the language server. registerDebugger(context, _languageServer, platformInfo, optionProvider, _channel); diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index 27e63e65e..122fee686 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -83,6 +83,11 @@ export interface RunTestsParams extends lsp.WorkDoneProgressParams, lsp.PartialR * Whether the request should attempt to call back to the client to attach a debugger before running the tests. */ attachDebugger: boolean; + + /** + * The absolute path to a .runsettings file to configure the test run. + */ + runSettingsPath?: string; } export interface TestProgress { diff --git a/src/lsptoolshost/unitTesting.ts b/src/lsptoolshost/unitTesting.ts index 298cda283..08fee0634 100644 --- a/src/lsptoolshost/unitTesting.ts +++ b/src/lsptoolshost/unitTesting.ts @@ -3,26 +3,30 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as fs from 'fs'; +import * as path from 'path'; import * as vscode from 'vscode'; import * as languageClient from 'vscode-languageclient/node'; import { RoslynLanguageServer } from './roslynLanguageServer'; import { RunTestsParams, RunTestsPartialResult, RunTestsRequest } from './roslynProtocol'; +import OptionProvider from '../shared/observers/optionProvider'; export function registerUnitTestingCommands( context: vscode.ExtensionContext, languageServer: RoslynLanguageServer, - dotnetTestChannel: vscode.OutputChannel + dotnetTestChannel: vscode.OutputChannel, + optionProvider: OptionProvider ) { context.subscriptions.push( vscode.commands.registerCommand('dotnet.test.run', async (request) => - runTests(request, languageServer, dotnetTestChannel) + runTests(request, languageServer, dotnetTestChannel, optionProvider) ) ); context.subscriptions.push( vscode.commands.registerTextEditorCommand( 'dotnet.test.runTestsInContext', async (textEditor: vscode.TextEditor) => { - return runTestsInContext(false, textEditor, languageServer, dotnetTestChannel); + return runTestsInContext(false, textEditor, languageServer, dotnetTestChannel, optionProvider); } ) ); @@ -31,7 +35,7 @@ export function registerUnitTestingCommands( vscode.commands.registerTextEditorCommand( 'dotnet.test.debugTestsInContext', async (textEditor: vscode.TextEditor) => { - return runTestsInContext(true, textEditor, languageServer, dotnetTestChannel); + return runTestsInContext(true, textEditor, languageServer, dotnetTestChannel, optionProvider); } ) ); @@ -41,12 +45,17 @@ async function runTestsInContext( debug: boolean, textEditor: vscode.TextEditor, languageServer: RoslynLanguageServer, - dotnetTestChannel: vscode.OutputChannel + dotnetTestChannel: vscode.OutputChannel, + optionProvider: OptionProvider ) { const contextRange: languageClient.Range = { start: textEditor.selection.active, end: textEditor.selection.active }; const textDocument: languageClient.TextDocumentIdentifier = { uri: textEditor.document.fileName }; - const request: RunTestsParams = { textDocument: textDocument, range: contextRange, attachDebugger: debug }; - await runTests(request, languageServer, dotnetTestChannel); + const request: RunTestsParams = { + textDocument: textDocument, + range: contextRange, + attachDebugger: debug, + }; + await runTests(request, languageServer, dotnetTestChannel, optionProvider); } let _testRunInProgress = false; @@ -54,8 +63,11 @@ let _testRunInProgress = false; async function runTests( request: RunTestsParams, languageServer: RoslynLanguageServer, - dotnetTestChannel: vscode.OutputChannel + dotnetTestChannel: vscode.OutputChannel, + optionProvider: OptionProvider ) { + request.runSettingsPath = getRunSettings(request.textDocument.uri, optionProvider, dotnetTestChannel); + if (_testRunInProgress) { vscode.window.showErrorMessage('Test run already in progress'); return; @@ -125,3 +137,34 @@ async function runTests( () => (_testRunInProgress = false) ); } + +function getRunSettings( + documentUri: string, + optionProvider: OptionProvider, + dotnetTestChannel: vscode.OutputChannel +): string | undefined { + const runSettingsPathOption = optionProvider.GetLatestOptions().commonOptions.runSettingsPath; + if (runSettingsPathOption.length === 0) { + return undefined; + } + + let absolutePath = runSettingsPathOption; + if (!path.isAbsolute(runSettingsPathOption)) { + // Path is relative to the workspace. Create absolute path. + const workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(documentUri)); + if (workspaceFolder === undefined) { + dotnetTestChannel.appendLine( + `Warning: Unable to find workspace folder for ${documentUri}, cannot resolve run settings path ${runSettingsPathOption}.` + ); + return undefined; + } + absolutePath = path.join(workspaceFolder.uri.fsPath, runSettingsPathOption); + } + + if (!fs.existsSync(absolutePath)) { + dotnetTestChannel.appendLine(`Warning: Unable to find run settings file at ${absolutePath}.`); + return undefined; + } + + return absolutePath; +} diff --git a/src/shared/migrateOptions.ts b/src/shared/migrateOptions.ts index 1405f10eb..0f6b50401 100644 --- a/src/shared/migrateOptions.ts +++ b/src/shared/migrateOptions.ts @@ -70,6 +70,10 @@ export const migrateOptions = [ omnisharpOption: 'csharp.unitTestDebuggingOptions', roslynOption: 'dotnet.unitTestDebuggingOptions', }, + { + omnisharpOption: 'omnisharp.testRunSettings', + roslynOption: 'dotnet.unitTests.runSettingsPath', + }, ]; export async function MigrateOptions(vscode: vscode): Promise { diff --git a/src/shared/options.ts b/src/shared/options.ts index 7c274adb9..4b969554b 100644 --- a/src/shared/options.ts +++ b/src/shared/options.ts @@ -97,6 +97,12 @@ export class Options { {}, 'csharp.unitTestDebuggingOptions' ); + const runSettingsPath = Options.readOption( + config, + 'dotnet.unitTests.runSettingsPath', + '', + 'omnisharp.testRunSettings' + ); // Omnisharp Server Options @@ -179,7 +185,6 @@ export class Options { 'omnisharp.enableMsBuildLoadProjectsOnDemand', false ); - const testRunSettings = Options.readOption(config, 'omnisharp.testRunSettings', ''); const dotNetCliPaths = Options.readOption(config, 'omnisharp.dotNetCliPaths', []); const useFormatting = Options.readOption(config, 'csharp.format.enable', true); @@ -312,6 +317,7 @@ export class Options { excludePaths: excludePaths, defaultSolution: defaultSolution, unitTestDebuggingOptions: unitTestDebuggingOptions, + runSettingsPath: runSettingsPath, }, { useModernNet: useModernNet, @@ -337,7 +343,6 @@ export class Options { sdkPath: sdkPath, sdkVersion: sdkVersion, sdkIncludePrereleases: sdkIncludePrereleases, - testRunSettings: testRunSettings, dotNetCliPaths: dotNetCliPaths, useFormatting: useFormatting, showReferencesCodeLens: showReferencesCodeLens, @@ -425,6 +430,7 @@ export interface CommonOptions { /** 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 */ defaultSolution: string; unitTestDebuggingOptions: object; + runSettingsPath: string; } export const CommonOptionsThatTriggerReload: ReadonlyArray = [ @@ -458,7 +464,6 @@ export interface OmnisharpServerOptions { sdkPath: string; sdkVersion: string; sdkIncludePrereleases: boolean; - testRunSettings: string; dotNetCliPaths: string[]; useFormatting: boolean; showReferencesCodeLens: boolean; From c07eaa499c623569e2764fc9a77112cf1231a4af Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 31 Aug 2023 17:12:03 -0700 Subject: [PATCH 2/4] Update package.json Co-authored-by: Joey Robichaud --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bed9aeb5..da21b3a4e 100644 --- a/package.json +++ b/package.json @@ -1356,7 +1356,7 @@ }, "dotnet.unitTests.runSettingsPath": { "type": "string", - "description": "Path to the .runsettings file which should be used when running unit tests." + "description": "Path to the .runsettings file which should be used when running unit tests. (Previously `omnisharp.testRunSettings`)" }, "dotnet.unitTestDebuggingOptions": { "type": "object", From 326c0b75da07cba39cc81e2c1ebc463dd9cfc1c3 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Fri, 8 Sep 2023 16:10:02 -0700 Subject: [PATCH 3/4] Update Roslyn version --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17c490994..26c0c9829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,24 @@ - Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876) ## Latest +* Add support for specifying a .runsettings file when using Roslyn LSP (PR: [#6265](https://github.com/dotnet/vscode-csharp/pull/6265)) +* Update Roslyn version (PR: [#6265](https://github.com/dotnet/vscode-csharp/pull/6265)) + * Add server support for .runsettings in unit tests (PR: [#69792](https://github.com/dotnet/roslyn/pull/69792)) + * Log more information when we're unable to parse a URI (PR: [#69840](https://github.com/dotnet/roslyn/pull/69840)) + * Bump ICSharpCode.Decompiler to 8.1.0.745 (PR: [#69772](https://github.com/dotnet/roslyn/pull/69772)) + * Fix override completion erroring when framework assemblies are not found (PR: [#69795](https://github.com/dotnet/roslyn/pull/69795)) +* Fix override completion when drive letter casing does not match (PR: [#6315](https://github.com/dotnet/vscode-csharp/pull/6315)) +* 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)) + +## 2.1.10 * Update Roslyn version * Includes better support for .NET 8 and .NET Framework-targeting projects (PR: [#69616](https://github.com/dotnet/roslyn/pull/69616)) * 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. * Fix issues where some projects fail to load being unable to find NuGet.Frameworks (PR: [#69824](https://github.com/dotnet/roslyn/pull/69824)) * Update Razor to 7.0.0-preview.23455.5 (PR: [#6291](https://github.com/dotnet/vscode-csharp/pull/6291)) * Fixes issue reading razor.format.enable and other options (PR: [dotnet/razor#9240](https://github.com/dotnet/razor/issues/9240)) +* Fix parsing of tasks.json with comments in certain locations (PR: [#6288](https://github.com/dotnet/vscode-csharp/pull/6288)) +* 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)) ## 2.0.448 * Update Roslyn version (PR: [#6264](https://github.com/dotnet/vscode-csharp/pull/6264)) diff --git a/package.json b/package.json index 74ee4fe96..286d8f3a0 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ } }, "defaults": { - "roslyn": "4.8.0-3.23455.11", + "roslyn": "4.8.0-3.23458.4", "omniSharp": "1.39.7", "razor": "7.0.0-preview.23455.5", "razorOmnisharp": "7.0.0-preview.23363.1" From 67425d63ea2dd4cd4d74042fa9da6615ff80ff91 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Fri, 8 Sep 2023 16:14:54 -0700 Subject: [PATCH 4/4] Update o# integration tests to specify new setting --- .../dotnetTest.integration.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/omnisharptest/omnisharpIntegrationTests/dotnetTest.integration.test.ts b/omnisharptest/omnisharpIntegrationTests/dotnetTest.integration.test.ts index dd4a76669..894c2f1b2 100644 --- a/omnisharptest/omnisharpIntegrationTests/dotnetTest.integration.test.ts +++ b/omnisharptest/omnisharpIntegrationTests/dotnetTest.integration.test.ts @@ -47,8 +47,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { }); test('Undefined runsettings path is unchanged', async function () { - const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); - await omnisharpConfig.update('testRunSettings', undefined); + const omnisharpConfig = vscode.workspace.getConfiguration('dotnet'); + await omnisharpConfig.update('unitTests.runSettingsPath', undefined); const eventWaiter = testAssetWorkspace.waitForEvent( eventStream, @@ -69,8 +69,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { const relativeRunSettingsPath = `.\\settings\\TestSettings.runsettings`.replace('\\', path.sep); const absoluteRunSettingsPath = path.join(process.cwd(), relativeRunSettingsPath); - const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); - await omnisharpConfig.update('testRunSettings', absoluteRunSettingsPath); + const omnisharpConfig = vscode.workspace.getConfiguration('dotnet'); + await omnisharpConfig.update('unitTests.runSettingsPath', absoluteRunSettingsPath); const eventWaiter = testAssetWorkspace.waitForEvent( eventStream, @@ -91,8 +91,8 @@ suite(`DotnetTest: ${testAssetWorkspace.description}`, function () { const endingPath = 'settings\\TestSettings.runsettings'.replace('\\', path.sep); const relativeRunSettingPath = `.\\${endingPath}`.replace('\\', path.sep); - const omnisharpConfig = vscode.workspace.getConfiguration('omnisharp'); - await omnisharpConfig.update('testRunSettings', relativeRunSettingPath); + const omnisharpConfig = vscode.workspace.getConfiguration('dotnet'); + await omnisharpConfig.update('unitTests.runSettingsPath', relativeRunSettingPath); const eventWaiter = testAssetWorkspace.waitForEvent( eventStream,