Allow disabling JS/TS suggestion actions

Fixes #46590
This commit is contained in:
Matt Bierner
2018-03-26 15:28:43 -07:00
parent 6eebe4ba3a
commit a1c693ab1a
4 changed files with 49 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ export class DiagnosticsManager {
private readonly _diagnostics = new Map<DiagnosticKind, DiagnosticSet>();
private readonly _currentDiagnostics: vscode.DiagnosticCollection;
private _validate: boolean = true;
private _enableSuggestions: boolean = true;
constructor(
language: string
@@ -68,12 +69,24 @@ export class DiagnosticsManager {
if (this._validate === value) {
return;
}
this._validate = value;
if (!value) {
this._currentDiagnostics.clear();
}
}
public set enableSuggestions(value: boolean) {
if (this._enableSuggestions === value) {
return;
}
this._enableSuggestions = value;
if (!value) {
this._currentDiagnostics.clear();
}
}
public diagnosticsReceived(
kind: DiagnosticKind,
file: vscode.Uri,
@@ -99,10 +112,12 @@ export class DiagnosticsManager {
return;
}
const allDiagnostics = allDiagnosticKinds.reduce((sum, kind) => {
sum.push(...this._diagnostics.get(kind)!.get(file));
return sum;
}, [] as vscode.Diagnostic[]);
const allDiagnostics: vscode.Diagnostic[] = [];
allDiagnostics.push(...this._diagnostics.get(DiagnosticKind.Syntax)!.get(file));
allDiagnostics.push(...this._diagnostics.get(DiagnosticKind.Semantic)!.get(file));
if (this._enableSuggestions) {
allDiagnostics.push(...this._diagnostics.get(DiagnosticKind.Suggestion)!.get(file));
}
this._currentDiagnostics.set(file, allDiagnostics);
}

View File

@@ -22,6 +22,7 @@ import { memoize } from './utils/memoize';
import { disposeAll } from './utils/dipose';
const validateSetting = 'validate.enable';
const suggestionSetting = 'suggestionActions.enabled';
const foldingSetting = 'typescript.experimental.syntaxFolding';
export default class LanguageProvider {
@@ -32,6 +33,7 @@ export default class LanguageProvider {
private readonly toUpdateOnConfigurationChanged: ({ updateConfiguration: () => void })[] = [];
private _validate: boolean = true;
private _enableSuggestionDiagnostics: boolean = true;
private readonly disposables: Disposable[] = [];
private readonly versionDependentDisposables: Disposable[] = [];
@@ -165,6 +167,7 @@ export default class LanguageProvider {
private configurationChanged(): void {
const config = workspace.getConfiguration(this.id);
this.updateValidate(config.get(validateSetting, true));
this.updateSuggestionDiagnostics(config.get(suggestionSetting, true));
for (const toUpdate of this.toUpdateOnConfigurationChanged) {
toUpdate.updateConfiguration();
@@ -204,6 +207,18 @@ export default class LanguageProvider {
}
}
private updateSuggestionDiagnostics(value: boolean) {
if (this._enableSuggestionDiagnostics === value) {
return;
}
this._enableSuggestionDiagnostics = value;
this.diagnosticsManager.enableSuggestions = value;
if (value) {
this.triggerAllDiagnostics();
}
}
public reInitialize(): void {
this.diagnosticsManager.reInitialize();
this.bufferSyncSupport.reOpenDocuments();