Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for code lens enable/disable options to roslyn LSP #6001

Merged
merged 4 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
},
"defaults": {
"roslyn": "4.8.0-1.23403.6",
"roslyn": "4.8.0-1.23404.8",
"omniSharp": "1.39.7",
"razor": "7.0.0-preview.23328.2",
"razorOmnisharp": "7.0.0-preview.23363.1"
Expand Down Expand Up @@ -1138,11 +1138,6 @@
"default": true,
"description": "Suppress 'hidden' diagnostics (such as 'unnecessary using directives') from appearing in the editor or the Problems pane."
},
"csharp.referencesCodeLens.enabled": {
"type": "boolean",
"default": true,
"description": "Specifies whether the references CodeLens should be shown."
},
"csharp.referencesCodeLens.filteredSymbols": {
"type": "array",
"items": {
Expand All @@ -1151,11 +1146,6 @@
"default": [],
"description": "Array of custom symbol names for which CodeLens should be disabled."
},
"csharp.testsCodeLens.enabled": {
"type": "boolean",
"default": true,
"description": "Specifies whether the run and debug test CodeLens should be shown."
},
"csharp.maxProjectFileCountForDiagnosticAnalysis": {
"type": "number",
"default": 1000,
Expand Down Expand Up @@ -1403,6 +1393,16 @@
"description": "Generation behavior of properties when implement interface or abstract class.",
"order": 10
},
"dotnet.codeLens.enableReferencesCodeLens": {
"type": "boolean",
"default": true,
"description": "Specifies whether the references CodeLens should be shown."
},
"dotnet.codeLens.enableTestsCodeLens": {
"type": "boolean",
"default": true,
"description": "Specifies whether the run and debug test CodeLens should be shown."
},
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": {
"type": "boolean",
"default": true,
Expand Down
8 changes: 8 additions & 0 deletions src/shared/migrateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export const migrateOptions = [
omnisharpOption: 'omnisharp.enableImportCompletion',
roslynOption: 'dotnet.completion.showCompletionItemsFromUnimportedNamespaces',
},
{
omnisharpOption: 'csharp.referencesCodeLens.enabled',
roslynOption: 'dotnet.codeLens.enableReferencesCodeLens',
},
{
omnisharpOption: 'csharp.testsCodeLens.enabled',
roslynOption: 'dotnet.codeLens.enableTestsCodeLens',
},
];

export async function MigrateOptions(vscode: vscode): Promise<void> {
Expand Down
14 changes: 12 additions & 2 deletions src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,18 @@ export class Options {
const dotNetCliPaths = Options.readOption<string[]>(config, 'omnisharp.dotNetCliPaths', []);

const useFormatting = Options.readOption<boolean>(config, 'csharp.format.enable', true);
const showReferencesCodeLens = Options.readOption<boolean>(config, 'csharp.referencesCodeLens.enabled', true);
const showTestsCodeLens = Options.readOption<boolean>(config, 'csharp.testsCodeLens.enabled', true);
const showReferencesCodeLens = Options.readOption<boolean>(
config,
'dotnet.codeLens.enableReferencesCodeLens',
true,
'csharp.referencesCodeLens.enabled'
);
const showTestsCodeLens = Options.readOption<boolean>(
config,
'dotnet.codeLens.enableTestsCodeLens',
true,
'csharp.testsCodeLens.enabled'
);
const filteredSymbolsCodeLens = Options.readOption<string[]>(
config,
'csharp.referencesCodeLens.filteredSymbols',
Expand Down
30 changes: 15 additions & 15 deletions test/integrationTests/codeLensProvider.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () {
const filePath = path.join(projectDirectory, fileName);
fileUri = vscode.Uri.file(filePath);

const csharpConfig = vscode.workspace.getConfiguration('csharp');
await csharpConfig.update('referencesCodeLens.enabled', true);
await csharpConfig.update('testsCodeLens.enabled', true);
const csharpConfig = vscode.workspace.getConfiguration('dotnet');
await csharpConfig.update('codeLens.enableReferencesCodeLens', true);
await csharpConfig.update('codeLens.enableTestsCodeLens', true);

await vscode.commands.executeCommand('vscode.open', fileUri);

Expand Down Expand Up @@ -90,10 +90,10 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function ()
});

/* Skip this test until we are able to understand the cause of flakiness */
test.skip("Returns no references code lenses when 'csharp.referencesCodeLens.enabled' option is set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('csharp');
await csharpConfig.update('referencesCodeLens.enabled', false);
await csharpConfig.update('testsCodeLens.enabled', true);
test.skip("Returns no references code lenses when 'dotnet.codeLens.enableReferencesCodeLens' option is set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('dotnet');
await csharpConfig.update('codeLens.enableReferencesCodeLens', false);
await csharpConfig.update('codeLens.enableTestsCodeLens', true);

const codeLenses = await GetCodeLenses(fileUri, 100);
expect(codeLenses.length).to.equal(4);
Expand All @@ -111,10 +111,10 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function ()
}
});

test("Returns no test code lenses when 'csharp.testsCodeLens.enabled' option is set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('csharp');
await csharpConfig.update('referencesCodeLens.enabled', true);
await csharpConfig.update('testsCodeLens.enabled', false);
test("Returns no test code lenses when 'dotnet.testsCodeLens.enabled' option is set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('dotnet');
await csharpConfig.update('codeLens.enableReferencesCodeLens', true);
await csharpConfig.update('codeLens.enableTestsCodeLens', false);

const codeLenses = await GetCodeLenses(fileUri, 100);
expect(codeLenses.length).to.equal(2);
Expand All @@ -127,10 +127,10 @@ suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function ()
}
});

test("Returns no code lenses when 'csharp.referencesCodeLens.enabled' and 'csharp.testsCodeLens.enabled' options are set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('csharp');
await csharpConfig.update('referencesCodeLens.enabled', false);
await csharpConfig.update('testsCodeLens.enabled', false);
test("Returns no code lenses when 'dotnet.codeLens.enableReferencesCodeLens' and 'dotnet.codeLens.enableTestsCodeLens' options are set to false", async function () {
const csharpConfig = vscode.workspace.getConfiguration('dotnet');
await csharpConfig.update('codeLens.enableReferencesCodeLens', false);
await csharpConfig.update('codeLens.enableTestsCodeLens', false);

const codeLenses = await GetCodeLenses(fileUri, 100);
expect(codeLenses.length).to.equal(0);
Expand Down
20 changes: 20 additions & 0 deletions test/unitTests/lspToolHost/configurationMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ const testData = [
vsCodeConfiguration: null,
declareInPackageJson: false,
},
{
serverOption: 'csharp|code_lens.dotnet_enable_references_code_lens',
vsCodeConfiguration: 'dotnet.codeLens.enableReferencesCodeLens',
declareInPackageJson: true,
},
{
serverOption: 'mystery_language|code_lens.dotnet_enable_references_code_lens',
vsCodeConfiguration: null,
declareInPackageJson: false,
},
{
serverOption: 'csharp|code_lens.dotnet_enable_tests_code_lens',
vsCodeConfiguration: 'dotnet.codeLens.enableTestsCodeLens',
declareInPackageJson: true,
},
{
serverOption: 'mystery_language|code_lens.dotnet_enable_tests_code_lens',
vsCodeConfiguration: null,
declareInPackageJson: false,
},
];

suite('Server option name to vscode configuration name test', () => {
Expand Down