From c3d2bc4d4dfbd1f43b7df3cd7372970e8acdf7c8 Mon Sep 17 00:00:00 2001 From: chemzqm Date: Tue, 11 Jun 2019 17:36:41 +0800 Subject: [PATCH] fix suggestionActions.enabled option not working --- src/server/features/diagnostics.ts | 53 +++++++++++------------ src/server/languageProvider.ts | 10 +++++ src/server/typescriptServiceClientHost.ts | 1 + 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/server/features/diagnostics.ts b/src/server/features/diagnostics.ts index 33ebbb5..ad08046 100644 --- a/src/server/features/diagnostics.ts +++ b/src/server/features/diagnostics.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Diagnostic } from 'vscode-languageserver-protocol' -import { languages, DiagnosticCollection } from 'coc.nvim' +import { workspace, languages, DiagnosticCollection } from 'coc.nvim' import { ResourceMap } from './resourceMap' export class DiagnosticSet { @@ -38,8 +38,8 @@ export class DiagnosticsManager { private readonly _diagnostics = new Map() private readonly _currentDiagnostics: DiagnosticCollection private _pendingUpdates = new ResourceMap() - private _validate = true - private _enableSuggestions = true + private _enableJavascriptSuggestions = true + private _enableTypescriptSuggestions = true private readonly updateDelay = 200 @@ -65,25 +65,15 @@ export class DiagnosticsManager { } } - public set validate(value: boolean) { - if (this._validate === value) { + public setEnableSuggestions(languageId: string, value: boolean): void { + let curr = languageId == 'javascript' ? this._enableJavascriptSuggestions : this._enableTypescriptSuggestions + if (curr == 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() + if (languageId == 'javascript') { + this._enableJavascriptSuggestions = value + } else { + this._enableTypescriptSuggestions = value } } @@ -139,10 +129,6 @@ export class DiagnosticsManager { this._pendingUpdates.delete(uri) } - if (!this._validate) { - return - } - const allDiagnostics = [ ...this._diagnostics.get(DiagnosticKind.Syntax)!.get(uri), ...this._diagnostics.get(DiagnosticKind.Semantic)!.get(uri), @@ -152,15 +138,28 @@ export class DiagnosticsManager { } private getSuggestionDiagnostics(uri: string): Diagnostic[] { + const enabled = this.suggestionsEnabled(uri) return this._diagnostics .get(DiagnosticKind.Suggestion)! .get(uri) .filter(x => { - if (!this._enableSuggestions) { + if (!enabled) { // Still show unused - return x.code && x.code == 6133 + return x.tags && x.tags.includes(1) } - return true + return enabled }) } + + private suggestionsEnabled(uri: string): boolean { + let doc = workspace.getDocument(uri) + if (!doc) return false + if (doc.filetype.startsWith('javascript')) { + return this._enableJavascriptSuggestions + } + if (doc.filetype.startsWith('typescript')) { + return this._enableTypescriptSuggestions + } + return true + } } diff --git a/src/server/languageProvider.ts b/src/server/languageProvider.ts index 0160365..74dbb3f 100644 --- a/src/server/languageProvider.ts +++ b/src/server/languageProvider.ts @@ -34,6 +34,8 @@ import { LanguageDescription } from './utils/languageDescription' import TypingsStatus from './utils/typingsStatus' import { OrganizeImportsCodeActionProvider } from './organizeImports' +const suggestionSetting = 'suggestionActions.enabled' + export default class LanguageProvider { public readonly fileConfigurationManager: FileConfigurationManager // tslint:disable-line private readonly disposables: Disposable[] = [] @@ -45,6 +47,9 @@ export default class LanguageProvider { ) { this.fileConfigurationManager = new FileConfigurationManager(client) + workspace.onDidChangeConfiguration(this.configurationChanged, this, this.disposables) + this.configurationChanged() + events.on('BufEnter', bufnr => { let doc = workspace.getDocument(bufnr) if (!doc || client.state !== ServiceStat.Running) return @@ -69,6 +74,11 @@ export default class LanguageProvider { }) } + private configurationChanged(): void { + const config = workspace.getConfiguration(this.id, null) + this.client.diagnosticsManager.setEnableSuggestions(this.id, config.get(suggestionSetting, true)) + } + public dispose(): void { disposeAll(this.disposables) } diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index ec59c5e..04aad43 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -92,6 +92,7 @@ export default class TypeScriptServiceClientHost implements Disposable { this.client.onTsServerStarted(() => { this.triggerAllDiagnostics() }) + workspace.onDidChangeConfiguration(this.configurationChanged, this, this.disposables) this.configurationChanged() }