ast-grep-vscode icon indicating copy to clipboard operation
ast-grep-vscode copied to clipboard

Find and replace in current (unsaved/out-of-workspace) file

Open molenzwiebel opened this issue 10 months ago • 3 comments

I'd love some way to have an ast-grep version of Ctrl-F, i.e. limited to the current file and not requiring the file to actually be in my current vscode workspace (or even be on disk at all). I don't mind if it still writes it to the disk in the background to do the actual processing.

I often find myself wanting to use ast-grep to do small transformations on code snippets that I copied from the internet/am sending to someone as an example/are not in my current workspace. Right now I have to copy them over, perform the transformation, then delete the result. As a result, I end up just fumbling around with multi-cursor replacements instead.

molenzwiebel avatar Jan 05 '25 16:01 molenzwiebel

It is possible to do that with ast-grep --stdin and pass file content to the binary.

I am not personally interested in this feature. But interested people can leave their proposal here and we can discuss the implementation and pull request.

HerringtonDarkholme avatar Jan 05 '25 18:01 HerringtonDarkholme

@HerringtonDarkholme i'd be happy to help but subjectively it would make the most sense if ast-grep-core allowed incremental parsing. Then the lsp and client could use TextDocumentSyncKind.Incremental.

PiotrSokol avatar Apr 11 '25 13:04 PiotrSokol

@PiotrSokol

ast-grep-core allowed incremental parsing

It does support incremental parsing. but it is a different issue from the find/replace.

Currently find/replace is done by calling ast-grep cli and is not aware of any unsaved change in vscode.

HerringtonDarkholme avatar Apr 11 '25 13:04 HerringtonDarkholme

I'd like this, but I don't care so much about unsaved files. I'd just like an equivalent of cmd+f to search/replace the current file only

WickyNilliams avatar Aug 01 '25 08:08 WickyNilliams

I'd just like an equivalent of cmd+f to search/replace the current file only

vscode does not expose such API. https://github.com/microsoft/vscode/issues/59924

HerringtonDarkholme avatar Aug 19 '25 22:08 HerringtonDarkholme