BurntSushi / ripgrep

ripgrep recursively searches directories for a regex pattern while respecting your gitignore
The Unlicense
48.92k stars 2.01k forks source link

Add replacement into json output #2883

Open MagicDuck opened 2 months ago

MagicDuck commented 2 months ago

fixes https://github.com/BurntSushi/ripgrep/issues/1872

Hi, I am new to this repo so feel free to let me know if there is any way I can improve this PR. As detailed in the liked issue, this functionality is useful for quite a few cases where search/replace type tooling is built around ripgrep. My own neovim plugin is an example of a tool built on top of your great work 😄 : https://github.com/MagicDuck/grug-far.nvim This change would allow me to show diffs, a much requested feature.

Example:

Given the following text in file /home/andrew/sherlock:

For the Doctor Watsons of this world, as opposed to the Sherlock
Holmeses, success in the province of detective work must always

Searching for Watson with a replacement parameter of Moriarity, here's what a match type item would looks like:

{
  "type": "match",
  "data": {
    "path": {"text": "/home/andrew/sherlock"},
    "lines": {"text": "For the Doctor Watsons of this world, as opposed to the Sherlock\n"},
    "line_number": 1,
    "absolute_offset": 0,
    "submatches": [
      {"match": {"text": "Watson"}, "replacement": {"text": "Moriarity"}, "start": 15, "end": 21}
    ]
  }
}

P.S. Your documentation in code is amazing!

MagicDuck commented 2 months ago

hmm, not sure why the musleabihf test failed, it just says This job failed...

MagicDuck commented 2 months ago

hmm, passed now after changing a comment, just a blip I guess 😆