-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeScriptServiceClient.ts
34 lines (27 loc) · 1.15 KB
/
typeScriptServiceClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as vscode from 'vscode';
import { ITypeScriptServiceClient } from './ITypeScriptServiceClient';
export default class TypeScriptServiceClient implements ITypeScriptServiceClient {
private pathSeparator: string = "\\";
public normalizedPath(resource: vscode.Uri): string | undefined {
const result = resource.fsPath;
if (!result) {
return undefined;
}
// Both \ and / must be escaped in regular expressions
return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/');
}
public toPath(resource: vscode.Uri): string | undefined {
return this.normalizedPath(resource);
}
public toOpenedFilePath(document: vscode.TextDocument): string | undefined {
// TODO : Handle large files
return this.toPath(document.uri) || undefined;
}
public toResource(filepath: string, document: vscode.TextDocument): vscode.Uri {
if(document.uri.scheme === "untitled") { // when trying to find references in a file which isnt saved
return document.uri;
}
let resource = vscode.Uri.file(filepath);
return resource;
}
}