Skip to content

Commit 093ebf8

Browse files
committed
fix: add handle for resolveExternalUri
This adds a fix to properly handle `resolveExternalUri` which is used by extensions like Tabnine.
1 parent b2f043a commit 093ebf8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

patches/proxy-uri.diff

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,66 @@ Index: code-server/lib/vscode/src/vs/workbench/contrib/terminal/common/terminalE
9898

9999
// Merge config (settings) and ShellLaunchConfig environments
100100
mergeEnvironments(env, allowedEnvFromConfig);
101+
Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
102+
===================================================================
103+
--- code-server.orig/lib/vscode/src/vs/code/browser/workbench/workbench.ts
104+
+++ code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
105+
@@ -17,6 +17,7 @@ import { isFolderToOpen, isWorkspaceToOp
106+
import { create, ICredentialsProvider, IURLCallbackProvider, IWorkbenchConstructionOptions, IWorkspace, IWorkspaceProvider } from 'vs/workbench/workbench.web.main';
107+
import { posix } from 'vs/base/common/path';
108+
import { ltrim } from 'vs/base/common/strings';
109+
+import { relativeRoot } from 'vs/server/node/webClientServer';
110+
111+
interface ICredential {
112+
service: string;
113+
@@ -485,6 +486,7 @@ function doCreateUri(path: string, query
114+
});
115+
}
116+
117+
+ path = (window.location.pathname + "/" + path).replace(/\/\/+/g, "/")
118+
return URI.parse(window.location.href).with({ path, query });
119+
}
120+
121+
@@ -496,7 +498,7 @@ function doCreateUri(path: string, query
122+
if (!configElement || !configElementAttribute) {
123+
throw new Error('Missing web configuration element');
124+
}
125+
- const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents; workspaceUri?: UriComponents; callbackRoute: string } = JSON.parse(configElementAttribute);
126+
+ const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents; workspaceUri?: UriComponents; callbackRoute: string } = { ...JSON.parse(configElementAttribute), remoteAuthority: location.host }
127+
128+
// Create workbench
129+
create(document.body, {
130+
@@ -506,6 +508,32 @@ function doCreateUri(path: string, query
131+
} : undefined,
132+
workspaceProvider: WorkspaceProvider.create(config),
133+
urlCallbackProvider: new LocalStorageURLCallbackProvider(config.callbackRoute),
134+
- credentialsProvider: config.remoteAuthority ? undefined : new LocalStorageCredentialsProvider() // with a remote, we don't use a local credentials provider
135+
+ credentialsProvider: config.remoteAuthority ? undefined : new LocalStorageCredentialsProvider(), // with a remote, we don't use a local credentials provider
136+
+ resolveExternalUri: (uri: URI): Promise<URI> => {
137+
+ // TODO@jsjoeio - how do we make it relative to work when hosted on subpath?
138+
+ const baseUrl = `${window.location.protocol}//${window.location.host}`
139+
+ let resolvedUri = uri
140+
+
141+
+ // NOTE@jsjoeio - this isn't exhaustive
142+
+ // also doesn't handle if not http or https i.e. ws
143+
+ const localhostMatch = uri.toString().includes("localhost")
144+
+ if (localhostMatch) {
145+
+ // Source: extractLocalHostUriMetaDataForPortMapping
146+
+ const matches = /^(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)$/.exec(uri.authority)
147+
+ const port = matches && +matches[2]
148+
+ if (port) {
149+
+ // Use code-server's built in /proxy/<port>
150+
+ resolvedUri = URI.parse(`${baseUrl}/proxy/${port}`)
151+
+ } else {
152+
+ // If here probably means no port found
153+
+ // Assume 80 for HTTP and 443 for HTTPS
154+
+ const isHttps = uri.scheme === "https"
155+
+ resolvedUri = URI.parse(`${baseUrl}/proxy/${isHttps ? "443" : "80"}`)
156+
+ }
157+
+ }
158+
+
159+
+ // If not localhost, return unmodified
160+
+ return Promise.resolve(resolvedUri)
161+
+ }
162+
});
163+
})();

0 commit comments

Comments
 (0)