Skip to content

Commit 6acb089

Browse files
fix: fix several bugs
1 parent c6933a1 commit 6acb089

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/extension/codelens.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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-
(ruleId: string, text: string) => {
17+
(text: string) => {
1818
parentPort.postMessage('searchByYAML', {
1919
text,
2020
})
@@ -29,27 +29,21 @@ class CodelensProvider implements vscode.CodeLensProvider {
2929
document: vscode.TextDocument,
3030
_token: vscode.CancellationToken,
3131
): vscode.CodeLens[] {
32-
const codeLenses: vscode.CodeLens[] = []
3332
const text = document.getText()
3433

35-
// Look for rule definitions in YAML files (sgconfig.yml)
36-
const ruleMatches = text.matchAll(/^(\s*)id:\s*(.+)$/gm)
37-
38-
for (const match of ruleMatches) {
39-
const ruleId = match[2].trim()
40-
const line = document.positionAt(match.index!).line
41-
const range = new vscode.Range(line, 0, line, 0)
42-
43-
const command: vscode.Command = {
44-
title: `Run rule: ${ruleId}`,
45-
command: 'ast-grep.runRule',
46-
arguments: [ruleId, text],
47-
}
48-
49-
codeLenses.push(new vscode.CodeLens(range, command))
34+
// Look for rule definitions in YAML files
35+
const isAstGrepRule = /^rule:/m.test(text) && /^id:/m.test(text) && /^language:/m.test(text)
36+
if (!isAstGrepRule) {
37+
return []
5038
}
5139

52-
return codeLenses
40+
const range = new vscode.Range(0, 0, 0, 0)
41+
const command: vscode.Command = {
42+
title: `Run ast-grep rule`,
43+
command: 'ast-grep.runRule',
44+
arguments: [text],
45+
}
46+
return [new vscode.CodeLens(range, command)]
5347
}
5448

5549
resolveCodeLens(codeLens: vscode.CodeLens, _token: vscode.CancellationToken): vscode.CodeLens {

src/webview/hooks/useSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function getSnapshot() {
177177

178178
function queryHasRewrite() {
179179
if ('yaml' in queryInFlight) {
180-
return /^fix:/.test(queryInFlight.yaml)
180+
return /^fix:/m.test(queryInFlight.yaml)
181181
}
182182
return !!queryInFlight.rewrite
183183
}

0 commit comments

Comments
 (0)