ast-grep / ast-grep-vscode

ast-grep VSCode is a structural search and replace extension for many languages.
https://marketplace.visualstudio.com/items?itemName=ast-grep.ast-grep-vscode
MIT License
165 stars 16 forks source link

Is there a trick to matching to `()` call? #401

Closed JasonKleban closed 1 month ago

JasonKleban commented 1 month ago

SG AST-GREP vscode is working for me in some cases (so it's wired up), but parentheses for a function call are not working. So pattern format works, but pattern format($A) does not find format(data) for example. I'm on Windows, btw. I'm surprised I can't find any mention of this.

HerringtonDarkholme commented 1 month ago

What language are you using? It's probably already mentioned in the doc

https://ast-grep.github.io/catalog/c/#match-function-call-in-c

JasonKleban commented 1 month ago

Thanks! I'm using typescript (.ts files, not .tsx yet) and the commandline sg --pattern 'format($A)' --lang ts is working for me. Just not the VSCode extension when ( ) are involved.

HerringtonDarkholme commented 1 month ago

Please provide a minimal reproduction and also check your setting

image
JasonKleban commented 1 month ago

OK, I found my way to this extension through a back alleyway and so I didn't know to fully set up the environment.

I guess perhaps a simple term doesn't require a working LSP but the parentheses do. Without the sgconfig.yml, the search for format finds matches. Checking the ~hidden Output Log of "ast-grep" gave me the full diagnosis.

image

Side note: Could this empty sgconfig.yml just be assumed? Even with no ruleDirs set, it seems to work. It's not super nice to include a convenience extension's config file in a project root shared with others who might not use the extension.

JasonKleban commented 1 month ago

Even with no ruleDirs set, it seems to work.

No, it doesn't work well with the empty file. And neither does sg (silently finds no matches) but if I get rid of the sgconfig.yml sg works again.

HerringtonDarkholme commented 1 month ago

You have to have a valid configuration file or have no configuration at all

JasonKleban commented 1 month ago

No, without a config file, the LSP won't start and the AST-GREP extension fails silently on all but simple patterns, as above. ("24 results in 10 files" for pattern format)

image

HerringtonDarkholme commented 1 month ago

I believe it's your problem. If you can help providing a minimal reproduction we can help you.