Skip to content

Commit d76752f

Browse files
Merge pull request #1782 from filipw/bugfix/disable-references
Fixed disabling of code lens references
2 parents 38ffa15 + f7a9c49 commit d76752f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,12 @@
326326
"csharp.showReferencesCodeLens": {
327327
"type": "boolean",
328328
"default": true,
329-
"description": "Specifies whether the references CodeLens show be shown."
329+
"description": "Specifies whether the references CodeLens should be show be shown."
330+
},
331+
"csharp.showTestsCodeLens": {
332+
"type": "boolean",
333+
"default": true,
334+
"description": "Specifies whether the run and debug test CodeLens should be show be shown."
330335
},
331336
"omnisharp.path": {
332337
"type": [

src/features/codeLensProvider.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ class OmniSharpCodeLens extends vscode.CodeLens {
2828
export default class OmniSharpCodeLensProvider extends AbstractProvider implements vscode.CodeLensProvider {
2929

3030
private _testManager: TestManager;
31+
private _options: Options;
3132

3233
constructor(server: OmniSharpServer, reporter: TelemetryReporter, testManager: TestManager)
3334
{
3435
super(server, reporter);
3536

3637
this._testManager = testManager;
38+
this._checkOptions();
39+
40+
let configChangedDisposable = vscode.workspace.onDidChangeConfiguration(this._checkOptions, this);
41+
this.addDisposables(configChangedDisposable);
42+
}
43+
44+
private _checkOptions(): void {
45+
this._options = Options.Read();
3746
}
3847

3948
private static filteredSymbolNames: { [name: string]: boolean } = {
@@ -44,8 +53,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
4453
};
4554

4655
provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
47-
const options = Options.Read();
48-
if (!options.showReferencesCodeLens)
56+
if (!this._options.showReferencesCodeLens && !this._options.showTestsCodeLens)
4957
{
5058
return [];
5159
}
@@ -64,13 +72,17 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
6472
}
6573

6674
let lens = new OmniSharpCodeLens(fileName, toRange(node.Location));
67-
bucket.push(lens);
75+
if (this._options.showReferencesCodeLens) {
76+
bucket.push(lens);
77+
}
6878

6979
for (let child of node.ChildNodes) {
7080
this._convertQuickFix(bucket, fileName, child);
7181
}
7282

73-
this._updateCodeLensForTest(bucket, fileName, node);
83+
if (this._options.showTestsCodeLens) {
84+
this._updateCodeLensForTest(bucket, fileName, node);
85+
}
7486
}
7587

7688
resolveCodeLens(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Thenable<vscode.CodeLens> {

src/omnisharp/options.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class Options {
1616
public maxProjectResults?: number,
1717
public useEditorFormattingSettings?: boolean,
1818
public useFormatting?: boolean,
19-
public showReferencesCodeLens?: boolean) { }
19+
public showReferencesCodeLens?: boolean,
20+
public showTestsCodeLens?: boolean) { }
2021

2122
public static Read(): Options {
2223
// Extra effort is taken below to ensure that legacy versions of options
@@ -53,6 +54,7 @@ export class Options {
5354
const useFormatting = csharpConfig.get<boolean>('format.enable', true);
5455

5556
const showReferencesCodeLens = csharpConfig.get<boolean>('showReferencesCodeLens', true);
57+
const showTestsCodeLens = csharpConfig.get<boolean>('showTestsCodeLens', true);
5658

5759
return new Options(path,
5860
useMono,
@@ -63,6 +65,7 @@ export class Options {
6365
maxProjectResults,
6466
useEditorFormattingSettings,
6567
useFormatting,
66-
showReferencesCodeLens);
68+
showReferencesCodeLens,
69+
showTestsCodeLens);
6770
}
6871
}

0 commit comments

Comments
 (0)