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
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

View file

@ -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);
})
}

View file

@ -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 {