BrianHicks / tree-grepper

Like grep, but uses tree-sitter grammars to search
Other
290 stars 20 forks source link

enable building only with Cargo #490

Open wis opened 2 months ago

wis commented 2 months ago

Hello! thank you for creating this awesome project, I'm finding it immensely useful and fun to use. I tried using ast-grep many times, but I was never able to get it to work and have the query return what I want. I just tried tree-grepper and in about 10 minutes, with the help of the Tree-sitter ":Inspect" Playground in Neovim, which looks like this:

Tree-sitter Inspect in Neovim

...and with the help of ChatGPT to refine the tree-sitter query, I was able to have the query return what I wanted exactly:

[
  {
    "file": "mod.rs",
    "file_type": "rust",
    "matches": [
      {
        "kind": "string_content",
        "name": "string",
        "text": "lrld",
        "start": {
          "row": 1486,
          "column": 10
        },
        "end": {
          "row": 1486,
          "column": 14
        }
      },
      {
        "kind": "string_content",
        "name": "string",
        "text": "sldr",
        "start": {
          "row": 1489,
          "column": 10
        },
        "end": {
          "row": 1489,
          "column": 14
        }
      },
      {
        "kind": "string_content",
        "name": "string",
        "text": "scnl",
        "start": {
          "row": 1498,
          "column": 10
        },
        "end": {
          "row": 1498,
          "column": 14
        }
      },
      {
        "kind": "string_content",
        "name": "string",
        "text": "rpt-any",
        "start": {
          "row": 1542,
          "column": 10
        },
        "end": {
          "row": 1542,
          "column": 17
        }
      },
      "............"
]

The query:

(
  (match_expression
    "match"
    value: (identifier)
    body: (match_block
      "{"
      (match_arm
        pattern: (match_pattern
            (string_literal
              "\"" 
              (string_content) @string
            )
        )
      )
    )
  )
)

but before actually getting to try it out, I had a lot of trouble and wasted quite a lot of time trying to get to try to use it, by building it, since trying out the Nix package manager on Arch didn't work for me, it didn't install correctly and outputs something something "socket permission error" when I try to use a Nix command.

I think enabling only a Cargo build option, without Nix, would be helpful to a lot more people and would enable a lot more people to try the software. a Cargo only build would also enable you to publish a pre-built binary to crates.io, so it would make installing for people even more easier.

Edit: see prior issues about this, which this PR potentially fixes #229 #261 #293