Skip to content

Commit

Permalink
Add support for code lens enable/disable options to roslyn LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Aug 3, 2023
1 parent dd03e9a commit 47fe006
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,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 @@ -1144,11 +1139,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 @@ -1396,6 +1386,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

0 comments on commit 47fe006

Please sign in to comment.