mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Fix some possible TSServer spawn issues (#32007)
**Bug** A few users are seeing issues spaning the tsserver. The most common error seems to be ERRNO when spawning it **Fix** - Ensure we always try to set `env.PATH` - Use `require.resolve` to check the existance of the `electronForkStart` helper before calling spawn
This commit is contained in:
@@ -599,10 +599,6 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
private get mainWorkspaceRootPath(): string | undefined {
|
||||
if (workspace.rootPath) {
|
||||
return workspace.rootPath;
|
||||
}
|
||||
|
||||
if (workspace.workspaceFolders && workspace.workspaceFolders.length) {
|
||||
return workspace.workspaceFolders[0].uri.fsPath;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export function makeRandomHexString(length: number): string {
|
||||
let chars = ['0', '1', '2', '3', '4', '5', '6', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
let idx = Math.floor(chars.length * Math.random());
|
||||
const idx = Math.floor(chars.length * Math.random());
|
||||
result += chars[idx];
|
||||
}
|
||||
return result;
|
||||
@@ -27,6 +27,7 @@ export function makeRandomHexString(length: number): string {
|
||||
function generatePipeName(): string {
|
||||
return getPipeName(makeRandomHexString(40));
|
||||
}
|
||||
|
||||
function getPipeName(name: string): string {
|
||||
const fullName = 'vscode-' + name;
|
||||
if (process.platform === 'win32') {
|
||||
@@ -43,19 +44,22 @@ export function getTempFile(name: string): string {
|
||||
}
|
||||
|
||||
|
||||
function generatePatchedEnv(env: any, stdInPipeName: string, stdOutPipeName: string, stdErrPipeName: string): any {
|
||||
function generatePatchedEnv(
|
||||
env: any,
|
||||
stdInPipeName: string,
|
||||
stdOutPipeName: string,
|
||||
stdErrPipeName: string
|
||||
): any {
|
||||
const newEnv = Object.assign({}, env);
|
||||
|
||||
// Set the two unique pipe names and the electron flag as process env
|
||||
|
||||
var newEnv: any = {};
|
||||
for (var key in env) {
|
||||
newEnv[key] = env[key];
|
||||
}
|
||||
|
||||
newEnv['STDIN_PIPE_NAME'] = stdInPipeName;
|
||||
newEnv['STDOUT_PIPE_NAME'] = stdOutPipeName;
|
||||
newEnv['STDERR_PIPE_NAME'] = stdErrPipeName;
|
||||
newEnv['ELECTRON_RUN_AS_NODE'] = '1';
|
||||
|
||||
// Ensure we always have a PATH set
|
||||
newEnv['PATH'] = newEnv['PATH'] || process.env.PATH;
|
||||
return newEnv;
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ export function fork(
|
||||
callback: (error: any, cp: cp.ChildProcess | null) => void,
|
||||
): void {
|
||||
|
||||
var callbackCalled = false;
|
||||
let callbackCalled = false;
|
||||
const resolve = (result: cp.ChildProcess) => {
|
||||
if (callbackCalled) {
|
||||
return;
|
||||
@@ -90,7 +94,7 @@ export function fork(
|
||||
|
||||
|
||||
const newEnv = generatePatchedEnv(process.env, stdInPipeName, stdOutPipeName, stdErrPipeName);
|
||||
var childProcess: cp.ChildProcess;
|
||||
let childProcess: cp.ChildProcess;
|
||||
|
||||
// Begin listening to stderr pipe
|
||||
let stdErrServer = net.createServer((stdErrStream) => {
|
||||
@@ -115,7 +119,7 @@ export function fork(
|
||||
});
|
||||
stdOutServer.listen(stdOutPipeName);
|
||||
|
||||
var serverClosed = false;
|
||||
let serverClosed = false;
|
||||
const closeServer = () => {
|
||||
if (serverClosed) {
|
||||
return;
|
||||
@@ -128,8 +132,8 @@ export function fork(
|
||||
// Create the process
|
||||
logger.info('Forking TSServer', `PATH: ${newEnv['PATH']}`);
|
||||
|
||||
const bootstrapperPath = path.join(__dirname, 'electronForkStart');
|
||||
childProcess = cp.fork(bootstrapperPath, [modulePath].concat(args), <any>{
|
||||
const bootstrapperPath = require.resolve('./electronForkStart');
|
||||
childProcess = cp.fork(bootstrapperPath, [modulePath].concat(args), {
|
||||
silent: true,
|
||||
cwd: options.cwd,
|
||||
env: newEnv,
|
||||
|
||||
Reference in New Issue
Block a user