Skip to content

Commit

Permalink
AI generated image included bash
Browse files Browse the repository at this point in the history
* instead, call tree-sitter binary directly
  • Loading branch information
slimslenderslacks committed Oct 9, 2024
1 parent b920a03 commit de7226e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
18 changes: 6 additions & 12 deletions functions/tree-sitter/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,28 @@
in rec {
packages = rec {

# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/go/module.nix
goBinary = pkgs.buildGoModule {
pname = "tree-sitter-query";
version = "0.1.0";
src = ./.; # Assuming your Go code is in the same directory as the flake.nix

buildInputs = [pkgs.tree-sitter];

CGO_ENABLED = "1";

CGO_CFLAGS = "-I${pkgs.tree-sitter}/include";

# If you have vendored dependencies, use this:
# vendorSha256 = null;

# If you're not using vendored dependencies, compute the hash of your go.mod and go.sum
# You can get this hash by first setting it to lib.fakeSha256,
# then running the build and replacing it with the correct hash
vendorHash = "sha256-/X9cuzpVzVOqcON3c2GtUwCXi6gfFzjjQ8r+D0Yhgu8=";

postInstall = ''
mv $out/bin/ts $out/bin/entrypoint
'';

# Specify the package to build if it's not in the root of your project
subPackages = [ "cmd/ts" ];
};

default = pkgs.writeShellScriptBin "entrypoint" ''
export PATH=${pkgs.lib.makeBinPath [goBinary]}
ts "$@"
'';

default = goBinary;
};

devShells.default = pkgs.devshell.mkShell {
Expand Down
8 changes: 5 additions & 3 deletions functions/tree-sitter/runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ docker buildx build \
docker pull vonwig/tree-sitter:latest
```

## Run

```sh
./result/bin/ts -lang python -query "(module (function_definition) @top-level)" < test/resources/hello.py
./result/bin/ts -lang markdown -query "(document (section (atx_heading (atx_h1_marker))) @h1)" < test/resources/hello.md
./result/bin/entrypoint -lang python -query "(module (function_definition) @top-level)" < test/resources/hello.py
./result/bin/entrypoint -lang markdown -query "(document (section (atx_heading (atx_h1_marker))) @h1)" < test/resources/hello.md
```

```sh
./result/bin/ts -lang markdown < test/resources/hello.md
./result/bin/entrypoint -lang markdown < test/resources/hello.md
```

```sh
Expand Down

0 comments on commit de7226e

Please sign in to comment.