Skip to content

Commit 579de17

Browse files
docs: Update tree-sitter-typst setup instructions
1 parent b7aa390 commit 579de17

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,19 @@ Use [ast-grep playground (forked version)][playground].
4646
4747
### Local
4848
49-
First, compile https://github.com/uben0/tree-sitter-typst to [add typst support](https://ast-grep.github.io/advanced/custom-language.html).
49+
First, put the tree-sitter-typst dynamic library beside this README. It will [add typst support to ast-grep](https://ast-grep.github.io/advanced/custom-language.html).
5050
51-
You could use GitHub Codespaces or Gitpod to compile:
51+
You could do so by any of the following methods:
5252
53-
```shell
54-
gh repo clone uben0/tree-sitter-typst -- --filter=blob:none
55-
npm install -g tree-sitter-cli
53+
- Run `just setup` to download it with GitHub CLI.
5654
57-
# Compile for Linux
58-
tree-sitter build --output tree-sitter-typst.so
55+
- Manually download it from [![Build tree-sitter-typst](https://github.com/YDX-2147483647/ast-grep-typst/actions/workflows/build-tree-sitter.yml/badge.svg)](https://github.com/YDX-2147483647/ast-grep-typst/actions/workflows/build-tree-sitter.yml).
5956
60-
# Cross-compile for Windows
61-
apt install mingw-w64
62-
CC=x86_64-w64-mingw32-gcc CFLAGS="-D_WIN32" tree-sitter build --output tree-sitter-typst.dll
63-
# At the end of the build process, tree-sitter will complain that “tree-sitter-typst.dll: invalid ELF header”, because it fails to verify dll on Linux.
64-
# You could ignore this error and manually verify the dll on Windows.
65-
```
57+
Choose the latest run, scroll down to _Artifacts_, select `*.so` for Linux or `*.dll` for Windows, and extract the downloaded zip file.
58+
59+
- (For professionals only) Compile it from https://github.com/uben0/tree-sitter-typst.
6660
67-
Download `tree-sitter-typst.{so,dll}` and put it at the root directory of this project.
61+
You could open that repo with GitHub Codespaces or Gitpod. Please refer to [the workflow file](./.github/workflows/build-tree-sitter.yml) for more info.
6862
6963
After that, you can use `ast-grep`. Please refer to [Quick Start | ast-grep](https://ast-grep.github.io/guide/quick-start.html) for more information.
7064

justfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
typst_preview := replace(cache_directory(), '\', '/') + "/typst/packages/preview"
2+
tree-sitter-typst := "tree-sitter-typst." + if os_family() == "windows" { "dll" } else { "so" }
23

34
# List available recipes
45
@list:
56
just --list
67

8+
# Download tree-sitter-typst from GitHub Actions
9+
setup:
10+
{{ \
11+
if path_exists(tree-sitter-typst) != "true" { \
12+
"gh run download --name " + tree-sitter-typst \
13+
} else { \
14+
"echo 'Found existing " + tree-sitter-typst + ".'" \
15+
} \
16+
}}
17+
718
# Scan code by rules, e.g., `just scan headcount`, `just scan tidy/0.3.0 --filter=eval`, `just scan physica/0.9.5 --hint=hard-coded-str --filter=hard-coded-str`
819
scan PREVIEW_PACKAGE_PATH *OPTIONS:
920
ast-grep scan {{ OPTIONS }} {{ typst_preview }}/{{ PREVIEW_PACKAGE_PATH }}

sgconfig.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ testConfigs:
44
- testDir: rules-tests
55
customLanguages:
66
typst:
7-
libraryPath: tree-sitter-typst.dll # or tree-sitter-typst.so
7+
libraryPath:
8+
x86_64-unknown-linux-gnu: tree-sitter-typst.so
9+
x86_64-pc-windows-msvc: tree-sitter-typst.dll
810
extensions: [typ]
911
expandoChar: μ

0 commit comments

Comments
 (0)