Skip to content

Commit 9fdfacb

Browse files
committed
Quality check
1 parent e8cb6ff commit 9fdfacb

File tree

11 files changed

+191
-426
lines changed

11 files changed

+191
-426
lines changed

scripts/nbin-shim.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
/* global require, global, process, __dirname */
21
if (!global.NBIN_LOADED) {
32
try {
43
const nbin = require("nbin");
54
nbin.shimNativeFs("{{ROOT_PATH}}");
65
global.NBIN_LOADED = true;
7-
86
const path = require("path");
97
const rg = require("vscode-ripgrep");
108
rg.binaryRgPath = rg.rgPath;
119
rg.rgPath = path.join(
1210
require("os").tmpdir(),
13-
`code-server/${path.basename(rg.binaryRgPath)}`,
11+
`code-server/${path.basename(rg.binaryRgPath)}`
1412
);
15-
} catch (error) {
16-
// Not in the binary.
17-
}
13+
} catch (error) { /* Not in the binary. */ }
1814
}

src/api.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const vscodeApi = (serviceCollection: ServiceCollection): typeof vscode =
6060
FileSystemError: extHostTypes.FileSystemError,
6161
FileType: FileType,
6262
Uri: URI,
63-
6463
commands: {
6564
executeCommand: (commandId: string, ...args: any[]): any => {
6665
return commandService.executeCommand(commandId, ...args);
@@ -69,7 +68,6 @@ export const vscodeApi = (serviceCollection: ServiceCollection): typeof vscode =
6968
return CommandsRegistry.registerCommand(id, command);
7069
},
7170
},
72-
7371
window: {
7472
registerTreeDataProvider: (id: string, dataProvider: ITreeViewDataProvider): void => {
7573
const view = viewsRegistry.getView(id);
@@ -81,7 +79,6 @@ export const vscodeApi = (serviceCollection: ServiceCollection): typeof vscode =
8179
notificationService.error(message);
8280
},
8381
},
84-
8582
workspace: {
8683
registerFileSystemProvider: (scheme: string, provider: vscode.FileSystemProvider): IDisposable => {
8784
return fileService.registerProvider(scheme, new FileSystemProvider(provider));
@@ -95,21 +92,15 @@ export const vscodeApi = (serviceCollection: ServiceCollection): typeof vscode =
9592
*/
9693
export const coderApi = (serviceCollection: ServiceCollection): typeof coder => {
9794
const getService = <T>(id: ServiceIdentifier<T>): T => serviceCollection.get<T>(id) as T;
98-
9995
return {
10096
workbench: {
10197
action: Action,
10298
syncActionDescriptor: SyncActionDescriptor,
10399
commandRegistry: CommandsRegistry,
104100
actionsRegistry: Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions),
105101
registerView: (viewId, viewName, containerId, containerName, icon): void => {
106-
const viewContainersRegistry = Registry.as<IViewContainersRegistry>(ViewsExtensions.ViewContainersRegistry);
107-
const viewsRegistry = Registry.as<IViewsRegistry>(ViewsExtensions.ViewsRegistry);
108-
const container = viewContainersRegistry.registerViewContainer(containerId);
109-
110102
const cssClass = `extensionViewlet-${containerId}`;
111103
const id = `workbench.view.extension.${containerId}`;
112-
113104
class CustomViewlet extends ViewContainerViewlet {
114105
public constructor(
115106
@IConfigurationService configurationService: IConfigurationService,
@@ -127,44 +118,32 @@ export const coderApi = (serviceCollection: ServiceCollection): typeof coder =>
127118
}
128119
}
129120

130-
const viewletDescriptor = new ViewletDescriptor(
131-
CustomViewlet as any,
132-
id,
133-
containerName,
134-
cssClass,
135-
undefined,
136-
URI.parse(icon),
121+
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(
122+
new ViewletDescriptor(CustomViewlet as any, id, containerName, cssClass, undefined, URI.parse(icon)),
137123
);
138124

139-
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(viewletDescriptor);
140-
141-
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
142-
registry.registerWorkbenchAction(
125+
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions).registerWorkbenchAction(
143126
new SyncActionDescriptor(OpenCustomViewletAction as any, id, localize("showViewlet", "Show {0}", containerName)),
144127
"View: Show {0}",
145128
localize("view", "View"),
146129
);
147130

148-
// Generate CSS to show the icon in the activity bar
131+
// Generate CSS to show the icon in the activity bar.
149132
const iconClass = `.monaco-workbench .activitybar .monaco-action-bar .action-label.${cssClass}`;
150133
createCSSRule(iconClass, `-webkit-mask: url('${icon}') no-repeat 50% 50%`);
151134

152-
const views = [{
135+
const container = Registry.as<IViewContainersRegistry>(ViewsExtensions.ViewContainersRegistry).registerViewContainer(containerId);
136+
Registry.as<IViewsRegistry>(ViewsExtensions.ViewsRegistry).registerViews([{
153137
id: viewId,
154138
name: viewName,
155139
ctorDescriptor: { ctor: CustomTreeViewPanel },
156140
treeView: getService(IInstantiationService).createInstance(CustomTreeView as any, viewId, container),
157-
}] as ITreeViewDescriptor[];
158-
viewsRegistry.registerViews(views, container);
141+
}] as ITreeViewDescriptor[], container);
159142
},
160-
// Even though the enums are exactly the same, Typescript says they are
161-
// not assignable to each other, so use `any`. I don't know if there is a
162-
// way around this.
163143
menuRegistry: MenuRegistry as any,
164144
statusbarService: getService(IStatusbarService) as any,
165145
notificationService: getService(INotificationService),
166146
terminalService: getService(ITerminalService),
167-
168147
onFileCreate: (cb): void => {
169148
getService<IFileService>(IFileService).onAfterOperation((e) => {
170149
if (e.operation === FileOperation.CREATE) {
@@ -198,7 +177,6 @@ export const coderApi = (serviceCollection: ServiceCollection): typeof coder =>
198177
}
199178
});
200179
},
201-
202180
onModelAdded: (cb): void => {
203181
getService<IModelService>(IModelService).onModelAdded((e) => {
204182
cb(e.uri.path, e.getLanguageIdentifier().language);
@@ -214,15 +192,13 @@ export const coderApi = (serviceCollection: ServiceCollection): typeof coder =>
214192
cb(e.model.uri.path, e.model.getLanguageIdentifier().language, e.oldModeId);
215193
});
216194
},
217-
218195
onTerminalAdded: (cb): void => {
219196
getService<ITerminalService>(ITerminalService).onInstanceCreated(() => cb());
220197
},
221198
onTerminalRemoved: (cb): void => {
222199
getService<ITerminalService>(ITerminalService).onInstanceDisposed(() => cb());
223200
},
224201
},
225-
226202
// @ts-ignore
227203
MenuId: MenuId,
228204
Severity: Severity,
@@ -250,9 +226,7 @@ class FileSystemProvider implements IFileSystemProvider {
250226
public readonly capabilities: FileSystemProviderCapabilities;
251227
public readonly onDidChangeCapabilities: Event<void> = Event.None;
252228

253-
public constructor(
254-
private readonly provider: vscode.FileSystemProvider,
255-
) {
229+
public constructor(private readonly provider: vscode.FileSystemProvider) {
256230
this.capabilities = FileSystemProviderCapabilities.Readonly;
257231
}
258232

src/channel.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ class Watcher extends DiskFileSystemProvider {
4343
}
4444
}
4545

46-
/**
47-
* See: src/vs/platform/remote/common/remoteAgentFileSystemChannel.ts.
48-
*/
4946
export class FileProviderChannel implements IServerChannel, IDisposable {
5047
private readonly provider: DiskFileSystemProvider;
5148
private readonly watchers = new Map<string, Watcher>();
@@ -175,9 +172,6 @@ export class FileProviderChannel implements IServerChannel, IDisposable {
175172
}
176173
}
177174

178-
/**
179-
* See: src/vs/workbench/services/remote/common/remoteAgentEnvironmentChannel.ts.
180-
*/
181175
export class ExtensionEnvironmentChannel implements IServerChannel {
182176
public constructor(
183177
private readonly environment: IEnvironmentService,
@@ -245,7 +239,6 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
245239
};
246240

247241
return Promise.all([scanBuiltin(), scanInstalled()]).then((allExtensions) => {
248-
// It's possible to get duplicates.
249242
const uniqueExtensions = new Map<string, IExtensionDescription>();
250243
allExtensions.forEach((multipleExtensions) => {
251244
multipleExtensions.forEach((extensions) => {
@@ -254,18 +247,13 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
254247
if (uniqueExtensions.has(id)) {
255248
const oldPath = uniqueExtensions.get(id)!.extensionLocation.fsPath;
256249
const newPath = extension.extensionLocation.fsPath;
257-
this.log.warn(
258-
`Extension ${id} in ${oldPath} has been overridden ${newPath}`,
259-
);
250+
this.log.warn(`${oldPath} has been overridden ${newPath}`);
260251
}
261252
uniqueExtensions.set(id, extension);
262253
});
263254
});
264255
});
265-
266-
const finalExtensions = <IExtensionDescription[]>[];
267-
uniqueExtensions.forEach((e) => finalExtensions.push(e));
268-
return finalExtensions;
256+
return Array.from(uniqueExtensions.values());
269257
});
270258
}
271259

src/cli.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ const main = async (): Promise<void> => {
9292
const version = `${(pkg as any).codeServerVersion || "development"}-vsc${pkg.version}`;
9393
if (args.help) {
9494
const executable = `${product.applicationName}${os.platform() === "win32" ? ".exe" : ""}`;
95-
return console.log(buildHelpMessage(
96-
product.nameLong, executable,
97-
version,
98-
undefined,
99-
false,
100-
));
95+
return console.log(buildHelpMessage(product.nameLong, executable, version, undefined, false));
10196
}
10297

10398
if (args.version) {
@@ -116,26 +111,22 @@ const main = async (): Promise<void> => {
116111
if (shouldSpawnCliProcess()) {
117112
const cli = await new Promise<IMainCli>((c, e) => require(["vs/code/node/cliProcessMain"], c, e));
118113
await cli.main(args);
119-
// There is some WriteStream instance keeping it open so force an exit.
120-
return process.exit(0);
114+
return process.exit(0); // There is a WriteStream instance keeping it open.
121115
}
122116

117+
const extra = args["_"] || [];
123118
const options = {
124-
host: args.host,
125119
allowHttp: args["allow-http"],
120+
auth: typeof args.auth !== "undefined" ? args.auth : true,
126121
cert: args.cert,
127122
certKey: args["cert-key"],
128-
auth: typeof args.auth !== "undefined" ? args.auth : true,
123+
folderUri: extra.length > 1 ? extra[extra.length - 1] : undefined,
124+
host: args.host,
129125
password: process.env.PASSWORD,
130-
folderUri: args["_"] && args["_"].length > 1
131-
? args["_"][args["_"].length - 1]
132-
: undefined,
133126
};
134127

135128
if (!options.host) {
136-
options.host = !options.auth || options.allowHttp
137-
? "localhost"
138-
: "0.0.0.0";
129+
options.host = !options.auth || options.allowHttp ? "localhost" : "0.0.0.0";
139130
}
140131

141132
let usingGeneratedCert = false;
@@ -152,18 +143,16 @@ const main = async (): Promise<void> => {
152143
usingGeneratedPassword = true;
153144
}
154145

155-
const webviewPort = typeof args["webview-port"] !== "undefined"
156-
&& parseInt(args["webview-port"], 10) || 8444;
146+
const webviewPort = args["webview-port"];
157147
const webviewServer = new WebviewServer({
158148
...options,
159-
port: webviewPort,
149+
port: typeof webviewPort !== "undefined" && parseInt(webviewPort, 10) || 8444,
160150
socket: args["webview-socket"],
161151
});
162152

163-
const port = typeof args.port !== "undefined" && parseInt(args.port, 10) || 8443;
164153
const server = new MainServer({
165154
...options,
166-
port,
155+
port: typeof args.port !== "undefined" && parseInt(args.port, 10) || 8443,
167156
socket: args.socket,
168157
}, webviewServer, args);
169158

@@ -196,7 +185,7 @@ const main = async (): Promise<void> => {
196185

197186
if (!args.socket && args.open) {
198187
// The web socket doesn't seem to work if using 0.0.0.0.
199-
const openAddress = `http://localhost:${port}`;
188+
const openAddress = `http://localhost:${server.options.port}`;
200189
await open(openAddress).catch(console.error);
201190
console.log(` - Opened ${openAddress}`);
202191
}

src/connection.ts

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Emitter } from "vs/base/common/event";
66
import { ISocket } from "vs/base/parts/ipc/common/ipc.net";
77
import { NodeSocket } from "vs/base/parts/ipc/node/ipc.net";
88
import { ILogService } from "vs/platform/log/common/log";
9-
import { IExtHostReadyMessage, IExtHostSocketMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol";
9+
import { IExtHostReadyMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol";
1010

1111
import { Protocol } from "vs/server/src/protocol";
1212
import { uriTransformerPath } from "vs/server/src/util";
@@ -15,17 +15,11 @@ export abstract class Connection {
1515
protected readonly _onClose = new Emitter<void>();
1616
public readonly onClose = this._onClose.event;
1717
protected disposed: boolean = false;
18-
1918
public constructor(protected protocol: Protocol) {}
20-
2119
/**
2220
* Set up the connection on a new socket.
2321
*/
2422
public abstract reconnect(socket: ISocket, buffer: VSBuffer): void;
25-
26-
/**
27-
* Clean up the connection.
28-
*/
2923
protected abstract dispose(): void;
3024
}
3125

@@ -62,16 +56,10 @@ export class ManagementConnection extends Connection {
6256
}
6357
}
6458

65-
/**
66-
* Manage the extension host process.
67-
*/
6859
export class ExtensionHostConnection extends Connection {
6960
private process: cp.ChildProcess;
7061

71-
public constructor(
72-
protocol: Protocol, buffer: VSBuffer,
73-
private readonly log: ILogService,
74-
) {
62+
public constructor(protocol: Protocol, buffer: VSBuffer, private readonly log: ILogService) {
7563
super(protocol);
7664
protocol.dispose();
7765
this.process = this.spawn(buffer);
@@ -96,23 +84,17 @@ export class ExtensionHostConnection extends Connection {
9684
private sendInitMessage(buffer: VSBuffer): void {
9785
const socket = this.protocol.getUnderlyingSocket();
9886
socket.pause();
99-
100-
const initMessage: IExtHostSocketMessage = {
87+
this.process.send({
10188
type: "VSCODE_EXTHOST_IPC_SOCKET",
10289
initialDataChunk: (buffer.buffer as Buffer).toString("base64"),
10390
skipWebSocketFrames: this.protocol.getSocket() instanceof NodeSocket,
104-
};
105-
106-
this.process.send(initMessage, socket);
91+
}, socket);
10792
}
10893

10994
private spawn(buffer: VSBuffer): cp.ChildProcess {
11095
const proc = cp.fork(
11196
getPathFromAmdModule(require, "bootstrap-fork"),
112-
[
113-
"--type=extensionHost",
114-
`--uriTransformerPath=${uriTransformerPath()}`
115-
],
97+
[ "--type=extensionHost", `--uriTransformerPath=${uriTransformerPath()}` ],
11698
{
11799
env: {
118100
...process.env,
@@ -129,13 +111,8 @@ export class ExtensionHostConnection extends Connection {
129111

130112
proc.on("error", () => this.dispose());
131113
proc.on("exit", () => this.dispose());
132-
133-
proc.stdout.setEncoding("utf8");
134-
proc.stderr.setEncoding("utf8");
135-
136-
proc.stdout.on("data", (d) => this.log.info("Extension host stdout", d));
137-
proc.stderr.on("data", (d) => this.log.error("Extension host stderr", d));
138-
114+
proc.stdout.setEncoding("utf8").on("data", (d) => this.log.info("Extension host stdout", d));
115+
proc.stderr.setEncoding("utf8").on("data", (d) => this.log.error("Extension host stderr", d));
139116
proc.on("message", (event) => {
140117
if (event && event.type === "__$console") {
141118
const severity = this.log[event.severity] ? event.severity : "info";
@@ -149,8 +126,7 @@ export class ExtensionHostConnection extends Connection {
149126
this.sendInitMessage(buffer);
150127
}
151128
};
152-
proc.on("message", listen);
153129

154-
return proc;
130+
return proc.on("message", listen);
155131
}
156132
}

src/protocol.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ export class Protocol extends PersistentProtocol {
7373
* TODO: This ignores the authentication process entirely for now.
7474
*/
7575
private authenticate(_message: AuthRequest): void {
76-
this.sendMessage({
77-
type: "sign",
78-
data: "",
79-
});
76+
this.sendMessage({ type: "sign", data: "" });
8077
}
8178

8279
/**

0 commit comments

Comments
 (0)