Skip to content

Commit 1ba9d83

Browse files
author
Matt Bierner
committed
Use uris instead of string paths in more locations
String paths should only be used when talking to the ts server
1 parent 5163810 commit 1ba9d83

6 files changed

Lines changed: 29 additions & 28 deletions

File tree

extensions/typescript/src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function goToProjectConfig(
121121

122122
const file = client.normalizePath(resource);
123123
// TSServer errors when 'projectInfo' is invoked on a non js/ts file
124-
if (!file || !clientHost.handles(file)) {
124+
if (!file || !clientHost.handles(resource)) {
125125
vscode.window.showWarningMessage(
126126
localize(
127127
'typescript.projectConfigUnsupportedFile',

extensions/typescript/src/features/bufferSyncSupport.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as fs from 'fs';
77

8-
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable } from 'vscode';
8+
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable, Uri } from 'vscode';
99
import * as Proto from '../protocol';
1010
import { ITypeScriptServiceClient } from '../typescriptService';
1111
import { Delayer } from '../utils/async';
@@ -142,8 +142,9 @@ export default class BufferSyncSupport {
142142
this._validate = value;
143143
}
144144

145-
public handles(file: string): boolean {
146-
return this.syncedBuffers.has(file);
145+
public handles(resource: Uri): boolean {
146+
const file = this.client.normalizePath(resource);
147+
return !!file && this.syncedBuffers.has(file);
147148
}
148149

149150
public reOpenDocuments(): void {

extensions/typescript/src/languageProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ export default class LanguageProvider {
171171
}
172172
}
173173

174-
public handles(file: string, doc: TextDocument): boolean {
174+
public handles(resource: Uri, doc: TextDocument): boolean {
175175
if (doc && this.description.modeIds.indexOf(doc.languageId) >= 0) {
176176
return true;
177177
}
178178

179-
if (this.bufferSyncSupport.handles(file)) {
179+
if (this.bufferSyncSupport.handles(resource)) {
180180
return true;
181181
}
182182

183-
const base = basename(file);
183+
const base = basename(resource.fsPath);
184184
return !!base && base === this.description.configFile;
185185
}
186186

extensions/typescript/src/typeScriptServiceClientHost.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export default class TypeScriptServiceClientHost {
7070
this.client = new TypeScriptServiceClient(workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider);
7171
this.disposables.push(this.client);
7272

73-
this.client.onSyntaxDiagnosticsReceived(({ file, diagnostics }) => this.syntaxDiagnosticsReceived(file, diagnostics), null, this.disposables);
74-
this.client.onSemanticDiagnosticsReceived(({ file, diagnostics }) => this.semanticDiagnosticsReceived(file, diagnostics), null, this.disposables);
73+
this.client.onSyntaxDiagnosticsReceived(({ resource, diagnostics }) => this.syntaxDiagnosticsReceived(resource, diagnostics), null, this.disposables);
74+
this.client.onSemanticDiagnosticsReceived(({ resource, diagnostics }) => this.semanticDiagnosticsReceived(resource, diagnostics), null, this.disposables);
7575
this.client.onConfigDiagnosticsReceived(diag => this.configFileDiagnosticsReceived(diag), null, this.disposables);
7676
this.client.onResendModelsRequested(() => this.populateService(), null, this.disposables);
7777

@@ -137,19 +137,19 @@ export default class TypeScriptServiceClientHost {
137137
this.triggerAllDiagnostics();
138138
}
139139

140-
public handles(file: string): boolean {
141-
return !!this.findLanguage(file);
140+
public handles(resource: Uri): boolean {
141+
return !!this.findLanguage(resource);
142142
}
143143

144144
private configurationChanged(): void {
145145
const config = workspace.getConfiguration('typescript');
146146
this.reportStyleCheckAsWarnings = config.get('reportStyleChecksAsWarnings', true);
147147
}
148148

149-
private async findLanguage(file: string): Promise<LanguageProvider | undefined> {
149+
private async findLanguage(resource: Uri): Promise<LanguageProvider | undefined> {
150150
try {
151-
const doc = await workspace.openTextDocument(this.client.asUrl(file));
152-
return this.languages.find(language => language.handles(file, doc));
151+
const doc = await workspace.openTextDocument(resource);
152+
return this.languages.find(language => language.handles(resource, doc));
153153
} catch {
154154
return undefined;
155155
}
@@ -170,20 +170,20 @@ export default class TypeScriptServiceClientHost {
170170
});
171171
}
172172

173-
private async syntaxDiagnosticsReceived(file: string, diagnostics: Proto.Diagnostic[]): Promise<void> {
174-
const language = await this.findLanguage(file);
173+
private async syntaxDiagnosticsReceived(resource: Uri, diagnostics: Proto.Diagnostic[]): Promise<void> {
174+
const language = await this.findLanguage(resource);
175175
if (language) {
176176
language.syntaxDiagnosticsReceived(
177-
this.client.asUrl(file),
177+
resource,
178178
this.createMarkerDatas(diagnostics, language.diagnosticSource));
179179
}
180180
}
181181

182-
private async semanticDiagnosticsReceived(file: string, diagnostics: Proto.Diagnostic[]): Promise<void> {
183-
const language = await this.findLanguage(file);
182+
private async semanticDiagnosticsReceived(resource: Uri, diagnostics: Proto.Diagnostic[]): Promise<void> {
183+
const language = await this.findLanguage(resource);
184184
if (language) {
185185
language.semanticDiagnosticsReceived(
186-
this.client.asUrl(file),
186+
resource,
187187
this.createMarkerDatas(diagnostics, language.diagnosticSource));
188188
}
189189
}
@@ -195,7 +195,7 @@ export default class TypeScriptServiceClientHost {
195195
return;
196196
}
197197

198-
(this.findLanguage(body.configFile)).then(language => {
198+
(this.findLanguage(this.client.asUrl(body.configFile))).then(language => {
199199
if (!language) {
200200
return;
201201
}

extensions/typescript/src/typescriptServiceClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class ForkedTsServerProcess {
140140
}
141141

142142
export interface TsDiagnostics {
143-
file: string;
144-
diagnostics: Proto.Diagnostic[];
143+
readonly resource: Uri;
144+
readonly diagnostics: Proto.Diagnostic[];
145145
}
146146

147147
export default class TypeScriptServiceClient implements ITypeScriptServiceClient {
@@ -802,7 +802,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
802802
const diagnosticEvent: Proto.DiagnosticEvent = event;
803803
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
804804
this._onSyntaxDiagnosticsReceived.fire({
805-
file: diagnosticEvent.body.file,
805+
resource: this.asUrl(diagnosticEvent.body.file),
806806
diagnostics: diagnosticEvent.body.diagnostics
807807
});
808808
}
@@ -813,7 +813,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
813813
const diagnosticEvent: Proto.DiagnosticEvent = event;
814814
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
815815
this._onSemanticDiagnosticsReceived.fire({
816-
file: diagnosticEvent.body.file,
816+
resource: this.asUrl(diagnosticEvent.body.file),
817817
diagnostics: diagnosticEvent.body.diagnostics
818818
});
819819
}

extensions/typescript/src/utils/projectStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ExcludeHintItem {
6363
}
6464
}
6565

66-
function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITypeScriptServiceClient, isOpen: (path: string) => Promise<boolean>, memento: vscode.Memento): vscode.Disposable[] {
66+
function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITypeScriptServiceClient, isOpen: (resource: vscode.Uri) => Promise<boolean>, memento: vscode.Memento): vscode.Disposable[] {
6767
const toDispose: vscode.Disposable[] = [];
6868
const projectHinted: ProjectHintedMap = Object.create(null);
6969

@@ -88,7 +88,7 @@ function createLargeProjectMonitorForProject(item: ExcludeHintItem, client: ITyp
8888
if (!file) {
8989
return;
9090
}
91-
isOpen(file).then(value => {
91+
isOpen(editor.document.uri).then(value => {
9292
if (!value) {
9393
return;
9494
}
@@ -175,7 +175,7 @@ function onConfigureExcludesSelected(
175175
export function create(
176176
client: ITypeScriptServiceClient,
177177
telemetryReporter: TelemetryReporter,
178-
isOpen: (path: string) => Promise<boolean>,
178+
isOpen: (resource: vscode.Uri) => Promise<boolean>,
179179
memento: vscode.Memento
180180
) {
181181
const toDispose: vscode.Disposable[] = [];

0 commit comments

Comments
 (0)