From 59ea6999aa9d1c37275092ec0ba6221b02a177b5 Mon Sep 17 00:00:00 2001 From: chemzqm Date: Mon, 22 Oct 2018 20:55:01 +0800 Subject: [PATCH] show diagnostics of config file --- src/server/features/diagnostics.ts | 7 +++++++ src/server/languageProvider.ts | 9 ++++++++- src/server/typescriptServiceClientHost.ts | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/server/features/diagnostics.ts b/src/server/features/diagnostics.ts index a956177..256beb0 100644 --- a/src/server/features/diagnostics.ts +++ b/src/server/features/diagnostics.ts @@ -110,6 +110,13 @@ export class DiagnosticsManager { this.scheduleDiagnosticsUpdate(uri) } + public configFileDiagnosticsReceived( + uri: string, + diagnostics: Diagnostic[] + ): void { + this._currentDiagnostics.set(uri, diagnostics) + } + public delete(uri: string): void { this._currentDiagnostics.delete(uri) } diff --git a/src/server/languageProvider.ts b/src/server/languageProvider.ts index 7d6bbcd..9ee35bb 100644 --- a/src/server/languageProvider.ts +++ b/src/server/languageProvider.ts @@ -280,8 +280,11 @@ export default class LanguageProvider { } public handles(resource: Uri): boolean { + let { modeIds, configFile } = this.description + if (resource.toString().endsWith(configFile)) { + return true + } let doc = workspace.getDocument(resource.toString()) - let { modeIds } = this.description if (doc && modeIds.indexOf(doc.filetype) !== -1) { return true } @@ -346,4 +349,8 @@ export default class LanguageProvider { diagnostics ) } + + public configFileDiagnosticsReceived(uri: Uri, diagnostics: Diagnostic[]): void { + this.diagnosticsManager.configFileDiagnosticsReceived(uri.toString(), diagnostics) + } } diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index 775bced..09267ca 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { DiagnosticKind, disposeAll, workspace } from 'coc.nvim' -import { Diagnostic, DiagnosticSeverity, Disposable } from 'vscode-languageserver-protocol' +import { Range, Diagnostic, DiagnosticSeverity, Disposable, Position } from 'vscode-languageserver-protocol' import Uri from 'vscode-uri' import LanguageProvider from './languageProvider' import * as Proto from './protocol' @@ -63,8 +63,17 @@ export default class TypeScriptServiceClientHost implements Disposable { let { body } = diag if (body) { let { configFile, diagnostics } = body - if (diagnostics.length) { - workspace.showMessage(`Invalid config file: ${configFile}`, 'error') + let uri = Uri.file(configFile) + let language = this.findLanguage(uri) + if (!language) return + if (diagnostics.length == 0) { + language.configFileDiagnosticsReceived(uri, []) + } else { + let range = Range.create(Position.create(0, 0), Position.create(0, 1)) + let { text, code, category } = diagnostics[0] + let severity = category == 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning + let diagnostic = Diagnostic.create(range, text, severity, code) + language.configFileDiagnosticsReceived(uri, [diagnostic]) } } }, null, this.disposables)