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() {
32
32
}
33
33
34
34
export function resolveBinary ( ) {
35
- const config = workspace . getConfiguration ( 'astGrep' ) . get ( 'serverPath' , '' )
35
+ const config = workspace
36
+ . getConfiguration ( 'astGrep' )
37
+ . get ( 'serverPath' , '' )
38
+ . trim ( )
36
39
if ( ! config ) {
37
40
return defaultBinary
38
41
}
@@ -41,15 +44,16 @@ export function resolveBinary() {
41
44
42
45
export async function testBinaryExist ( command : string ) {
43
46
// 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
45
49
const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
46
50
return new Promise ( r => {
47
51
execFile (
48
52
normalizedCommand ,
49
53
[ '-h' ] ,
50
54
{
51
55
// for windows
52
- shell : process . platform === 'win32' ,
56
+ shell : process . platform === 'win32' && ! command . endsWith ( '.exe' ) ,
53
57
cwd : uris [ 0 ] ,
54
58
} ,
55
59
err => {
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ export function buildCommand(query: SearchQuery) {
114
114
return
115
115
}
116
116
const command = resolveBinary ( )
117
+ // windows user may input space in command
118
+ const normalizedCommand =
119
+ / \s / . test ( command ) && ! command . endsWith ( '.exe' ) ? `"${ command } "` : command
117
120
const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
118
121
const args = [ 'run' , '--pattern' , pattern , '--json=stream' ]
119
122
if ( query . selector ) {
@@ -135,9 +138,11 @@ export function buildCommand(query: SearchQuery) {
135
138
} else {
136
139
args . push ( ...validIncludeFile )
137
140
}
138
- console . debug ( 'running' , query , command , args )
141
+ console . debug ( 'running' , query , normalizedCommand , args )
139
142
// 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' ) ,
141
146
cwd : uris [ 0 ] ,
142
147
} )
143
148
}
You can’t perform that action at this time.
0 commit comments