提交 a1c693ab 编写于 作者: M Matt Bierner

Allow disabling JS/TS suggestion actions

Fixes #46590
上级 6eebe4ba
......@@ -413,6 +413,18 @@
"type": "boolean",
"default": true,
"description": "%typescript.experimental.syntaxFolding%"
},
"javascript.suggestionActions.enabled": {
"type": "boolean",
"default": true,
"description": "%javascript.suggestionActions.enabled%",
"scope": "window"
},
"typescript.suggestionActions.enabled": {
"type": "boolean",
"default": true,
"description": "%typescript.suggestionActions.enabled%",
"scope": "window"
}
}
},
......
......@@ -53,5 +53,7 @@
"typescript.autoImportSuggestions.enabled": "Enable/disable auto import suggestions. Requires TypeScript >=2.6.1",
"typescript.experimental.syntaxFolding": "Enables/disables syntax aware folding markers.",
"taskDefinition.tsconfig.description": "The tsconfig file that defines the TS build.",
"typescript.organizeImports": "Organize Imports"
"typescript.organizeImports": "Organize Imports",
"javascript.suggestionActions.enabled": "Enable/disable suggestion diagnostics for JavaScript files in the editor. Requires TypeScript >= 2.8",
"typescript.suggestionActions.enabled": "Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires TypeScript >= 2.8."
}
\ No newline at end of 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);
}
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册