diff --git a/src/server/server.ts b/src/server/server.ts index dc614fba1f7..2f98db89833 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -183,9 +183,25 @@ namespace ts.server { let args: string[] = []; if (this.logger.loggingEnabled() && this.logger.getLogFileName()) { - args = [ "--logFile", combinePaths(getDirectoryPath(normalizeSlashes(this.logger.getLogFileName())), `ti-${process.pid}.log`) ]; + args.push("--logFile", combinePaths(getDirectoryPath(normalizeSlashes(this.logger.getLogFileName())), `ti-${process.pid}.log`)); } - this.installer = childProcess.fork(combinePaths(__dirname, "typingsInstaller.js"), args); + let execArgv: string[] = []; + { + for (const arg of process.execArgv) { + const match = /^--(debug|inspect)(=(\d+))?$/.exec(arg); + if (match) { + // if port is specified - use port + 1 + // otherwise pick a default port depending on if 'debug' or 'inspect' and use its value + 1 + let currentPort = match[3] !== undefined + ? +match[3] + : match[1] === "debug" ? 5858 : 9229; + execArgv.push(`--${match[1]}=${currentPort + 1}`); + break; + } + } + } + + this.installer = childProcess.fork(combinePaths(__dirname, "typingsInstaller.js"), args, { execArgv }); this.installer.on("message", m => this.handleMessage(m)); process.on("exit", () => { this.installer.kill();