Skip to content

Commit 17c7a08

Browse files
authored
Add cli & command to run the code server on the desktop (#163546)
Add cli & command to run the code server on the desktop
1 parent 1e9295c commit 17c7a08

File tree

18 files changed

+996
-58
lines changed

18 files changed

+996
-58
lines changed

build/lib/i18n.resources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@
306306
"name": "vs/workbench/contrib/offline",
307307
"project": "vscode-workbench"
308308
},
309+
{
310+
"name": "vs/workbench/contrib/remoteTunnel",
311+
"project": "vscode-workbench"
312+
},
309313
{
310314
"name": "vs/workbench/services/actions",
311315
"project": "vscode-workbench"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-oss-dev",
33
"version": "1.73.0",
4-
"distro": "33ffc394a05e9cb3e9ac1fe2a72ab75610cf0d7e",
4+
"distro": "cac14b226f101a8186316eb3dc74f1de73c0a5be",
55
"author": {
66
"name": "Microsoft Corporation"
77
},

product.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"serverLicensePrompt": "",
1212
"serverApplicationName": "code-server-oss",
1313
"serverDataFolderName": ".vscode-server-oss",
14+
"tunnelApplicationName": "code-tunnel-oss",
1415
"win32DirName": "Microsoft Code OSS",
1516
"win32NameVersion": "Microsoft Code OSS",
1617
"win32RegValueName": "CodeOSS",

src/vs/base/common/product.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ export interface IProductConfiguration {
130130
readonly serverApplicationName: string;
131131
readonly serverDataFolderName?: string;
132132

133+
readonly tunnelApplicationName?: string;
134+
readonly tunnelApplicationConfig?: { authenticationProviders: IStringDictionary<{ scopes: string[] }> };
135+
133136
readonly npsSurveyUrl?: string;
134137
readonly cesSurveyUrl?: string;
135138
readonly surveys?: readonly ISurveyData[];
@@ -155,7 +158,6 @@ export interface IProductConfiguration {
155158
readonly 'configurationSync.store'?: ConfigurationSyncStore;
156159

157160
readonly 'editSessions.store'?: Omit<ConfigurationSyncStore, 'insidersUrl' | 'stableUrl'>;
158-
159161
readonly darwinUniversalAssetId?: string;
160162

161163
// experimental

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,18 @@ import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/elect
108108
import { SharedProcessRequestService } from 'vs/platform/request/electron-browser/sharedProcessRequestService';
109109
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
110110
import { UserDataProfilesCleaner } from 'vs/code/electron-browser/sharedProcess/contrib/userDataProfilesCleaner';
111+
import { RemoteTunnelService } from 'vs/platform/remoteTunnel/electron-browser/remoteTunnelService';
112+
import { IRemoteTunnelService } from 'vs/platform/remoteTunnel/common/remoteTunnel';
113+
import { ISharedProcessLifecycleService, SharedProcessLifecycleService } from 'vs/platform/lifecycle/electron-browser/sharedProcessLifecycleService';
111114

112115
class SharedProcessMain extends Disposable {
113116

114117
private server = this._register(new MessagePortServer());
115118

116119
private sharedProcessWorkerService: ISharedProcessWorkerService | undefined = undefined;
117120

121+
private lifecycleService: SharedProcessLifecycleService | undefined = undefined;;
122+
118123
constructor(private configuration: ISharedProcessConfiguration) {
119124
super();
120125

@@ -124,7 +129,14 @@ class SharedProcessMain extends Disposable {
124129
private registerListeners(): void {
125130

126131
// Shared process lifecycle
127-
const onExit = () => this.dispose();
132+
const onExit = async () => {
133+
if (this.lifecycleService) {
134+
await this.lifecycleService.fireOnWillShutdown();
135+
this.lifecycleService.dispose();
136+
this.lifecycleService = undefined;
137+
}
138+
this.dispose();
139+
};
128140
process.once('exit', onExit);
129141
ipcRenderer.once('vscode:electron-main->shared-process=exit', onExit);
130142

@@ -180,6 +192,8 @@ class SharedProcessMain extends Disposable {
180192
private async initServices(): Promise<IInstantiationService> {
181193
const services = new ServiceCollection();
182194

195+
// Lifecycle
196+
183197
// Product
184198
const productService = { _serviceBrand: undefined, ...product };
185199
services.set(IProductService, productService);
@@ -211,6 +225,10 @@ class SharedProcessMain extends Disposable {
211225
const logService = this._register(new FollowerLogService(logLevelClient, multiplexLogger));
212226
services.set(ILogService, logService);
213227

228+
// Lifecycle
229+
this.lifecycleService = new SharedProcessLifecycleService(logService);
230+
services.set(ISharedProcessLifecycleService, this.lifecycleService);
231+
214232
// Worker
215233
this.sharedProcessWorkerService = new SharedProcessWorkerService(logService);
216234
services.set(ISharedProcessWorkerService, this.sharedProcessWorkerService);
@@ -342,6 +360,8 @@ class SharedProcessMain extends Disposable {
342360
services.set(IUserDataSyncService, new SyncDescriptor(UserDataSyncService, undefined, false /* Initializes the Sync State */));
343361
services.set(IUserDataSyncProfilesStorageService, new SyncDescriptor(UserDataSyncProfilesStorageService, undefined, true));
344362

363+
// Terminal
364+
345365
const ptyHostService = new PtyHostService({
346366
graceTime: LocalReconnectConstants.GraceTime,
347367
shortGraceTime: LocalReconnectConstants.ShortGraceTime,
@@ -353,7 +373,6 @@ class SharedProcessMain extends Disposable {
353373
);
354374
ptyHostService.initialize();
355375

356-
// Terminal
357376
services.set(ILocalPtyService, this._register(ptyHostService));
358377

359378
// Signing
@@ -363,6 +382,9 @@ class SharedProcessMain extends Disposable {
363382
services.set(ISharedTunnelsService, new SyncDescriptor(SharedTunnelsService));
364383
services.set(ISharedProcessTunnelService, new SyncDescriptor(SharedProcessTunnelService));
365384

385+
// Remote Tunnel
386+
services.set(IRemoteTunnelService, new SyncDescriptor(RemoteTunnelService));
387+
366388
return new InstantiationService(services);
367389
}
368390

@@ -430,6 +452,10 @@ class SharedProcessMain extends Disposable {
430452
const sharedProcessWorkerChannel = ProxyChannel.fromService(accessor.get(ISharedProcessWorkerService));
431453
this.server.registerChannel(ipcSharedProcessWorkerChannelName, sharedProcessWorkerChannel);
432454

455+
// Remote Tunnel
456+
const remoteTunnelChannel = ProxyChannel.fromService(accessor.get(IRemoteTunnelService));
457+
this.server.registerChannel('remoteTunnel', remoteTunnelChannel);
458+
433459
}
434460

435461
private registerErrorHandler(logService: ILogService): void {

src/vs/code/node/cli.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { chmodSync, existsSync, readFileSync, statSync, truncateSync, unlinkSync
88
import { homedir, release, tmpdir } from 'os';
99
import type { ProfilingSession, Target } from 'v8-inspect-profiler';
1010
import { Event } from 'vs/base/common/event';
11-
import { isAbsolute, resolve, join } from 'vs/base/common/path';
11+
import { isAbsolute, resolve, join, dirname } from 'vs/base/common/path';
1212
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
1313
import { randomPort } from 'vs/base/common/ports';
1414
import { isString } from 'vs/base/common/types';
@@ -24,7 +24,6 @@ import product from 'vs/platform/product/common/product';
2424
import { CancellationTokenSource } from 'vs/base/common/cancellation';
2525
import { randomPath } from 'vs/base/common/extpath';
2626
import { Utils } from 'vs/platform/profiling/common/profiling';
27-
import { dirname } from 'vs/base/common/resources';
2827
import { FileAccess } from 'vs/base/common/network';
2928

3029
function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean {
@@ -50,6 +49,31 @@ export async function main(argv: string[]): Promise<any> {
5049
return;
5150
}
5251

52+
if (args.tunnel) {
53+
if (!product.tunnelApplicationName) {
54+
console.error(`'tunnel' command not supported in ${product.applicationName}`);
55+
return;
56+
}
57+
return new Promise((resolve, reject) => {
58+
let tunnelProcess;
59+
if (process.env['VSCODE_DEV']) {
60+
tunnelProcess = spawn('cargo', ['run', '--bin', 'code-tunnel', ...argv.slice(5)], { cwd: join(getAppRoot(), 'cli') });
61+
} else {
62+
const tunnelCommand = join(dirname(process.execPath), 'bin', `${product.tunnelApplicationName}${isWindows ? '.exe' : ''}`);
63+
const tunnelArgs = argv.slice(3);
64+
tunnelProcess = spawn(tunnelCommand, tunnelArgs);
65+
}
66+
tunnelProcess.stdout.on('data', data => {
67+
console.log(data.toString());
68+
});
69+
tunnelProcess.stderr.on('data', data => {
70+
console.error(data.toString());
71+
});
72+
tunnelProcess.on('exit', resolve);
73+
tunnelProcess.on('error', reject);
74+
});
75+
}
76+
5377
// Help
5478
if (args.help) {
5579
const executable = `${product.applicationName}${isWindows ? '.exe' : ''}`;
@@ -75,7 +99,7 @@ export async function main(argv: string[]): Promise<any> {
7599
case 'fish': file = 'shellIntegration.fish'; break;
76100
default: throw new Error('Error using --locate-shell-integration-path: Invalid shell type');
77101
}
78-
console.log(join(dirname(FileAccess.asFileUri('', require)).fsPath, 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
102+
console.log(join(getAppRoot(), 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
79103
}
80104

81105
// Extensions Management
@@ -467,6 +491,10 @@ export async function main(argv: string[]): Promise<any> {
467491
}
468492
}
469493

494+
function getAppRoot() {
495+
return dirname(FileAccess.asFileUri('', require).fsPath);
496+
}
497+
470498
function eventuallyExit(code: number): void {
471499
setTimeout(() => process.exit(code), 0);
472500
}

src/vs/platform/environment/common/argv.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
* A list of command line arguments we support natively.
88
*/
99
export interface NativeParsedArgs {
10+
// subcommands
11+
tunnel?: {
12+
'cli-data-dir'?: string;
13+
'disable-telemetry'?: boolean;
14+
'telemetry-level'?: string;
15+
user: {
16+
login: {
17+
'access-token'?: string;
18+
'provider'?: string;
19+
};
20+
};
21+
};
1022
_: string[];
1123
'folder-uri'?: string[]; // undefined or array of 1 or more
1224
'file-uri'?: string[]; // undefined or array of 1 or more

0 commit comments

Comments
 (0)