Skip to content

Commit 0edf650

Browse files
committed
Map the paths back to https:
// TODO: is this really needed or can vscode take care of this How do we handle when opening lib.d.ts as response to goto def in open files
1 parent f29b2e7 commit 0edf650

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/tsserver/webServer.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ namespace ts.server {
140140
return typeof cmdLineVerbosity === "undefined" ? nullLogger : new MainProcessLogger(cmdLineVerbosity);
141141
}
142142

143+
interface WebServerHost extends ServerHost {
144+
getWebPath: (path: string) => string | undefined;
145+
}
146+
143147
function createWebSystem(args: string[]) {
144148
Debug.assert(ts.sys === undefined);
145149
const returnEmptyString = () => "";
146150
// Later we could map ^memfs:/ to do something special if we want to enable more functionality like module resolution or something like that
147151
const getWebPath = (path: string) => startsWith(path, directorySeparator) ? path.replace(directorySeparator, executingDirectoryPath) : undefined;
148-
const sys: ServerHost = {
152+
const sys: WebServerHost = {
153+
getWebPath,
149154
args,
150155
newLine: "\r\n", // This can be configured by clients
151156
useCaseSensitiveFileNames: false, // Use false as the default on web since that is the safest option
@@ -233,10 +238,8 @@ namespace ts.server {
233238
function startWebSession(options: StartSessionOptions, logger: Logger, cancellationToken: ServerCancellationToken) {
234239
class WorkerSession extends Session<{}> {
235240
constructor() {
236-
const host = sys as ServerHost;
237-
238241
super({
239-
host,
242+
host: sys as WebServerHost,
240243
cancellationToken,
241244
...options,
242245
typingsInstaller: nullTypingsInstaller,
@@ -248,6 +251,9 @@ namespace ts.server {
248251
}
249252

250253
public send(msg: protocol.Message) {
254+
// Updates to file paths
255+
this.updateWebPaths(msg);
256+
251257
if (msg.type === "event" && !this.canUseEvents) {
252258
if (this.logger.hasLevel(LogLevel.verbose)) {
253259
this.logger.info(`Session does not support events: ignored event: ${JSON.stringify(msg)}`);
@@ -260,6 +266,30 @@ namespace ts.server {
260266
postMessage(msg);
261267
}
262268

269+
private updateWebPaths(obj: any) {
270+
if (isArray(obj)) {
271+
obj.forEach(ele => this.updateWebPaths(ele));
272+
}
273+
else if (typeof obj === "object") {
274+
for (const id in obj) {
275+
if (hasProperty(obj, id)) {
276+
const value = obj[id];
277+
if ((id === "file" || id === "fileName" || id === "renameFilename") && isString(value)) {
278+
const webpath = (sys as WebServerHost).getWebPath(value);
279+
if (webpath) obj[id] = webpath;
280+
}
281+
else if ((id === "files" || id === "fileNames") && isArray(value) && value.every(isString)) {
282+
obj[id] = value.map(ele => (sys as WebServerHost).getWebPath(ele) || ele);
283+
}
284+
else {
285+
this.updateWebPaths(value);
286+
}
287+
}
288+
}
289+
290+
}
291+
}
292+
263293
protected parseMessage(message: {}): protocol.Request {
264294
return <protocol.Request>message;
265295
}
@@ -279,8 +309,6 @@ namespace ts.server {
279309
this.onMessage(message.data);
280310
});
281311
}
282-
283-
// TODO:: Update all responses to use webPath
284312
}
285313

286314
const session = new WorkerSession();

0 commit comments

Comments
 (0)