Skip to content

Commit 8cd58ff

Browse files
fix: await if sg window is not initialized yet
1 parent f4aa1b2 commit 8cd58ff

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/extension/codelens.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ export function activateCodeLens(context: vscode.ExtensionContext) {
1414
// Register the command that the CodeLens will execute
1515
const runRuleCommand = vscode.commands.registerCommand(
1616
'ast-grep.runRule',
17-
(text: string) => {
18-
parentPort.postMessage('searchByYAML', {
19-
text,
20-
})
21-
vscode.commands.executeCommand('ast-grep.search.input.focus')
17+
async (text: string) => {
18+
await vscode.commands.executeCommand('ast-grep.search.input.focus')
19+
// if the input box is not ready, retry after a short delay
20+
// since unport is not set up yet
21+
try {
22+
parentPort.postMessage('searchByYAML', {
23+
text,
24+
})
25+
} catch (_e) {
26+
// wait for input box to show up
27+
await new Promise(r => setTimeout(r, 300))
28+
parentPort.postMessage('searchByYAML', {
29+
text,
30+
})
31+
}
2232
},
2333
)
2434

0 commit comments

Comments
 (0)