@@ -2,7 +2,12 @@ import path from 'node:path'
2
2
import { type ExtensionContext , commands , workspace , window } from 'vscode'
3
3
import { type ChildProcessWithoutNullStreams , spawn } from 'node:child_process'
4
4
5
- import { parentPort , resolveBinary , streamedPromise } from './common'
5
+ import {
6
+ parentPort ,
7
+ resolveBinary ,
8
+ streamedPromise ,
9
+ normalizeCommandForWindows ,
10
+ } from './common'
6
11
import type { SgSearch , DisplayResult , SearchQuery } from '../types'
7
12
8
13
/**
@@ -114,9 +119,7 @@ export function buildCommand(query: SearchQuery) {
114
119
return
115
120
}
116
121
const command = resolveBinary ( )
117
- // windows user may input space in command
118
- const normalizedCommand =
119
- / \s / . test ( command ) && ! command . endsWith ( '.exe' ) ? `"${ command } "` : command
122
+ const { normalizedCommand, shell } = normalizeCommandForWindows ( command )
120
123
const uris = workspace . workspaceFolders ?. map ( i => i . uri ?. fsPath ) ?? [ ]
121
124
const args = [ 'run' , '--pattern' , pattern , '--json=stream' ]
122
125
if ( query . selector ) {
@@ -141,9 +144,7 @@ export function buildCommand(query: SearchQuery) {
141
144
console . debug ( 'running' , query , normalizedCommand , args )
142
145
// TODO: multi-workspaces support
143
146
return spawn ( normalizedCommand , args , {
144
- // for windows
145
- shell :
146
- process . platform === 'win32' && ! command . toLowerCase ( ) . endsWith ( '.exe' ) ,
147
+ shell,
147
148
cwd : uris [ 0 ] ,
148
149
} )
149
150
}
0 commit comments