Skip to content

Commit adee1d0

Browse files
committed
Auto-detect running editor on Windows for error overlay
1 parent 67f6163 commit adee1d0

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

packages/react-dev-utils/launchEditor.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ function isTerminalEditor(editor) {
2929
// We can't just re-use full process name, because it will spawn a new instance
3030
// of the app every time
3131
var COMMON_EDITORS = {
32-
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
33-
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
34-
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
35-
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
36-
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
32+
'darwin': {
33+
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
34+
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta': '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
35+
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
36+
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2': '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
37+
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
38+
},
39+
'win32': {
40+
'\\Program Files (x86)\\Microsoft VS Code\\Code.exe': 'code'
41+
}
3742
};
3843

3944
function addWorkspaceToArgumentsIfExists(args, workspace) {
@@ -86,22 +91,32 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
8691
return [fileName];
8792
}
8893

94+
function getProcessList(platform) {
95+
if (platform === 'darwin') {
96+
return child_process.execSync('ps x').toString();
97+
} else if (platform === 'win32') {
98+
return child_process.execSync('powershell -Command "Get-Process | Select-Object Path"').toString();
99+
} else {
100+
return '';
101+
}
102+
}
103+
89104
function guessEditor() {
90105
// Explicit config always wins
91106
if (process.env.REACT_EDITOR) {
92107
return shellQuote.parse(process.env.REACT_EDITOR);
93108
}
94109

95-
// Using `ps x` on OSX we can find out which editor is currently running.
96-
// Potentially we could use similar technique for Windows and Linux
97-
if (process.platform === 'darwin') {
110+
// Using `ps x` on OSX or `Get-Process` on Windows we can find out which editor is currently running.
111+
// Potentially we could use similar technique for Linux
112+
if (process.platform === 'darwin' || process.platform === 'win32') {
98113
try {
99-
var output = child_process.execSync('ps x').toString();
100-
var processNames = Object.keys(COMMON_EDITORS);
114+
var output = getProcessList(process.platform);
115+
var processNames = Object.keys(COMMON_EDITORS[process.platform]);
101116
for (var i = 0; i < processNames.length; i++) {
102117
var processName = processNames[i];
103118
if (output.indexOf(processName) !== -1) {
104-
return [COMMON_EDITORS[processName]];
119+
return [COMMON_EDITORS[process.platform][processName]];
105120
}
106121
}
107122
} catch (error) {

0 commit comments

Comments
 (0)