File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,10 @@ export async function detectDefaultBinaryAtStart() {
3232}
3333
3434export function resolveBinary ( ) {
35- const config = workspace . getConfiguration ( 'astGrep' ) . get ( 'serverPath' , '' )
35+ const config = workspace
36+ . getConfiguration ( 'astGrep' )
37+ . get ( 'serverPath' , '' )
38+ . trim ( )
3639 if ( ! config ) {
3740 return defaultBinary
3841 }
@@ -41,15 +44,16 @@ export function resolveBinary() {
4144
4245export async function testBinaryExist ( command : string ) {
4346 // windows user may input space in command
44- const normalizedCommand = / \s / . test ( command . trim ( ) ) ? `"${ command } "` : command
47+ const normalizedCommand =
48+ / \s / . test ( command ) && ! command . endsWith ( '.exe' ) ? `"${ command } "` : command
4549 const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
4650 return new Promise ( r => {
4751 execFile (
4852 normalizedCommand ,
4953 [ '-h' ] ,
5054 {
5155 // for windows
52- shell : process . platform === 'win32' ,
56+ shell : process . platform === 'win32' && ! command . endsWith ( '.exe' ) ,
5357 cwd : uris [ 0 ] ,
5458 } ,
5559 err => {
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ export function buildCommand(query: SearchQuery) {
114114 return
115115 }
116116 const command = resolveBinary ( )
117+ // windows user may input space in command
118+ const normalizedCommand =
119+ / \s / . test ( command ) && ! command . endsWith ( '.exe' ) ? `"${ command } "` : command
117120 const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
118121 const args = [ 'run' , '--pattern' , pattern , '--json=stream' ]
119122 if ( query . selector ) {
@@ -135,9 +138,11 @@ export function buildCommand(query: SearchQuery) {
135138 } else {
136139 args . push ( ...validIncludeFile )
137140 }
138- console . debug ( 'running' , query , command , args )
141+ console . debug ( 'running' , query , normalizedCommand , args )
139142 // TODO: multi-workspaces support
140- return spawn ( command , args , {
143+ return spawn ( normalizedCommand , args , {
144+ // for windows
145+ shell : process . platform === 'win32' && ! command . endsWith ( '.exe' ) ,
141146 cwd : uris [ 0 ] ,
142147 } )
143148}
You can’t perform that action at this time.
0 commit comments