未验证 提交 00f0f2c8 编写于 作者: M Matt Bierner 提交者: GitHub

Use special prefix to tell TS that a resource is in-memory only (#42001)

* Use special prefix to tell TS that a resource is in memory

* Move scheme checking logic into getWorkspaceRootForResource
上级 65064fd5
...@@ -10,6 +10,7 @@ import * as Proto from '../protocol'; ...@@ -10,6 +10,7 @@ import * as Proto from '../protocol';
import { ITypeScriptServiceClient } from '../typescriptService'; import { ITypeScriptServiceClient } from '../typescriptService';
import { Delayer } from '../utils/async'; import { Delayer } from '../utils/async';
import * as languageModeIds from '../utils/languageModeIds'; import * as languageModeIds from '../utils/languageModeIds';
import * as fileSchemes from '../utils/fileSchemes';
interface IDiagnosticRequestor { interface IDiagnosticRequestor {
requestDiagnostic(filepath: string): void; requestDiagnostic(filepath: string): void;
...@@ -48,10 +49,7 @@ class SyncedBuffer { ...@@ -48,10 +49,7 @@ class SyncedBuffer {
} }
if (this.client.apiVersion.has230Features()) { if (this.client.apiVersion.has230Features()) {
const root = this.client.getWorkspaceRootForResource(this.document.uri); args.projectRootPath = this.client.getWorkspaceRootForResource(this.document.uri);
if (root) {
args.projectRootPath = root;
}
} }
if (this.client.apiVersion.has240Features()) { if (this.client.apiVersion.has240Features()) {
......
...@@ -578,12 +578,12 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -578,12 +578,12 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
} }
public normalizePath(resource: Uri): string | null { public normalizePath(resource: Uri): string | null {
if (resource.scheme === fileSchemes.walkThroughSnippet) { if (this._apiVersion.has213Features()) {
return resource.toString(); if (resource.scheme === fileSchemes.walkThroughSnippet || resource.scheme === fileSchemes.untitled) {
} const dirName = path.dirname(resource.path);
const fileName = this.inMemoryResourcePrefix + path.basename(resource.path);
if (resource.scheme === fileSchemes.untitled && this._apiVersion.has213Features()) { return resource.with({ path: path.join(dirName, fileName) }).toString(true);
return resource.toString(); }
} }
if (resource.scheme !== fileSchemes.file) { if (resource.scheme !== fileSchemes.file) {
...@@ -599,11 +599,24 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -599,11 +599,24 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/'); return result.replace(new RegExp('\\' + this.pathSeparator, 'g'), '/');
} }
private get inMemoryResourcePrefix(): string {
return this._apiVersion.has270Features() ? '^' : '';
}
public asUrl(filepath: string): Uri { public asUrl(filepath: string): Uri {
if (filepath.startsWith(TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME_COLON) if (this._apiVersion.has213Features()) {
|| (filepath.startsWith(fileSchemes.untitled + ':') && this._apiVersion.has213Features()) if (filepath.startsWith(TypeScriptServiceClient.WALK_THROUGH_SNIPPET_SCHEME_COLON) || (filepath.startsWith(fileSchemes.untitled + ':'))
) { ) {
return Uri.parse(filepath); let resource = Uri.parse(filepath);
if (this.inMemoryResourcePrefix) {
const dirName = path.dirname(resource.path);
const fileName = path.basename(resource.path);
if (fileName.startsWith(this.inMemoryResourcePrefix)) {
resource = resource.with({ path: path.join(dirName, fileName.slice(this.inMemoryResourcePrefix.length)) });
}
}
return resource;
}
} }
return Uri.file(filepath); return Uri.file(filepath);
} }
...@@ -620,8 +633,10 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient ...@@ -620,8 +633,10 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
return root.uri.fsPath; return root.uri.fsPath;
} }
} }
return roots[0].uri.fsPath;
} }
return roots[0].uri.fsPath;
return undefined;
} }
public execute(command: string, args: any, expectsResultOrToken?: boolean | CancellationToken): Promise<any> { public execute(command: string, args: any, expectsResultOrToken?: boolean | CancellationToken): Promise<any> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册