Support disabling suggestionActions by code number

This commit is contained in:
sup39 2021-10-17 02:47:01 +08:00
parent 701f309f3d
commit 03c5200939
3 changed files with 14 additions and 2 deletions

View file

@ -1,5 +1,14 @@
## Local Change ## 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 # coc-tsserver

View file

@ -139,6 +139,7 @@ export class DiagnosticsManager {
this._currentDiagnostics.set(uri, allDiagnostics) this._currentDiagnostics.set(uri, allDiagnostics)
} }
public disabledCodes: (string|number)[] = []
private getSuggestionDiagnostics(uri: string): Diagnostic[] { private getSuggestionDiagnostics(uri: string): Diagnostic[] {
const enabled = this.suggestionsEnabled(uri) const enabled = this.suggestionsEnabled(uri)
return this._diagnostics return this._diagnostics
@ -148,7 +149,7 @@ export class DiagnosticsManager {
if (!enabled) { if (!enabled) {
return x.tags && (x.tags.includes(DiagnosticTag.Unnecessary) || x.tags.includes(DiagnosticTag.Deprecated)) 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);
}) })
} }

View file

@ -36,6 +36,7 @@ import { LanguageDescription } from './utils/languageDescription'
import TypingsStatus from './utils/typingsStatus' import TypingsStatus from './utils/typingsStatus'
const suggestionSetting = 'suggestionActions.enabled' const suggestionSetting = 'suggestionActions.enabled'
const disabledCodesSetting = 'suggestionActions.disabledCodes'
export default class LanguageProvider { export default class LanguageProvider {
private readonly disposables: Disposable[] = [] private readonly disposables: Disposable[] = []
@ -61,6 +62,7 @@ export default class LanguageProvider {
private configurationChanged(): void { private configurationChanged(): void {
const config = workspace.getConfiguration(this.id, null) const config = workspace.getConfiguration(this.id, null)
this.client.diagnosticsManager.setEnableSuggestions(this.id, config.get(suggestionSetting, true)) this.client.diagnosticsManager.setEnableSuggestions(this.id, config.get(suggestionSetting, true))
this.client.diagnosticsManager.disabledCodes = config.get(disabledCodesSetting, []);
} }
public dispose(): void { public dispose(): void {