Skip to content

Commit 76182f2

Browse files
authored
Merge pull request #4418 from leo-labs/options-codelens-filteredsymbolnames
Add option to to exclude custom symbols from codelens
2 parents e0b8959 + 256f50d commit 76182f2

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,14 @@
663663
"default": true,
664664
"description": "Specifies whether the references CodeLens should be shown."
665665
},
666+
"csharp.referencesCodeLens.filteredSymbols": {
667+
"type": "array",
668+
"items": {
669+
"type": "string"
670+
},
671+
"default": [],
672+
"description": "Array of custom symbol names for which CodeLens should be disabled."
673+
},
666674
"csharp.testsCodeLens.enabled": {
667675
"type": "boolean",
668676
"default": true,

src/features/codeLensProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function createCodeLenses(elements: Structure.CodeElement[], fileName: string, o
194194
function createCodeLensesForElement(element: Structure.CodeElement, fileName: string, options: Options): vscode.CodeLens[] {
195195
let results: vscode.CodeLens[] = [];
196196

197-
if (options.showReferencesCodeLens && isValidElementForReferencesCodeLens(element)) {
197+
if (options.showReferencesCodeLens && isValidElementForReferencesCodeLens(element, options)) {
198198
let range = element.Ranges[SymbolRangeNames.Name];
199199
if (range) {
200200
results.push(new ReferencesCodeLens(range, fileName));
@@ -246,7 +246,7 @@ const filteredSymbolNames: { [name: string]: boolean } = {
246246
'GetEnumerator': true,
247247
};
248248

249-
function isValidElementForReferencesCodeLens(element: Structure.CodeElement): boolean {
249+
function isValidElementForReferencesCodeLens(element: Structure.CodeElement, options: Options): boolean {
250250
if (element.Kind === SymbolKinds.Namespace) {
251251
return false;
252252
}
@@ -255,6 +255,10 @@ function isValidElementForReferencesCodeLens(element: Structure.CodeElement): bo
255255
return false;
256256
}
257257

258+
if(options.filteredSymbolsCodeLens.includes(element.Name)) {
259+
return false;
260+
}
261+
258262
return true;
259263
}
260264

src/omnisharp/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Options {
1919
public organizeImportsOnFormat: boolean,
2020
public showReferencesCodeLens: boolean,
2121
public showTestsCodeLens: boolean,
22+
public filteredSymbolsCodeLens: string[],
2223
public disableCodeActions: boolean,
2324
public disableMSBuildDiagnosticWarning: boolean,
2425
public showOmnisharpLogOnError: boolean,
@@ -80,6 +81,7 @@ export class Options {
8081

8182
const showReferencesCodeLens = csharpConfig.get<boolean>('referencesCodeLens.enabled', true);
8283
const showTestsCodeLens = csharpConfig.get<boolean>('testsCodeLens.enabled', true);
84+
const filteredSymbolsCodeLens = csharpConfig.get<string[]>('referencesCodeLens.filteredSymbols', []);
8385

8486
const useSemanticHighlighting = csharpConfig.get<boolean>('semanticHighlighting.enabled', false);
8587

@@ -115,6 +117,7 @@ export class Options {
115117
organizeImportsOnFormat,
116118
showReferencesCodeLens,
117119
showTestsCodeLens,
120+
filteredSymbolsCodeLens,
118121
disableCodeActions,
119122
disableMSBuildDiagnosticWarning,
120123
showOmnisharpLogOnError,

test/unitTests/Fakes/FakeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import { Options } from "../../../src/omnisharp/options";
77

88
export function getEmptyOptions(): Options {
9-
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, "", "");
9+
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, "", "");
1010
}

0 commit comments

Comments
 (0)