Fixes #7186: Problem with changing languages

This commit is contained in:
Dirk Baeumer
2016-06-06 12:40:23 +02:00
parent 3cca023052
commit 50e579f9ac
2 changed files with 19 additions and 6 deletions
@@ -5,6 +5,7 @@
'use strict'; 'use strict';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path';
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable } from 'vscode'; import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable } from 'vscode';
import * as Proto from '../protocol'; import * as Proto from '../protocol';
@@ -78,6 +79,7 @@ export default class BufferSyncSupport {
private _validate: boolean; private _validate: boolean;
private modeIds: Map<boolean>; private modeIds: Map<boolean>;
private extensions: Map<boolean>;
private diagnostics: Diagnostics; private diagnostics: Diagnostics;
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
private syncedBuffers: Map<SyncedBuffer>; private syncedBuffers: Map<SyncedBuffer>;
@@ -86,11 +88,12 @@ export default class BufferSyncSupport {
private pendingDiagnostics: { [key: string]: number; }; private pendingDiagnostics: { [key: string]: number; };
private diagnosticDelayer: Delayer<any>; private diagnosticDelayer: Delayer<any>;
constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, validate: boolean = true) { constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, extensions: Map<boolean>, validate: boolean = true) {
this.client = client; this.client = client;
this.modeIds = Object.create(null); this.modeIds = Object.create(null);
modeIds.forEach(modeId => this.modeIds[modeId] = true); modeIds.forEach(modeId => this.modeIds[modeId] = true);
this.diagnostics = diagnostics; this.diagnostics = diagnostics;
this.extensions = extensions;
this._validate = validate; this._validate = validate;
this.pendingDiagnostics = Object.create(null); this.pendingDiagnostics = Object.create(null);
@@ -173,7 +176,7 @@ export default class BufferSyncSupport {
return; return;
} }
// If the file still exists on disk keep on validating the file. // 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; this.closedFiles[filepath] = true;
} else { } else {
// Ensure we don't have the file in the map and clear all errors. // Ensure we don't have the file in the map and clear all errors.
+14 -4
View File
@@ -16,6 +16,8 @@ import { env, languages, commands, workspace, window, Uri, ExtensionContext, Ind
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
nls.config({locale: env.language}); nls.config({locale: env.language});
import * as path from 'path';
import * as Proto from './protocol'; import * as Proto from './protocol';
import TypeScriptServiceClient from './typescriptServiceClient'; import TypeScriptServiceClient from './typescriptServiceClient';
import { ITypescriptServiceClientHost } from './typescriptService'; import { ITypescriptServiceClientHost } from './typescriptService';
@@ -39,6 +41,7 @@ interface LanguageDescription {
id: string; id: string;
diagnosticSource: string; diagnosticSource: string;
modeIds: string[]; modeIds: string[];
extensions: string[];
} }
export function activate(context: ExtensionContext): void { export function activate(context: ExtensionContext): void {
@@ -51,12 +54,14 @@ export function activate(context: ExtensionContext): void {
{ {
id: 'typescript', id: 'typescript',
diagnosticSource: 'ts', diagnosticSource: 'ts',
modeIds: [MODE_ID_TS, MODE_ID_TSX] modeIds: [MODE_ID_TS, MODE_ID_TSX],
extensions: ['.ts', '.tsx']
}, },
{ {
id: 'javascript', id: 'javascript',
diagnosticSource: 'js', 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 { class LanguageProvider {
private description: LanguageDescription; private description: LanguageDescription;
private extensions: Map<boolean>;
private syntaxDiagnostics: Map<Diagnostic[]>; private syntaxDiagnostics: Map<Diagnostic[]>;
private currentDiagnostics: DiagnosticCollection; private currentDiagnostics: DiagnosticCollection;
private bufferSyncSupport: BufferSyncSupport; private bufferSyncSupport: BufferSyncSupport;
@@ -96,16 +102,19 @@ class LanguageProvider {
constructor(client: TypeScriptServiceClient, description: LanguageDescription) { constructor(client: TypeScriptServiceClient, description: LanguageDescription) {
this.description = description; this.description = description;
this.extensions = Object.create(null);
description.extensions.forEach(extension => this.extensions[extension] = true);
this._validate = true; this._validate = true;
this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds, { this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds, {
delete: (file: string) => { delete: (file: string) => {
this.currentDiagnostics.delete(Uri.file(file)); this.currentDiagnostics.delete(Uri.file(file));
} }
}); }, this.extensions);
this.syntaxDiagnostics = Object.create(null); this.syntaxDiagnostics = Object.create(null);
this.currentDiagnostics = languages.createDiagnosticCollection(description.id); this.currentDiagnostics = languages.createDiagnosticCollection(description.id);
workspace.onDidChangeConfiguration(this.configurationChanged, this); workspace.onDidChangeConfiguration(this.configurationChanged, this);
this.configurationChanged(); this.configurationChanged();
@@ -220,7 +229,8 @@ class LanguageProvider {
} }
public handles(file: string): boolean { 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 { public get id(): string {