Skip to content

Commit 72f81e2

Browse files
authored
Merge pull request #11841 from Microsoft/vladima/report-typings-installer-pid
report typings installer process id to parent process
2 parents 7890f63 + f48728a commit 72f81e2

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
private throttledOperations: ThrottledOperations;
@@ -193,10 +195,25 @@ namespace ts.server {
193195
if (eventPort) {
194196
const s = net.connect({ port: eventPort }, () => {
195197
this.socket = s;
198+
this.reportInstallerProcessId();
196199
});
197200
}
198201
}
199202

203+
private reportInstallerProcessId() {
204+
if (this.installerPidReported) {
205+
return;
206+
}
207+
if (this.socket && this.installer) {
208+
this.sendEvent(0, "typingsInstallerPid", { pid: this.installer.pid });
209+
this.installerPidReported = true;
210+
}
211+
}
212+
213+
private sendEvent(seq: number, event: string, body: any): void {
214+
this.socket.write(formatMessage({ seq, type: "event", event, body }, this.logger, Buffer.byteLength, this.newLine), "utf8");
215+
}
216+
200217
attach(projectService: ProjectService) {
201218
this.projectService = projectService;
202219
if (this.logger.hasLevel(LogLevel.requestTime)) {
@@ -225,6 +242,8 @@ namespace ts.server {
225242

226243
this.installer = childProcess.fork(combinePaths(__dirname, "typingsInstaller.js"), args, { execArgv });
227244
this.installer.on("message", m => this.handleMessage(m));
245+
this.reportInstallerProcessId();
246+
228247
process.on("exit", () => {
229248
this.installer.kill();
230249
});
@@ -255,7 +274,7 @@ namespace ts.server {
255274
}
256275
this.projectService.updateTypingsForProject(response);
257276
if (response.kind == "set" && this.socket) {
258-
this.socket.write(formatMessage({ seq: 0, type: "event", message: response }, this.logger, Buffer.byteLength, this.newLine), "utf8");
277+
this.sendEvent(0, "setTypings", response);
259278
}
260279
}
261280
}

0 commit comments

Comments
 (0)