Skip to content

Commit 9cfc257

Browse files
committed
Fix paths from Windows client to non-Windows server
Fixes #1659 Fixes #1642
1 parent 8626bed commit 9cfc257

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

ci/dev/vscode.patch

+5-7
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,17 @@ index 1e16cde724..0000000000
248248
-target "12.4.0"
249249
-runtime "node"
250250
diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts
251-
index e4546b2cf6..9df12239fb 100644
251+
index e4546b2cf6..ad2c544e89 100644
252252
--- a/src/vs/base/common/network.ts
253253
+++ b/src/vs/base/common/network.ts
254-
@@ -94,16 +94,18 @@ class RemoteAuthoritiesImpl {
254+
@@ -94,16 +94,17 @@ class RemoteAuthoritiesImpl {
255255
if (host && host.indexOf(':') !== -1) {
256256
host = `[${host}]`;
257257
}
258258
- const port = this._ports[authority];
259259
+ // const port = this._ports[authority];
260260
const connectionToken = this._connectionTokens[authority];
261-
- let query = `path=${encodeURIComponent(uri.path)}`;
262-
+ // NOTE@coder: Use fsPath for Windows support.
263-
+ let query = `path=${encodeURIComponent(uri.fsPath)}`;
261+
let query = `path=${encodeURIComponent(uri.path)}`;
264262
if (typeof connectionToken === 'string') {
265263
query += `&tkn=${encodeURIComponent(connectionToken)}`;
266264
}
@@ -1054,7 +1052,7 @@ index 0000000000..0d2e93edae
10541052
+}
10551053
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
10561054
new file mode 100644
1057-
index 0000000000..8db1e17c38
1055+
index 0000000000..a93381631a
10581056
--- /dev/null
10591057
+++ b/src/vs/server/browser/worker.ts
10601058
@@ -0,0 +1,57 @@
@@ -1077,7 +1075,7 @@ index 0000000000..8db1e17c38
10771075
+ scheme: self.location.protocol.replace(':', ''),
10781076
+ authority: self.location.host,
10791077
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
1080-
+ query: `tar=${encodeURIComponent(module.extensionLocation.fsPath)}`,
1078+
+ query: `tar=${encodeURIComponent(module.extensionLocation.path)}`,
10811079
+ });
10821080
+ const response = await fetch(fetchUri.toString(true));
10831081
+ if (response.status !== 200) {

src/node/app/vscode.ts

+48-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,53 @@ import { Args } from "../cli"
1919
import { HttpProvider, HttpProviderOptions, HttpResponse, Route } from "../http"
2020
import { settings } from "../settings"
2121

22+
/**
23+
* Taken from vs/base/common/charCode.ts. Copied for now instead of importing so
24+
* we don't have to set up a `vs` alias to be able to import with types (since
25+
* the alternative is to directly import from `out`).
26+
*/
27+
const enum CharCode {
28+
Slash = 47,
29+
A = 65,
30+
Z = 90,
31+
a = 97,
32+
z = 122,
33+
Colon = 58,
34+
}
35+
36+
/**
37+
* Compute `fsPath` for the given uri.
38+
* Taken from vs/base/common/uri.ts. It's not imported to avoid also importing
39+
* everything that file imports.
40+
*/
41+
function uriToFsPath(uri: { authority?: string; path: string; scheme: string }, keepDriveLetterCasing = false): string {
42+
const isWindows = process.platform === "win32"
43+
let value: string
44+
if (uri.authority && uri.path.length > 1 && uri.scheme === "file") {
45+
// unc path: file://shares/c$/far/boo
46+
value = `//${uri.authority}${uri.path}`
47+
} else if (
48+
uri.path.charCodeAt(0) === CharCode.Slash &&
49+
((uri.path.charCodeAt(1) >= CharCode.A && uri.path.charCodeAt(1) <= CharCode.Z) ||
50+
(uri.path.charCodeAt(1) >= CharCode.a && uri.path.charCodeAt(1) <= CharCode.z)) &&
51+
uri.path.charCodeAt(2) === CharCode.Colon
52+
) {
53+
if (!keepDriveLetterCasing) {
54+
// windows drive letter: file:///c:/far/boo
55+
value = uri.path[1].toLowerCase() + uri.path.substr(2)
56+
} else {
57+
value = uri.path.substr(1)
58+
}
59+
} else {
60+
// other path
61+
value = uri.path
62+
}
63+
if (isWindows) {
64+
value = value.replace(/\//g, "\\")
65+
}
66+
return value
67+
}
68+
2269
export class VscodeHttpProvider extends HttpProvider {
2370
private readonly serverRootPath: string
2471
private readonly vsRootPath: string
@@ -151,7 +198,7 @@ export class VscodeHttpProvider extends HttpProvider {
151198
case "/resource":
152199
case "/vscode-remote-resource":
153200
if (typeof route.query.path === "string") {
154-
return this.getResource(route.query.path)
201+
return this.getResource(uriToFsPath({ scheme: "file", path: route.query.path }))
155202
}
156203
break
157204
case "/webview":

0 commit comments

Comments
 (0)