ast-grep-vscode
ast-grep-vscode copied to clipboard
Find and replace in current (unsaved/out-of-workspace) file
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.
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 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
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.
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
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