diff --git a/src/main.js b/src/main.js index 839f5b226a96f5e43f4ac16edcfc9ff8a59c6a6a..362345c3ff19c0189113d9cfcae97582abb666fa 100644 --- a/src/main.js +++ b/src/main.js @@ -95,13 +95,16 @@ function getNLSConfiguration() { return { locale: initialLocale, availableLanguages: {} }; } -// Change cwd if given via env variable +// Update cwd based on environment and platform try { - if (process.env.VSCODE_CWD) { + if (process.platform === 'win32') { + process.env.VSCODE_CWD = process.cwd(); // remember as environment variable + process.chdir(path.dirname(app.getPath('exe'))); // always set application folder as cwd + } else if (process.env.VSCODE_CWD) { process.chdir(process.env.VSCODE_CWD); } } catch (err) { - // noop + console.error(err); } // Set path according to being built or not @@ -121,12 +124,12 @@ args.forEach(function (arg) { // Mac: when someone drops a file to the not-yet running VSCode, the open-file event fires even before // the app-ready event. We listen very early for open-file and remember this upon startup as path to open. global.macOpenFiles = []; -app.on('open-file', function(event, path) { +app.on('open-file', function (event, path) { global.macOpenFiles.push(path); }); // Load our code once ready -app.once('ready', function() { +app.once('ready', function () { var nlsConfig = getNLSConfiguration(); process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig); require('./bootstrap-amd').bootstrap('vs/workbench/electron-main/main'); diff --git a/src/vs/workbench/electron-main/env.ts b/src/vs/workbench/electron-main/env.ts index 0b6c8a0c0fb07b4d2628ebe2c4e94e79f6312480..0c2265893e37fe9fe0ac0f8d04e4934fe835cdc7 100644 --- a/src/vs/workbench/electron-main/env.ts +++ b/src/vs/workbench/electron-main/env.ts @@ -64,6 +64,8 @@ export const isBuilt = !process.env.VSCODE_DEV; export const appRoot = path.dirname(uri.parse(require.toUrl('')).fsPath); +export const currentWorkingDirectory = process.env.VSCODE_CWD || process.cwd(); + let productContents: IProductConfiguration; try { productContents = JSON.parse(fs.readFileSync(path.join(appRoot, 'product.json'), 'utf8')); @@ -280,7 +282,7 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] { } if (pathCandidate) { - pathCandidate = massagePath(pathCandidate); + pathCandidate = preparePath(pathCandidate); } let realPath: string; @@ -289,7 +291,7 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] { } catch (error) { // in case of an error, assume the user wants to create this file // if the path is relative, we join it to the cwd - realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(process.cwd(), pathCandidate)); + realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(currentWorkingDirectory, pathCandidate)); } if (!paths.isValidBasename(path.basename(realPath))) { @@ -310,30 +312,32 @@ function parsePathArguments(argv: string[], gotoLineMode?: boolean): string[] { ); } -function massagePath(path: string): string { +function preparePath(p: string): string { + + // Trim trailing quotes if (platform.isWindows) { - path = strings.rtrim(path, '"'); // https://github.com/Microsoft/vscode/issues/1498 + p = strings.rtrim(p, '"'); // https://github.com/Microsoft/vscode/issues/1498 } // Trim whitespaces - path = strings.trim(strings.trim(path, ' '), '\t'); + p = strings.trim(strings.trim(p, ' '), '\t'); - // Trim '.' chars on Windows to prevent invalid file names if (platform.isWindows) { - path = strings.rtrim(resolvePath(path), '.'); + + // Resolve the path against cwd if it is relative + p = path.resolve(currentWorkingDirectory, p); + + // Trim trailing '.' chars on Windows to prevent invalid file names + p = strings.rtrim(p, '.'); } - return path; + return p; } function normalizePath(p?: string): string { return p ? path.normalize(p) : p; } -function resolvePath(p?: string): string { - return p ? path.resolve(p): p; -} - function parseNumber(argv: string[], key: string, defaultValue?: number, fallbackValue?: number): number { let value: number;