diff --git a/package.json b/package.json index a926f3b65..146bad44e 100644 --- a/package.json +++ b/package.json @@ -663,6 +663,14 @@ "default": true, "description": "Specifies whether the references CodeLens should be shown." }, + "csharp.referencesCodeLens.filteredSymbols": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Array of custom symbol names for which CodeLens should be disabled." + }, "csharp.testsCodeLens.enabled": { "type": "boolean", "default": true, diff --git a/src/features/codeLensProvider.ts b/src/features/codeLensProvider.ts index 4a8f8419a..703c15fe3 100644 --- a/src/features/codeLensProvider.ts +++ b/src/features/codeLensProvider.ts @@ -194,7 +194,7 @@ function createCodeLenses(elements: Structure.CodeElement[], fileName: string, o function createCodeLensesForElement(element: Structure.CodeElement, fileName: string, options: Options): vscode.CodeLens[] { let results: vscode.CodeLens[] = []; - if (options.showReferencesCodeLens && isValidElementForReferencesCodeLens(element)) { + if (options.showReferencesCodeLens && isValidElementForReferencesCodeLens(element, options)) { let range = element.Ranges[SymbolRangeNames.Name]; if (range) { results.push(new ReferencesCodeLens(range, fileName)); @@ -246,7 +246,7 @@ const filteredSymbolNames: { [name: string]: boolean } = { 'GetEnumerator': true, }; -function isValidElementForReferencesCodeLens(element: Structure.CodeElement): boolean { +function isValidElementForReferencesCodeLens(element: Structure.CodeElement, options: Options): boolean { if (element.Kind === SymbolKinds.Namespace) { return false; } @@ -255,6 +255,10 @@ function isValidElementForReferencesCodeLens(element: Structure.CodeElement): bo return false; } + if(options.filteredSymbolsCodeLens.includes(element.Name)) { + return false; + } + return true; } diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index 0d5d9fc50..0210244cf 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -19,6 +19,7 @@ export class Options { public organizeImportsOnFormat: boolean, public showReferencesCodeLens: boolean, public showTestsCodeLens: boolean, + public filteredSymbolsCodeLens: string[], public disableCodeActions: boolean, public disableMSBuildDiagnosticWarning: boolean, public showOmnisharpLogOnError: boolean, @@ -80,6 +81,7 @@ export class Options { const showReferencesCodeLens = csharpConfig.get('referencesCodeLens.enabled', true); const showTestsCodeLens = csharpConfig.get('testsCodeLens.enabled', true); + const filteredSymbolsCodeLens = csharpConfig.get('referencesCodeLens.filteredSymbols', []); const useSemanticHighlighting = csharpConfig.get('semanticHighlighting.enabled', false); @@ -115,6 +117,7 @@ export class Options { organizeImportsOnFormat, showReferencesCodeLens, showTestsCodeLens, + filteredSymbolsCodeLens, disableCodeActions, disableMSBuildDiagnosticWarning, showOmnisharpLogOnError, diff --git a/test/unitTests/Fakes/FakeOptions.ts b/test/unitTests/Fakes/FakeOptions.ts index 59fe2c817..25b2aa6e6 100644 --- a/test/unitTests/Fakes/FakeOptions.ts +++ b/test/unitTests/Fakes/FakeOptions.ts @@ -6,5 +6,5 @@ import { Options } from "../../../src/omnisharp/options"; export function getEmptyOptions(): Options { - return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", ""); + return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, [], false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", ""); }