From fff7bdd57f06b8a613e9ccb27a7cc97b1ecca59f Mon Sep 17 00:00:00 2001 From: chemzqm Date: Tue, 11 Jun 2019 15:42:52 +0800 Subject: [PATCH] fix validate.enable not work sometimes --- src/server/features/bufferSyncSupport.ts | 18 +++++++++++------- src/server/languageProvider.ts | 9 +++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/server/features/bufferSyncSupport.ts b/src/server/features/bufferSyncSupport.ts index 5bca5b3..789104e 100644 --- a/src/server/features/bufferSyncSupport.ts +++ b/src/server/features/bufferSyncSupport.ts @@ -271,7 +271,10 @@ export default class BufferSyncSupport { } for (const resource of handledResources) { - this.pendingDiagnostics.set(resource.toString(), Date.now()) + let uri = resource.toString() + if (this.shouldValidate(uri)) { + this.pendingDiagnostics.set(uri, Date.now()) + } } this.triggerDiagnostics() @@ -285,8 +288,7 @@ export default class BufferSyncSupport { public requestAllDiagnostics(): void { for (const uri of this.uris) { - let doc = workspace.getDocument(uri) - if (doc && this.shouldValidate(doc.filetype)) { + if (this.shouldValidate(uri)) { this.pendingDiagnostics.set(uri, Date.now()) } } @@ -297,7 +299,7 @@ export default class BufferSyncSupport { public requestDiagnostic(uri: string): boolean { let document = workspace.getDocument(uri) - if (!document || !this.shouldValidate(document.filetype)) return false + if (!document || !this.shouldValidate(uri)) return false this.pendingDiagnostics.set(uri, Date.now()) const lineCount = document.lineCount const delay = Math.min(Math.max(Math.ceil(lineCount / 20), 300), 800) @@ -339,11 +341,13 @@ export default class BufferSyncSupport { this._validateTypeScript = tsConfig.get('validate.enable', true) } - private shouldValidate(filetype: string): boolean { - if (languageModeIds.languageIds.indexOf(filetype) == -1) { + public shouldValidate(uri: string): boolean { + let doc = workspace.getDocument(uri) + if (!doc) return false + if (languageModeIds.languageIds.indexOf(doc.filetype) == -1) { return false } - if (filetype.startsWith('javascript')) { + if (doc.filetype.startsWith('javascript')) { return this._validateJavaScript } return this._validateTypeScript diff --git a/src/server/languageProvider.ts b/src/server/languageProvider.ts index b41d5bd..0160365 100644 --- a/src/server/languageProvider.ts +++ b/src/server/languageProvider.ts @@ -313,12 +313,9 @@ export default class LanguageProvider { file: Uri, diagnostics: (Diagnostic & { reportUnnecessary: any })[] ): void { - this.client.diagnosticsManager.diagnosticsReceived( - diagnosticsKind, - file.toString(), - diagnostics - ) - + if (!this.client.bufferSyncSupport.shouldValidate(file.toString())) { + return + } const config = workspace.getConfiguration(this.id, file.toString()) const reportUnnecessary = config.get('showUnused', true) this.client.diagnosticsManager.diagnosticsReceived(diagnosticsKind, file.toString(), diagnostics.filter(diag => {