Skip to content

Commit 9fc26d2

Browse files
fix: terminate search even query is empty
fix #205
1 parent b649ab4 commit 9fc26d2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/extension/search.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ type StreamingHandler = (r: SgSearch[]) => void
8383
let child: ChildProcessWithoutNullStreams | undefined
8484

8585
async function uniqueCommand(
86-
proc: ChildProcessWithoutNullStreams,
86+
proc: ChildProcessWithoutNullStreams | undefined,
8787
handler: StreamingHandler,
8888
) {
8989
// kill previous search
9090
if (child) {
9191
child.kill('SIGTERM')
9292
}
93+
if (!proc) {
94+
return Promise.resolve()
95+
}
9396
try {
9497
// set current proc to child
9598
child = proc
@@ -140,13 +143,12 @@ function getPatternRes(query: SearchQuery, handlers: Handlers) {
140143
includeFiles: [query.includeFile],
141144
rewrite: query.rewrite,
142145
})
143-
if (!proc) {
144-
return Promise.resolve()
146+
if (proc) {
147+
proc.on('error', error => {
148+
console.debug('ast-grep CLI runs error')
149+
handlers.onError(error)
150+
})
145151
}
146-
proc.on('error', error => {
147-
console.debug('ast-grep CLI runs error')
148-
handlers.onError(error)
149-
})
150152
return uniqueCommand(proc, handlers.onData)
151153
}
152154

0 commit comments

Comments
 (0)