提交 1ba9d83f 编写于 作者: M Matt Bierner

Use uris instead of string paths in more locations

String paths should only be used when talking to the ts server
上级 51638106
......@@ -121,7 +121,7 @@ async function goToProjectConfig(
const file = client.normalizePath(resource);
// TSServer errors when 'projectInfo' is invoked on a non js/ts file
if (!file || !clientHost.handles(file)) {
if (!file || !clientHost.handles(resource)) {
vscode.window.showWarningMessage(
localize(
'typescript.projectConfigUnsupportedFile',
......
......@@ -5,7 +5,7 @@
import * as fs from 'fs';
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable } from 'vscode';
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable, Uri } from 'vscode';
import * as Proto from '../protocol';
import { ITypeScriptServiceClient } from '../typescriptService';
import { Delayer } from '../utils/async';
......@@ -142,8 +142,9 @@ export default class BufferSyncSupport {
this._validate = value;
}
public handles(file: string): boolean {
return this.syncedBuffers.has(file);
public handles(resource: Uri): boolean {
const file = this.client.normalizePath(resource);
return !!file && this.syncedBuffers.has(file);
}
public reOpenDocuments(): void {
......
......@@ -171,16 +171,16 @@ export default class LanguageProvider {
}
}
public handles(file: string, doc: TextDocument): boolean {
public handles(resource: Uri, doc: TextDocument): boolean {
if (doc && this.description.modeIds.indexOf(doc.languageId) >= 0) {
return true;
}
if (this.bufferSyncSupport.handles(file)) {
if (this.bufferSyncSupport.handles(resource)) {
return true;
}
const base = basename(file);
const base = basename(resource.fsPath);
return !!base && base === this.description.configFile;
}
......
......@@ -70,8 +70,8 @@ export default class TypeScriptServiceClientHost {
this.client = new TypeScriptServiceClient(workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider);
this.disposables.push(this.client);
this.client.onSyntaxDiagnosticsReceived(({ file, diagnostics }) => this.syntaxDiagnosticsReceived(file, diagnostics), null, this.disposables);
this.client.onSemanticDiagnosticsReceived(({ file, diagnostics }) => this.semanticDiagnosticsReceived(file, diagnostics), null, this.disposables);
this.client.onSyntaxDiagnosticsReceived(({ resource, diagnostics }) => this.syntaxDiagnosticsReceived(resource, diagnostics), null, this.disposables);
this.client.onSemanticDiagnosticsReceived(({ resource, diagnostics }) => this.semanticDiagnosticsReceived(resource, diagnostics), null, this.disposables);
this.client.onConfigDiagnosticsReceived(diag => this.configFileDiagnosticsReceived(diag), null, this.disposables);
this.client.onResendModelsRequested(() => this.populateService(), null, this.disposables);
......@@ -137,8 +137,8 @@ export default class TypeScriptServiceClientHost {
this.triggerAllDiagnostics();
}
public handles(file: string): boolean {
return !!this.findLanguage(file);
public handles(resource: Uri): boolean {
return !!this.findLanguage(resource);
}
private configurationChanged(): void {
......@@ -146,10 +146,10 @@ export default class TypeScriptServiceClientHost {
this.reportStyleCheckAsWarnings = config.get('reportStyleChecksAsWarnings', true);
}
private async findLanguage(file: string): Promise<LanguageProvider | undefined> {
private async findLanguage(resource: Uri): Promise<LanguageProvider | undefined> {
try {
const doc = await workspace.openTextDocument(this.client.asUrl(file));
return this.languages.find(language => language.handles(file, doc));
const doc = await workspace.openTextDocument(resource);
return this.languages.find(language => language.handles(resource, doc));
} catch {
return undefined;
}
......@@ -170,20 +170,20 @@ export default class TypeScriptServiceClientHost {
});
}
private async syntaxDiagnosticsReceived(file: string, diagnostics: Proto.Diagnostic[]): Promise<void> {
const language = await this.findLanguage(file);
private async syntaxDiagnosticsReceived(resource: Uri, diagnostics: Proto.Diagnostic[]): Promise<void> {
const language = await this.findLanguage(resource);
if (language) {
language.syntaxDiagnosticsReceived(
this.client.asUrl(file),
resource,
this.createMarkerDatas(diagnostics, language.diagnosticSource));
}
}
private async semanticDiagnosticsReceived(file: string, diagnostics: Proto.Diagnostic[]): Promise<void> {
const language = await this.findLanguage(file);
private async semanticDiagnosticsReceived(resource: Uri, diagnostics: Proto.Diagnostic[]): Promise<void> {
const language = await this.findLanguage(resource);
if (language) {
language.semanticDiagnosticsReceived(
this.client.asUrl(file),
resource,
this.createMarkerDatas(diagnostics, language.diagnosticSource));
}
}
......@@ -195,7 +195,7 @@ export default class TypeScriptServiceClientHost {
return;
}
(this.findLanguage(body.configFile)).then(language => {
(this.findLanguage(this.client.asUrl(body.configFile))).then(language => {
if (!language) {
return;
}
......
......@@ -140,8 +140,8 @@ class ForkedTsServerProcess {
}
export interface TsDiagnostics {
file: string;
diagnostics: Proto.Diagnostic[];
readonly resource: Uri;
readonly diagnostics: Proto.Diagnostic[];
}
export default class TypeScriptServiceClient implements ITypeScriptServiceClient {
......@@ -802,7 +802,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
const diagnosticEvent: Proto.DiagnosticEvent = event;
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
this._onSyntaxDiagnosticsReceived.fire({
file: diagnosticEvent.body.file,
resource: this.asUrl(diagnosticEvent.body.file),
diagnostics: diagnosticEvent.body.diagnostics
});
}
......@@ -813,7 +813,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
const diagnosticEvent: Proto.DiagnosticEvent = event;
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
this._onSemanticDiagnosticsReceived.fire({
file: diagnosticEvent.body.file,
resource: this.asUrl(diagnosticEvent.body.file),
diagnostics: diagnosticEvent.body.diagnostics
});
}
......
......@@ -63,7 +63,7 @@ class ExcludeHintItem {
}
}
function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITypeScriptServiceClient, isOpen: (path: string) => Promise<boolean>, memento: vscode.Memento): vscode.Disposable[] {
function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITypeScriptServiceClient, isOpen: (resource: vscode.Uri) => Promise<boolean>, memento: vscode.Memento): vscode.Disposable[] {
const toDispose: vscode.Disposable[] = [];
const projectHinted: ProjectHintedMap = Object.create(null);
......@@ -88,7 +88,7 @@ function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITyp
if (!file) {
return;
}
isOpen(file).then(value => {
isOpen(editor.document.uri).then(value => {
if (!value) {
return;
}
......@@ -175,7 +175,7 @@ function onConfigureExcludesSelected(
export function create(
client: ITypeScriptServiceClient,
telemetryReporter: TelemetryReporter,
isOpen: (path: string) => Promise<boolean>,
isOpen: (resource: vscode.Uri) => Promise<boolean>,
memento: vscode.Memento
) {
const toDispose: vscode.Disposable[] = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册