Skip to content

Commit 64b4921

Browse files
Merge pull request #1786 from DustinCampbell/option-caching-consistency
Make option caching consistent between providers
2 parents d76752f + 4c9ea96 commit 64b4921

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/features/codeActionProvider.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ import AbstractProvider from './abstractProvider';
1111
import * as protocol from '../omnisharp/protocol';
1212
import { toRange2 } from '../omnisharp/typeConvertion';
1313
import * as serverUtils from '../omnisharp/utils';
14+
import { Options } from '../omnisharp/options';
1415
import TelemetryReporter from 'vscode-extension-telemetry';
1516

1617
export default class CodeActionProvider extends AbstractProvider implements vscode.CodeActionProvider {
1718

18-
private _disabled: boolean;
19+
private _options: Options;
1920
private _commandId: string;
2021

2122
constructor(server: OmniSharpServer, reporter: TelemetryReporter) {
2223
super(server, reporter);
2324

2425
this._commandId = 'omnisharp.runCodeAction';
2526

26-
this._checkOption();
27+
this._resetCachedOptions();
2728

28-
let d1 = vscode.workspace.onDidChangeConfiguration(this._checkOption, this);
29+
let d1 = vscode.workspace.onDidChangeConfiguration(this._resetCachedOptions, this);
2930
let d2 = vscode.commands.registerCommand(this._commandId, this._runCodeAction, this);
3031
this.addDisposables(d1, d2);
3132
}
3233

33-
private _checkOption(): void {
34-
let value = vscode.workspace.getConfiguration().get('csharp.disableCodeActions', false);
35-
this._disabled = value;
34+
private _resetCachedOptions(): void {
35+
this._options = Options.Read();
3636
}
3737

3838
public provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<vscode.Command[]> {
39-
if (this._disabled) {
39+
if (this._options.disableCodeActions) {
4040
return;
4141
}
4242

src/features/codeLensProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
3535
super(server, reporter);
3636

3737
this._testManager = testManager;
38-
this._checkOptions();
38+
this._resetCachedOptions();
3939

40-
let configChangedDisposable = vscode.workspace.onDidChangeConfiguration(this._checkOptions, this);
40+
let configChangedDisposable = vscode.workspace.onDidChangeConfiguration(this._resetCachedOptions, this);
4141
this.addDisposables(configChangedDisposable);
4242
}
4343

44-
private _checkOptions(): void {
44+
private _resetCachedOptions(): void {
4545
this._options = Options.Read();
4646
}
4747

src/omnisharp/options.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class Options {
1717
public useEditorFormattingSettings?: boolean,
1818
public useFormatting?: boolean,
1919
public showReferencesCodeLens?: boolean,
20-
public showTestsCodeLens?: boolean) { }
20+
public showTestsCodeLens?: boolean,
21+
public disableCodeActions?: boolean) { }
2122

2223
public static Read(): Options {
2324
// Extra effort is taken below to ensure that legacy versions of options
@@ -56,6 +57,8 @@ export class Options {
5657
const showReferencesCodeLens = csharpConfig.get<boolean>('showReferencesCodeLens', true);
5758
const showTestsCodeLens = csharpConfig.get<boolean>('showTestsCodeLens', true);
5859

60+
const disableCodeActions = csharpConfig.get<boolean>('disableCodeActions', false);
61+
5962
return new Options(path,
6063
useMono,
6164
waitForDebugger,
@@ -66,6 +69,7 @@ export class Options {
6669
useEditorFormattingSettings,
6770
useFormatting,
6871
showReferencesCodeLens,
69-
showTestsCodeLens);
72+
showTestsCodeLens,
73+
disableCodeActions);
7074
}
7175
}

0 commit comments

Comments
 (0)