@@ -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 * ) i d : \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 = / ^ r u l e : / m. test ( text ) && / ^ i d : / m. test ( text ) && / ^ l a n g u a g e : / 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 {
0 commit comments