From 3114621321d122b3ca66feff0012ff472b87799c Mon Sep 17 00:00:00 2001 From: filipw Date: Fri, 6 Oct 2017 22:41:52 +0200 Subject: [PATCH 1/4] fixed references code lens and added ability to disable tests code lens --- src/features/codeLensProvider.ts | 13 +++++++++---- src/omnisharp/options.ts | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/features/codeLensProvider.ts b/src/features/codeLensProvider.ts index cccd3d6c0..022d58bdb 100644 --- a/src/features/codeLensProvider.ts +++ b/src/features/codeLensProvider.ts @@ -28,12 +28,14 @@ class OmniSharpCodeLens extends vscode.CodeLens { export default class OmniSharpCodeLensProvider extends AbstractProvider implements vscode.CodeLensProvider { private _testManager: TestManager; + private _options: Options; constructor(server: OmniSharpServer, reporter: TelemetryReporter, testManager: TestManager) { super(server, reporter); this._testManager = testManager; + this._options = Options.Read(); } private static filteredSymbolNames: { [name: string]: boolean } = { @@ -44,8 +46,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen }; provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable { - const options = Options.Read(); - if (!options.showReferencesCodeLens) + if (!this._options.showReferencesCodeLens && !this._options.showTestsCodeLens) { return []; } @@ -64,13 +65,17 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen } let lens = new OmniSharpCodeLens(fileName, toRange(node.Location)); - bucket.push(lens); + if (this._options.showReferencesCodeLens) { + bucket.push(lens); + } for (let child of node.ChildNodes) { this._convertQuickFix(bucket, fileName, child); } - this._updateCodeLensForTest(bucket, fileName, node); + if (this._options.showTestsCodeLens) { + this._updateCodeLensForTest(bucket, fileName, node); + } } resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Thenable { diff --git a/src/omnisharp/options.ts b/src/omnisharp/options.ts index 56f4026c0..d5db54416 100644 --- a/src/omnisharp/options.ts +++ b/src/omnisharp/options.ts @@ -16,7 +16,8 @@ export class Options { public maxProjectResults?: number, public useEditorFormattingSettings?: boolean, public useFormatting?: boolean, - public showReferencesCodeLens?: boolean) { } + public showReferencesCodeLens?: boolean, + public showTestsCodeLens?: boolean) { } public static Read(): Options { // Extra effort is taken below to ensure that legacy versions of options @@ -53,6 +54,7 @@ export class Options { const useFormatting = csharpConfig.get('format.enable', true); const showReferencesCodeLens = csharpConfig.get('showReferencesCodeLens', true); + const showTestsCodeLens = csharpConfig.get('showTestsCodeLens', true); return new Options(path, useMono, @@ -63,6 +65,7 @@ export class Options { maxProjectResults, useEditorFormattingSettings, useFormatting, - showReferencesCodeLens); + showReferencesCodeLens, + showTestsCodeLens); } } \ No newline at end of file From 737b71d568c9a2403fb42d060c0fd2b191b724e7 Mon Sep 17 00:00:00 2001 From: filipw Date: Fri, 6 Oct 2017 22:42:09 +0200 Subject: [PATCH 2/4] added settings to package.json --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 9a8c86e79..5eb7508cf 100644 --- a/package.json +++ b/package.json @@ -328,6 +328,11 @@ "default": true, "description": "Specifies whether the references CodeLens show be shown." }, + "csharp.showTestsCodeLens": { + "type": "boolean", + "default": true, + "description": "Specifies whether the run and debug test CodeLens show be shown." + }, "omnisharp.path": { "type": [ "string", From 4bb7fba21391e1ce87525faa0b68b3f7cf5222ec Mon Sep 17 00:00:00 2001 From: Filip W Date: Fri, 6 Oct 2017 23:10:21 +0200 Subject: [PATCH 3/4] fixed typo --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5eb7508cf..af77d9537 100644 --- a/package.json +++ b/package.json @@ -326,12 +326,12 @@ "csharp.showReferencesCodeLens": { "type": "boolean", "default": true, - "description": "Specifies whether the references CodeLens show be shown." + "description": "Specifies whether the references CodeLens should be show be shown." }, "csharp.showTestsCodeLens": { "type": "boolean", "default": true, - "description": "Specifies whether the run and debug test CodeLens show be shown." + "description": "Specifies whether the run and debug test CodeLens should be show be shown." }, "omnisharp.path": { "type": [ From f7a9c4975f605066aedd1e373784abeb41371b88 Mon Sep 17 00:00:00 2001 From: filipw Date: Sun, 8 Oct 2017 19:30:47 +0200 Subject: [PATCH 4/4] react to config changes immediately --- src/features/codeLensProvider.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/features/codeLensProvider.ts b/src/features/codeLensProvider.ts index 022d58bdb..0f1ecc45f 100644 --- a/src/features/codeLensProvider.ts +++ b/src/features/codeLensProvider.ts @@ -35,6 +35,13 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen super(server, reporter); this._testManager = testManager; + this._checkOptions(); + + let configChangedDisposable = vscode.workspace.onDidChangeConfiguration(this._checkOptions, this); + this.addDisposables(configChangedDisposable); + } + + private _checkOptions(): void { this._options = Options.Read(); }