fix suggestionActions.enabled option not working
This commit is contained in:
parent
bda7301e8b
commit
c3d2bc4d4d
3 changed files with 37 additions and 27 deletions
|
@ -3,7 +3,7 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { Diagnostic } from 'vscode-languageserver-protocol'
|
import { Diagnostic } from 'vscode-languageserver-protocol'
|
||||||
import { languages, DiagnosticCollection } from 'coc.nvim'
|
import { workspace, languages, DiagnosticCollection } from 'coc.nvim'
|
||||||
import { ResourceMap } from './resourceMap'
|
import { ResourceMap } from './resourceMap'
|
||||||
|
|
||||||
export class DiagnosticSet {
|
export class DiagnosticSet {
|
||||||
|
@ -38,8 +38,8 @@ export class DiagnosticsManager {
|
||||||
private readonly _diagnostics = new Map<DiagnosticKind, DiagnosticSet>()
|
private readonly _diagnostics = new Map<DiagnosticKind, DiagnosticSet>()
|
||||||
private readonly _currentDiagnostics: DiagnosticCollection
|
private readonly _currentDiagnostics: DiagnosticCollection
|
||||||
private _pendingUpdates = new ResourceMap<any>()
|
private _pendingUpdates = new ResourceMap<any>()
|
||||||
private _validate = true
|
private _enableJavascriptSuggestions = true
|
||||||
private _enableSuggestions = true
|
private _enableTypescriptSuggestions = true
|
||||||
|
|
||||||
private readonly updateDelay = 200
|
private readonly updateDelay = 200
|
||||||
|
|
||||||
|
@ -65,25 +65,15 @@ export class DiagnosticsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public set validate(value: boolean) {
|
public setEnableSuggestions(languageId: string, value: boolean): void {
|
||||||
if (this._validate === value) {
|
let curr = languageId == 'javascript' ? this._enableJavascriptSuggestions : this._enableTypescriptSuggestions
|
||||||
|
if (curr == value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (languageId == 'javascript') {
|
||||||
this._validate = value
|
this._enableJavascriptSuggestions = value
|
||||||
if (!value) {
|
} else {
|
||||||
this._currentDiagnostics.clear()
|
this._enableTypescriptSuggestions = value
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public set enableSuggestions(value: boolean) {
|
|
||||||
if (this._enableSuggestions === value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this._enableSuggestions = value
|
|
||||||
if (!value) {
|
|
||||||
this._currentDiagnostics.clear()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +129,6 @@ export class DiagnosticsManager {
|
||||||
this._pendingUpdates.delete(uri)
|
this._pendingUpdates.delete(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._validate) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const allDiagnostics = [
|
const allDiagnostics = [
|
||||||
...this._diagnostics.get(DiagnosticKind.Syntax)!.get(uri),
|
...this._diagnostics.get(DiagnosticKind.Syntax)!.get(uri),
|
||||||
...this._diagnostics.get(DiagnosticKind.Semantic)!.get(uri),
|
...this._diagnostics.get(DiagnosticKind.Semantic)!.get(uri),
|
||||||
|
@ -152,15 +138,28 @@ export class DiagnosticsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSuggestionDiagnostics(uri: string): Diagnostic[] {
|
private getSuggestionDiagnostics(uri: string): Diagnostic[] {
|
||||||
|
const enabled = this.suggestionsEnabled(uri)
|
||||||
return this._diagnostics
|
return this._diagnostics
|
||||||
.get(DiagnosticKind.Suggestion)!
|
.get(DiagnosticKind.Suggestion)!
|
||||||
.get(uri)
|
.get(uri)
|
||||||
.filter(x => {
|
.filter(x => {
|
||||||
if (!this._enableSuggestions) {
|
if (!enabled) {
|
||||||
// Still show unused
|
// 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ import { LanguageDescription } from './utils/languageDescription'
|
||||||
import TypingsStatus from './utils/typingsStatus'
|
import TypingsStatus from './utils/typingsStatus'
|
||||||
import { OrganizeImportsCodeActionProvider } from './organizeImports'
|
import { OrganizeImportsCodeActionProvider } from './organizeImports'
|
||||||
|
|
||||||
|
const suggestionSetting = 'suggestionActions.enabled'
|
||||||
|
|
||||||
export default class LanguageProvider {
|
export default class LanguageProvider {
|
||||||
public readonly fileConfigurationManager: FileConfigurationManager // tslint:disable-line
|
public readonly fileConfigurationManager: FileConfigurationManager // tslint:disable-line
|
||||||
private readonly disposables: Disposable[] = []
|
private readonly disposables: Disposable[] = []
|
||||||
|
@ -45,6 +47,9 @@ export default class LanguageProvider {
|
||||||
) {
|
) {
|
||||||
this.fileConfigurationManager = new FileConfigurationManager(client)
|
this.fileConfigurationManager = new FileConfigurationManager(client)
|
||||||
|
|
||||||
|
workspace.onDidChangeConfiguration(this.configurationChanged, this, this.disposables)
|
||||||
|
this.configurationChanged()
|
||||||
|
|
||||||
events.on('BufEnter', bufnr => {
|
events.on('BufEnter', bufnr => {
|
||||||
let doc = workspace.getDocument(bufnr)
|
let doc = workspace.getDocument(bufnr)
|
||||||
if (!doc || client.state !== ServiceStat.Running) return
|
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 {
|
public dispose(): void {
|
||||||
disposeAll(this.disposables)
|
disposeAll(this.disposables)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ export default class TypeScriptServiceClientHost implements Disposable {
|
||||||
this.client.onTsServerStarted(() => {
|
this.client.onTsServerStarted(() => {
|
||||||
this.triggerAllDiagnostics()
|
this.triggerAllDiagnostics()
|
||||||
})
|
})
|
||||||
|
workspace.onDidChangeConfiguration(this.configurationChanged, this, this.disposables)
|
||||||
this.configurationChanged()
|
this.configurationChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue