@@ -29,11 +29,16 @@ function isTerminalEditor(editor) {
29
29
// We can't just re-use full process name, because it will spawn a new instance
30
30
// of the app every time
31
31
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
+ }
37
42
} ;
38
43
39
44
function addWorkspaceToArgumentsIfExists ( args , workspace ) {
@@ -86,22 +91,32 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
86
91
return [ fileName ] ;
87
92
}
88
93
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
+
89
104
function guessEditor ( ) {
90
105
// Explicit config always wins
91
106
if ( process . env . REACT_EDITOR ) {
92
107
return shellQuote . parse ( process . env . REACT_EDITOR ) ;
93
108
}
94
109
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' ) {
98
113
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 ] ) ;
101
116
for ( var i = 0 ; i < processNames . length ; i ++ ) {
102
117
var processName = processNames [ i ] ;
103
118
if ( output . indexOf ( processName ) !== - 1 ) {
104
- return [ COMMON_EDITORS [ processName ] ] ;
119
+ return [ COMMON_EDITORS [ process . platform ] [ processName ] ] ;
105
120
}
106
121
}
107
122
} catch ( error ) {
0 commit comments