From 833b28a65fdd58d6a6b5f977b5560c4ba641baa3 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Fri, 6 Oct 2017 09:34:39 -0700 Subject: [PATCH 1/2] Add an option to disable the references CodeLens --- package.json | 5 +++++ src/features/codeLensProvider.ts | 8 ++++++++ src/omnisharp/options.ts | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0128406d7..cf2a2b91e 100644 --- a/package.json +++ b/package.json @@ -373,6 +373,11 @@ "type": "boolean", "default": true, "description": "Specifes whether OmniSharp should use VS Code editor settings for C# code formatting (use of tabs, indentation size)." + }, + "omnisharp.showReferencesCodeLens": { + "type": "boolean", + "default": true, + "description": "Specifies whether Omnisharp should show the references CodeLens" } } }, diff --git a/src/features/codeLensProvider.ts b/src/features/codeLensProvider.ts index e17602004..2165b3e3a 100644 --- a/src/features/codeLensProvider.ts +++ b/src/features/codeLensProvider.ts @@ -13,6 +13,7 @@ import { toRange, toLocation } from '../omnisharp/typeConvertion'; import AbstractProvider from './abstractProvider'; import * as protocol from '../omnisharp/protocol'; import * as serverUtils from '../omnisharp/utils'; +import { Options } from '../omnisharp/options'; class OmniSharpCodeLens extends vscode.CodeLens { @@ -43,6 +44,13 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen }; provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable { + const options = Options.Read(); + if (!options.showReferencesCodeLens) + { + let arr: vscode.CodeLens[] = []; + return arr; + } + return serverUtils.currentFileMembersAsTree(this._server, { FileName: document.fileName }, token).then(tree => { let ret: vscode.CodeLens[] = []; tree.TopLevelTypeDefinitions.forEach(node => this._convertQuickFix(ret, document.fileName, node)); diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index 435ce39d2..f0ae0edbd 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -15,7 +15,8 @@ export class Options { public projectLoadTimeout?: number, public maxProjectResults?: number, public useEditorFormattingSettings?: boolean, - public useFormatting?: boolean) { } + public useFormatting?: boolean, + public showReferencesCodeLens?: boolean) { } public static Read(): Options { // Extra effort is taken below to ensure that legacy versions of options @@ -51,6 +52,17 @@ export class Options { const useFormatting = csharpConfig.get('format.enable', true); - return new Options(path, useMono, waitForDebugger, loggingLevel, autoStart, projectLoadTimeout, maxProjectResults, useEditorFormattingSettings, useFormatting); + const showReferencesCodeLens = omnisharpConfig.get('showReferencesCodeLens', true); + + return new Options(path, + useMono, + waitForDebugger, + loggingLevel, + autoStart, + projectLoadTimeout, + maxProjectResults, + useEditorFormattingSettings, + useFormatting, + showReferencesCodeLens); } } \ No newline at end of file From 1d6310071ed0e83dd85ea2fc5b16b786d95765b5 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Fri, 6 Oct 2017 09:49:13 -0700 Subject: [PATCH 2/2] CR feedback: move option into C# options and use better empty array syntax --- package.json | 10 +++++----- src/features/codeLensProvider.ts | 3 +-- src/omnisharp/options.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index cf2a2b91e..9a8c86e79 100644 --- a/package.json +++ b/package.json @@ -323,6 +323,11 @@ "default": true, "description": "Suppress 'hidden' diagnostics (such as 'unnecessary using directives') from appearing in the editor or the Problems pane." }, + "csharp.showReferencesCodeLens": { + "type": "boolean", + "default": true, + "description": "Specifies whether the references CodeLens show be shown." + }, "omnisharp.path": { "type": [ "string", @@ -373,11 +378,6 @@ "type": "boolean", "default": true, "description": "Specifes whether OmniSharp should use VS Code editor settings for C# code formatting (use of tabs, indentation size)." - }, - "omnisharp.showReferencesCodeLens": { - "type": "boolean", - "default": true, - "description": "Specifies whether Omnisharp should show the references CodeLens" } } }, diff --git a/src/features/codeLensProvider.ts b/src/features/codeLensProvider.ts index 2165b3e3a..cccd3d6c0 100644 --- a/src/features/codeLensProvider.ts +++ b/src/features/codeLensProvider.ts @@ -47,8 +47,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen const options = Options.Read(); if (!options.showReferencesCodeLens) { - let arr: vscode.CodeLens[] = []; - return arr; + return []; } return serverUtils.currentFileMembersAsTree(this._server, { FileName: document.fileName }, token).then(tree => { diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index f0ae0edbd..56f4026c0 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -52,7 +52,7 @@ export class Options { const useFormatting = csharpConfig.get('format.enable', true); - const showReferencesCodeLens = omnisharpConfig.get('showReferencesCodeLens', true); + const showReferencesCodeLens = csharpConfig.get('showReferencesCodeLens', true); return new Options(path, useMono,