Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - preview #196

Closed
niba opened this issue Aug 6, 2024 · 6 comments
Closed

Feature - preview #196

niba opened this issue Aug 6, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@niba
Copy link

niba commented Aug 6, 2024

I would like to propose a new feature called preview.

Very often, when I do search & replace in my projects, I want to quickly skim through the results to double-check everything. In vscode, when you perform a search and replace and select one of the results, you get a diff view of the entire file.
image

It would be really nice to have something similar here (if that's possible).

Workflow:

  1. Perform a search.
  2. Go to one of the results.
  3. Automatically display the diff on selection (as an option) or use a special keybinding/command.
    a) preview / diff shouldn't clutter your existing buffers.
@MagicDuck
Copy link
Owner

MagicDuck commented Aug 6, 2024

I think an external tool with git is probably much better for this kind of review.
Just apply the replace and then use lazygit or whatever tool to review it. If you don't like it, you can just discard and try again. Seems like an easier process. You just have to make sure to commit your previous work...

Alternatively, if what we really want is to show inline diffs that's maybe something that could be implemented, although a bit of a pain with ripgrep since we would have to call it twice (once without the replacement and once with). Note that you can already specify the --context=<num> flag to see more context around each match.

If you use the astgrep engine it will show you diffs already:

image

Although context is broken for it temporarily. See: ast-grep/ast-grep#1381 (comment)

@MagicDuck MagicDuck added the enhancement New feature or request label Aug 6, 2024
@MagicDuck
Copy link
Owner

Unfortunately inline diff can not work with rg atm, see BurntSushi/ripgrep#1872
And I dont think the side by side diff is a good fit for this plugin. As such I will close this.

@niba
Copy link
Author

niba commented Aug 9, 2024

@MagicDuck thanks for digging into this topic.

The trick with Git is indeed something that could replace what I mentioned. I just need to get into the habit of committing everything before any serious renaming 😄

@MagicDuck
Copy link
Owner

MagicDuck commented Aug 9, 2024

Yeah, or even just staging would be sufficient.
The way I do it is I have a special keybind in my terminal (wezterm) that takes me to a tab containing lazygit (and back if I am on the lazygit tab). I stage every time I am in a good spot and am going to do some refactoring or something slightly destructive 😆

@MagicDuck
Copy link
Owner

@niba FYI, we now show a diff for replace. Here's an example with 2 lines of context (-C 2):
image

@niba
Copy link
Author

niba commented Sep 9, 2024

Amazing! Thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants