Skip to content

Commit eea9c16

Browse files
committed
Move client-side extension code out of patch
1 parent f1b38e4 commit eea9c16

File tree

3 files changed

+69
-47
lines changed

3 files changed

+69
-47
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ Our changes include:
174174
- Allow multiple extension directories (both user and built-in).
175175
- Modify the loader, websocket, webview, service worker, and asset requests to
176176
use the URL of the page as a base (and TLS if necessary for the websocket).
177-
- Send client-side telemetry through the server and get the initial log level
178-
from the server.
179-
- Add an upload service for use in editor windows and the explorer along with a
180-
file prefix to ignore for temporary files created during upload.
177+
- Send client-side telemetry through the server.
178+
- Add an upload service along with a file prefix to ignore for temporary files
179+
created during upload.
181180
- Make changing the display language work.
182-
- Make hiding or toggling the menu bar possible.
183181
- Make it possible for us to load code on the client.
184-
- Modify the build process to include our code.
182+
- Make extensions work in the browser.
183+
- Fix getting permanently disconnected when you sleep or hibernate for a while.
184+
- Make it possible to automatically update the binary.
185185

186186
## License
187187

scripts/vscode.patch

+6-41
Original file line numberDiff line numberDiff line change
@@ -510,62 +510,27 @@ index 49a8e254fd..99d233aed5 100644
510510
throw new Error(`Cannot load URI: '${module}', must be of file-scheme`);
511511
}
512512
diff --git a/src/vs/workbench/api/worker/extHostExtensionService.ts b/src/vs/workbench/api/worker/extHostExtensionService.ts
513-
index afd82468c0..67d938e9ab 100644
513+
index afd82468c0..289145be54 100644
514514
--- a/src/vs/workbench/api/worker/extHostExtensionService.ts
515515
+++ b/src/vs/workbench/api/worker/extHostExtensionService.ts
516-
@@ -9,6 +9,10 @@ import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHost
516+
@@ -9,6 +9,9 @@ import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHost
517517
import { endsWith } from 'vs/base/common/strings';
518518
import { URI } from 'vs/base/common/uri';
519519
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
520520
+import { joinPath } from 'vs/base/common/resources';
521521
+import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
522-
+import { fromTar } from 'vs/server/node_modules/@coder/requirefs/out/requirefs';
523-
+import { Client } from 'vs/server/node_modules/@coder/node-browser/out/client/client';
522+
+import { loadCommonJSModule } from 'vs/server/src/browser/worker';
524523

525524
class WorkerRequireInterceptor extends RequireInterceptor {
526525

527-
@@ -41,7 +45,48 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
526+
@@ -41,7 +44,14 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
528527
await this._fakeModules.install();
529528
}
530529

