mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Fixes #7186: Problem with changing languages
This commit is contained in:
@@ -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<boolean>;
|
||||
private extensions: Map<boolean>;
|
||||
private diagnostics: Diagnostics;
|
||||
private disposables: Disposable[] = [];
|
||||
private syncedBuffers: Map<SyncedBuffer>;
|
||||
@@ -86,11 +88,12 @@ export default class BufferSyncSupport {
|
||||
private pendingDiagnostics: { [key: string]: number; };
|
||||
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.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.
|
||||
|
||||
@@ -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<boolean>;
|
||||
private syntaxDiagnostics: Map<Diagnostic[]>;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user