diff --git a/extensions/typescript/src/features/bufferSyncSupport.ts b/extensions/typescript/src/features/bufferSyncSupport.ts index 89ade4b5e1a19f2df52264f21c639a6916bb7dc6..4225c0c54283e288b318b14e052eed8e64f5c495 100644 --- a/extensions/typescript/src/features/bufferSyncSupport.ts +++ b/extensions/typescript/src/features/bufferSyncSupport.ts @@ -5,6 +5,7 @@ 'use strict'; import * as fs from 'fs'; +import * as path from 'path'; import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable } from 'vscode'; import * as Proto from '../protocol'; @@ -78,6 +79,7 @@ export default class BufferSyncSupport { private _validate: boolean; private modeIds: Map; + private extensions: Map; private diagnostics: Diagnostics; private disposables: Disposable[] = []; private syncedBuffers: Map; @@ -86,11 +88,12 @@ export default class BufferSyncSupport { private pendingDiagnostics: { [key: string]: number; }; private diagnosticDelayer: Delayer; - constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, validate: boolean = true) { + constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, extensions: Map, validate: boolean = true) { this.client = client; this.modeIds = Object.create(null); modeIds.forEach(modeId => this.modeIds[modeId] = true); this.diagnostics = diagnostics; + this.extensions = extensions; this._validate = validate; this.pendingDiagnostics = Object.create(null); @@ -173,7 +176,7 @@ export default class BufferSyncSupport { return; } // If the file still exists on disk keep on validating the file. - if (fs.existsSync(filepath)) { + if (fs.existsSync(filepath) && this.extensions[path.extname(filepath)]) { this.closedFiles[filepath] = true; } else { // Ensure we don't have the file in the map and clear all errors. diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index 57e05ea5ac4a3bc69e454c16951ef9840f977ef7..a336d72f4b0b379b9b38775b45d5f089af8182ad 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -16,6 +16,8 @@ import { env, languages, commands, workspace, window, Uri, ExtensionContext, Ind import * as nls from 'vscode-nls'; nls.config({locale: env.language}); +import * as path from 'path'; + import * as Proto from './protocol'; import TypeScriptServiceClient from './typescriptServiceClient'; import { ITypescriptServiceClientHost } from './typescriptService'; @@ -39,6 +41,7 @@ interface LanguageDescription { id: string; diagnosticSource: string; modeIds: string[]; + extensions: string[]; } export function activate(context: ExtensionContext): void { @@ -51,12 +54,14 @@ export function activate(context: ExtensionContext): void { { id: 'typescript', diagnosticSource: 'ts', - modeIds: [MODE_ID_TS, MODE_ID_TSX] + modeIds: [MODE_ID_TS, MODE_ID_TSX], + extensions: ['.ts', '.tsx'] }, { id: 'javascript', diagnosticSource: 'js', - modeIds: [MODE_ID_JS, MODE_ID_JSX] + modeIds: [MODE_ID_JS, MODE_ID_JSX], + extensions: ['.js', '.jsx'] } ]); @@ -85,6 +90,7 @@ const validateSetting = 'validate.enable'; class LanguageProvider { private description: LanguageDescription; + private extensions: Map; private syntaxDiagnostics: Map; private currentDiagnostics: DiagnosticCollection; private bufferSyncSupport: BufferSyncSupport; @@ -96,16 +102,19 @@ class LanguageProvider { constructor(client: TypeScriptServiceClient, description: LanguageDescription) { this.description = description; + this.extensions = Object.create(null); + description.extensions.forEach(extension => this.extensions[extension] = true); this._validate = true; this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds, { delete: (file: string) => { this.currentDiagnostics.delete(Uri.file(file)); } - }); + }, this.extensions); this.syntaxDiagnostics = Object.create(null); this.currentDiagnostics = languages.createDiagnosticCollection(description.id); + workspace.onDidChangeConfiguration(this.configurationChanged, this); this.configurationChanged(); @@ -220,7 +229,8 @@ class LanguageProvider { } public handles(file: string): boolean { - return this.bufferSyncSupport.handles(file); + let extension = path.extname(file); + return (extension && this.extensions[extension]) || this.bufferSyncSupport.handles(file); } public get id(): string {