Skip to content

Commit

Permalink
Merge pull request #4418 from leo-labs/options-codelens-filteredsymbo…
Browse files Browse the repository at this point in the history
…lnames

Add option to to exclude custom symbols from codelens
  • Loading branch information
JoeRobich committed May 3, 2021
2 parents e0b8959 + 256f50d commit 76182f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions package.json
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/features/codeLensProvider.ts
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand All @@ -255,6 +255,10 @@ function isValidElementForReferencesCodeLens(element: Structure.CodeElement): bo
return false;
}

if(options.filteredSymbolsCodeLens.includes(element.Name)) {
return false;
}

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/omnisharp/options.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -80,6 +81,7 @@ export class Options {

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

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

Expand Down Expand Up @@ -115,6 +117,7 @@ export class Options {
organizeImportsOnFormat,
showReferencesCodeLens,
showTestsCodeLens,
filteredSymbolsCodeLens,
disableCodeActions,
disableMSBuildDiagnosticWarning,
showOmnisharpLogOnError,
Expand Down
2 changes: 1 addition & 1 deletion test/unitTests/Fakes/FakeOptions.ts
Expand Up @@ -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, "", "");
}

0 comments on commit 76182f2

Please sign in to comment.