531530
- protected async _loadCommonJSModule<T>(module: URI, activationTimesBuilder: ExtensionActivationTimesBuilder): Promise<T> {
532531
+ protected async _loadCommonJSModule<T>(module: URI | IExtensionDescription, activationTimesBuilder: ExtensionActivationTimesBuilder): Promise<T> {
533532
+ if (!URI.isUri(module) && module.extensionKind !== 'web') {
534-
+ const fetchUri = URI.from({
535-
+ scheme: self.location.protocol.replace(':', ''),
536-
+ authority: self.location.host,
537-
+ path: `${self.location.pathname.replace(/\/static.*\/out\/vs\/workbench\/services\/extensions\/worker\/extensionHostWorkerMain.js$/, '')}/tar`,
538-
+ query: `path=${encodeURIComponent(module.extensionLocation.path)}`,
539-
+ });
540-
+ const response = await fetch(fetchUri.toString(true));
541-
+ if (response.status !== 200) {
542-
+ throw new Error(`Failed to download extension '${module.extensionLocation.path}'`);
543-
+ }
544-
+ const client = new Client(this._nodeProxy, { logger: this._logService });
545-
+ const init = await client.handshake();
546-
+ const buffer = new Uint8Array(await response.arrayBuffer());
547-
+ const rfs = fromTar(buffer);
548-
+ (<any>self).global = self;
549-
+ rfs.provide('vscode', this._fakeModules.getModule('vscode', module.extensionLocation));
550-
+ Object.keys(client.modules).forEach((key) => {
551-
+ const mod = (client.modules as any)[key];
552-
+ if (key === 'process') {
553-
+ (<any>self).process = mod;
554-
+ (<any>self).process.env = init.env;
555-
+ return;
556-
+ }
557-
+
558-
+ rfs.provide(key, mod);
559-
+ switch (key) {
560-
+ case 'buffer':
561-
+ (<any>self).Buffer = mod.Buffer;
562-
+ break;
563-
+ case 'timers':
564-
+ (<any>self).setImmediate = mod.setImmediate;
565-
+ break;
566-
+ }
567-
+ });
568-
+ return rfs.require('.');
533+
+ return loadCommonJSModule(module, activationTimesBuilder, this._nodeProxy, this._logService, this._fakeModules.getModule('vscode', module.extensionLocation));
569534
+ }
570535
+
571536
+ if (!URI.isUri(module)) {
@@ -574,7 +539,7 @@ index afd82468c0..67d938e9ab 100644
574539

575540
module = module.with({ path: ensureSuffix(module.path, '.js') });
576541
const response = await fetch(module.toString(true));
577-
@@ -57,7 +102,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
542+
@@ -57,7 +67,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
578543
const _exports = {};
579544
const _module = { exports: _exports };
580545
const _require = (request: string) => {

src/browser/worker.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { URI } from "vs/base/common/uri";
2+
import { IExtensionDescription } from "vs/platform/extensions/common/extensions";
3+
import { ILogService } from "vs/platform/log/common/log";
4+
import { Client } from "vs/server/node_modules/@coder/node-browser/out/client/client";
5+
import { fromTar } from "vs/server/node_modules/@coder/requirefs/out/requirefs";
6+
import { ExtensionActivationTimesBuilder } from "vs/workbench/api/common/extHostExtensionActivator";
7+
import { IExtHostNodeProxy } from "./extHostNodeProxy";
8+
9+
export const loadCommonJSModule = async <T>(
10+
module: IExtensionDescription,
11+
activationTimesBuilder: ExtensionActivationTimesBuilder,
12+
nodeProxy: IExtHostNodeProxy,
13+
logService: ILogService,
14+
vscode: any,
15+
): Promise<T> => {
16+
const fetchUri = URI.from({
17+
scheme: self.location.protocol.replace(":", ""),
18+
authority: self.location.host,
19+
path: `${self.location.pathname.replace(/\/static.*\/out\/vs\/workbench\/services\/extensions\/worker\/extensionHostWorkerMain.js$/, "")}/tar`,
20+
query: `path=${encodeURIComponent(module.extensionLocation.path)}`,
21+
});
22+
const response = await fetch(fetchUri.toString(true));
23+
if (response.status !== 200) {
24+
throw new Error(`Failed to download extension "${module.extensionLocation.path}"`);
25+
}
26+
const client = new Client(nodeProxy, { logger: logService });
27+
const init = await client.handshake();
28+
const buffer = new Uint8Array(await response.arrayBuffer());
29+
const rfs = fromTar(buffer);
30+
(<any>self).global = self;
31+
rfs.provide("vscode", vscode);
32+
Object.keys(client.modules).forEach((key) => {
33+
const mod = (client.modules as any)[key];
34+
if (key === "process") {
35+
(<any>self).process = mod;
36+
(<any>self).process.env = init.env;
37+
return;
38+
}
39+
40+
rfs.provide(key, mod);
41+
switch (key) {
42+
case "buffer":
43+
(<any>self).Buffer = mod.Buffer;
44+
break;
45+
case "timers":
46+
(<any>self).setImmediate = mod.setImmediate;
47+
break;
48+
}
49+
});
50+
51+
try {
52+
activationTimesBuilder.codeLoadingStart();
53+
return rfs.require(".");
54+
} finally {
55+
activationTimesBuilder.codeLoadingStop();
56+
}
57+
};

0 commit comments

Comments
 (0)