Skip to content

Commit f48728a

Browse files
committed
report typings installer process id to parent process
1 parent 66c1178 commit f48728a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/server/server.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace ts.server {
4040
send(message: any, sendHandle?: any): void;
4141
on(message: "message", f: (m: any) => void): void;
4242
kill(): void;
43+
pid: number;
4344
}
4445

4546
interface NodeSocket {
@@ -179,6 +180,7 @@ namespace ts.server {
179180

180181
class NodeTypingsInstaller implements ITypingsInstaller {
181182
private installer: NodeChildProcess;
183+
private installerPidReported = false;
182184
private socket: NodeSocket;
183185
private projectService: ProjectService;
184186

@@ -190,10 +192,25 @@ namespace ts.server {
190192
if (eventPort) {
191193
const s = net.connect({ port: eventPort }, () => {
192194
this.socket = s;
195+
this.reportInstallerProcessId();
193196
});
194197
}
195198
}
196199

200+
private reportInstallerProcessId() {
201+
if (this.installerPidReported) {
202+
return;
203+
}
204+
if (this.socket && this.installer) {
205+
this.sendEvent(0, "typingsInstallerPid", { pid: this.installer.pid });
206+
this.installerPidReported = true;
207+
}
208+
}
209+
210+
private sendEvent(seq: number, event: string, body: any): void {
211+
this.socket.write(formatMessage({ seq, type: "event", event, body }, this.logger, Buffer.byteLength, this.newLine), "utf8");
212+
}
213+
197214
attach(projectService: ProjectService) {
198215
this.projectService = projectService;
199216
if (this.logger.hasLevel(LogLevel.requestTime)) {
@@ -222,6 +239,8 @@ namespace ts.server {
222239

223240
this.installer = childProcess.fork(combinePaths(__dirname, "typingsInstaller.js"), args, { execArgv });
224241
this.installer.on("message", m => this.handleMessage(m));
242+
this.reportInstallerProcessId();
243+
225244
process.on("exit", () => {
226245
this.installer.kill();
227246
});
@@ -245,7 +264,7 @@ namespace ts.server {
245264
}
246265
this.projectService.updateTypingsForProject(response);
247266
if (response.kind == "set" && this.socket) {
248-
this.socket.write(formatMessage({ seq: 0, type: "event", message: response }, this.logger, Buffer.byteLength, this.newLine), "utf8");
267+
this.sendEvent(0, "setTypings", response);
249268
}
250269
}
251270
}

0 commit comments

Comments
 (0)