From 03c52009397d6d00111d208efb545358751bd17e Mon Sep 17 00:00:00 2001 From: sup39 Date: Sun, 17 Oct 2021 02:47:01 +0800 Subject: [PATCH] Support disabling suggestionActions by code number --- Readme.md | 11 ++++++++++- src/server/features/diagnostics.ts | 3 ++- src/server/languageProvider.ts | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 856e71d..4d97407 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,14 @@ ## Local Change -Disable annoying warning `[tsserver 80001] [I] File is a CommonJS module; it may be converted to an ES6 module.` permanently. +Support disabling suggestionActions by code number. + +### Example +In coc-settings.json: +``` +{ + "typescript.suggestionActions.disabledCodes": [80001, 80002], + "javascript.suggestionActions.disabledCodes": [80001, 80002, 7016] +} +``` # coc-tsserver diff --git a/src/server/features/diagnostics.ts b/src/server/features/diagnostics.ts index 9162aee..87cdd12 100644 --- a/src/server/features/diagnostics.ts +++ b/src/server/features/diagnostics.ts @@ -139,6 +139,7 @@ export class DiagnosticsManager { this._currentDiagnostics.set(uri, allDiagnostics) } + public disabledCodes: (string|number)[] = [] private getSuggestionDiagnostics(uri: string): Diagnostic[] { const enabled = this.suggestionsEnabled(uri) return this._diagnostics @@ -148,7 +149,7 @@ export class DiagnosticsManager { if (!enabled) { return x.tags && (x.tags.includes(DiagnosticTag.Unnecessary) || x.tags.includes(DiagnosticTag.Deprecated)) } - return x.code !== 80001 && x.code !== 80002 // disable annoying CommonJS module warning + return !this.disabledCodes.includes(x.code); }) } diff --git a/src/server/languageProvider.ts b/src/server/languageProvider.ts index efdb855..660cc4a 100644 --- a/src/server/languageProvider.ts +++ b/src/server/languageProvider.ts @@ -36,6 +36,7 @@ import { LanguageDescription } from './utils/languageDescription' import TypingsStatus from './utils/typingsStatus' const suggestionSetting = 'suggestionActions.enabled' +const disabledCodesSetting = 'suggestionActions.disabledCodes' export default class LanguageProvider { private readonly disposables: Disposable[] = [] @@ -61,6 +62,7 @@ export default class LanguageProvider { private configurationChanged(): void { const config = workspace.getConfiguration(this.id, null) this.client.diagnosticsManager.setEnableSuggestions(this.id, config.get(suggestionSetting, true)) + this.client.diagnosticsManager.disabledCodes = config.get(disabledCodesSetting, []); } public dispose(): void {