Skip to content

Commit 1a7b9f0

Browse files
committed
merge tree-sitter-lf into lf.nvim monorepo
Move tree-sitter grammar, parser source, and queries into tree-sitter-lf/ directory. Update CI to build from local sources instead of checking out the standalone repo. Remove version tracking via ts-version.txt (use git SHA in release title instead).
1 parent 2bdd0ae commit 1a7b9f0

16 files changed

Lines changed: 46613 additions & 88 deletions

File tree

.github/workflows/build-lsp.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ jobs:
9696
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9797
LSP_VERSION: ${{ needs.check.outputs.version }}
9898
run: |
99-
# Read tree-sitter version if available
100-
gh release download artifacts --repo "${{ github.repository }}" \
101-
--pattern "ts-version.txt" --dir /tmp --clobber 2>/dev/null || true
102-
ts_ver=$(cat /tmp/ts-version.txt 2>/dev/null || true)
99+
# Preserve existing title prefix (Tree-sitter part) if present
100+
current=$(gh release view artifacts --repo "${{ github.repository }}" --json name --jq '.name')
101+
ts_part=$(echo "$current" | sed -n 's/.*\(Tree-sitter.*\)/\1/p')
103102
104103
title="LSP ${LSP_VERSION}"
105-
if [ -n "$ts_ver" ]; then
106-
title="${title} · Tree-sitter ${ts_ver}"
104+
if [ -n "$ts_part" ]; then
105+
title="${title} · ${ts_part}"
107106
fi
108107
109108
gh release edit artifacts --repo "${{ github.repository }}" --title "$title"

.github/workflows/build-treesitter.yml

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,42 @@
11
name: Build Tree-sitter Parser
22

33
on:
4-
schedule:
5-
- cron: "0 0 * * 1" # Weekly on Monday
4+
push:
5+
branches: [main]
6+
paths:
7+
- "tree-sitter-lf/src/**"
8+
- "tree-sitter-lf/grammar.js"
9+
- "tree-sitter-lf/queries/**"
610
workflow_dispatch:
7-
inputs:
8-
ts_version:
9-
description: "tree-sitter-lf release tag (e.g. v0.0.1). Leave empty to auto-detect latest."
10-
required: false
11-
type: string
1211

1312
jobs:
14-
check:
15-
runs-on: ubuntu-latest
16-
outputs:
17-
version: ${{ steps.resolve.outputs.version }}
18-
should_build: ${{ steps.resolve.outputs.should_build }}
19-
steps:
20-
- name: Resolve version to build
21-
id: resolve
22-
env:
23-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24-
run: |
25-
if [ -n "${{ inputs.ts_version }}" ]; then
26-
version="${{ inputs.ts_version }}"
27-
else
28-
version=$(gh api repos/remifan/tree-sitter-lf/releases \
29-
--jq '[.[] | select(.prerelease == false)][0].tag_name')
30-
fi
31-
32-
echo "version=$version" >> "$GITHUB_OUTPUT"
33-
34-
# Check if this version's parsers already exist by reading ts-version.txt
35-
current=$(gh release view artifacts --repo "${{ github.repository }}" --json assets \
36-
--jq '.assets[] | select(.name == "ts-version.txt") | .name' 2>/dev/null || true)
37-
38-
if [ -n "$current" ]; then
39-
# Download and compare
40-
gh release download artifacts --repo "${{ github.repository }}" \
41-
--pattern "ts-version.txt" --dir /tmp --clobber 2>/dev/null || true
42-
existing=$(cat /tmp/ts-version.txt 2>/dev/null || true)
43-
if [ "$existing" = "$version" ]; then
44-
echo "Tree-sitter $version already built, skipping."
45-
echo "should_build=false" >> "$GITHUB_OUTPUT"
46-
else
47-
echo "Tree-sitter version changed ($existing -> $version), will build."
48-
echo "should_build=true" >> "$GITHUB_OUTPUT"
49-
fi
50-
else
51-
echo "No existing tree-sitter build, will build."
52-
echo "should_build=true" >> "$GITHUB_OUTPUT"
53-
fi
54-
5513
build:
56-
needs: check
57-
if: needs.check.outputs.should_build == 'true'
5814
strategy:
5915
matrix:
6016
include:
6117
- os: ubuntu-latest
6218
artifact: treesitter-linux-x64.so
63-
compile: cc -shared -o treesitter-linux-x64.so -fPIC -O2 -I./src src/parser.c src/scanner.c
19+
compile: cc -shared -o treesitter-linux-x64.so -fPIC -O2 -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
6420
- os: ubuntu-24.04-arm
6521
artifact: treesitter-linux-arm64.so
66-
compile: cc -shared -o treesitter-linux-arm64.so -fPIC -O2 -I./src src/parser.c src/scanner.c
22+
compile: cc -shared -o treesitter-linux-arm64.so -fPIC -O2 -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
6723
- os: macos-latest
6824
artifact: treesitter-darwin-x64.so
69-
compile: cc -shared -o treesitter-darwin-x64.so -fPIC -O2 -target x86_64-apple-macos11 -I./src src/parser.c src/scanner.c
25+
compile: cc -shared -o treesitter-darwin-x64.so -fPIC -O2 -target x86_64-apple-macos11 -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
7026
- os: macos-latest
7127
artifact: treesitter-darwin-arm64.so
72-
compile: cc -shared -o treesitter-darwin-arm64.so -fPIC -O2 -I./src src/parser.c src/scanner.c
28+
compile: cc -shared -o treesitter-darwin-arm64.so -fPIC -O2 -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
7329
- os: windows-latest
7430
artifact: treesitter-win-x64.dll
75-
compile: gcc -shared -o treesitter-win-x64.dll -O2 -I./src src/parser.c src/scanner.c
31+
compile: gcc -shared -o treesitter-win-x64.dll -O2 -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
7632
- os: windows-latest
7733
artifact: treesitter-win-arm64.dll
7834
setup: choco install llvm --params "'/InstallAllUsers'" -y
79-
compile: clang -shared -o treesitter-win-arm64.dll -O2 --target=aarch64-pc-windows-msvc -I./src src/parser.c src/scanner.c
35+
compile: clang -shared -o treesitter-win-arm64.dll -O2 --target=aarch64-pc-windows-msvc -I./tree-sitter-lf/src tree-sitter-lf/src/parser.c tree-sitter-lf/src/scanner.c
8036
runs-on: ${{ matrix.os }}
8137
steps:
82-
- name: Checkout tree-sitter-lf
38+
- name: Checkout
8339
uses: actions/checkout@v4
84-
with:
85-
repository: remifan/tree-sitter-lf
86-
ref: ${{ needs.check.outputs.version }}
8740

8841
- name: Setup toolchain
8942
if: matrix.setup
@@ -99,20 +52,14 @@ jobs:
9952
path: ${{ matrix.artifact }}
10053

10154
release:
102-
needs: [check, build]
55+
needs: build
10356
runs-on: ubuntu-latest
10457
steps:
105-
- name: Checkout tree-sitter-lf (for queries)
58+
- name: Checkout
10659
uses: actions/checkout@v4
107-
with:
108-
repository: remifan/tree-sitter-lf
109-
ref: ${{ needs.check.outputs.version }}
11060

11161
- name: Package queries
112-
run: cd queries && zip -r ../queries.zip .
113-
114-
- name: Write version marker
115-
run: echo "${{ needs.check.outputs.version }}" > ts-version.txt
62+
run: cd tree-sitter-lf/queries && zip -r ../../queries.zip .
11663

11764
- name: Download all build artifacts
11865
uses: actions/download-artifact@v4
@@ -127,33 +74,27 @@ jobs:
12774
gh release view artifacts --repo "${{ github.repository }}" > /dev/null 2>&1 || \
12875
gh release create artifacts --repo "${{ github.repository }}" \
12976
--title "Pre-built artifacts" \
130-
--notes "Pre-built LSP server and tree-sitter parser for lf.nvim.
131-
132-
Install in Neovim:
133-
\`\`\`vim
134-
:LFLspInstall
135-
:LFTSInstall
136-
\`\`\`"
77+
--notes "Pre-built LSP server and tree-sitter parser for lf.nvim."
13778
13879
- name: Upload to artifacts release
13980
env:
14081
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14182
run: |
14283
gh release upload artifacts \
143-
artifacts/* queries.zip ts-version.txt \
84+
artifacts/* queries.zip \
14485
--repo "${{ github.repository }}" --clobber
14586
14687
- name: Update release title
14788
env:
14889
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149-
TS_VERSION: ${{ needs.check.outputs.version }}
15090
run: |
151-
# Read LSP version from existing jar asset name
91+
ts_sha=$(git log -1 --format=%h -- tree-sitter-lf/)
92+
15293
lsp_ver=$(gh release view artifacts --repo "${{ github.repository }}" --json assets \
15394
--jq '[.assets[].name | select(startswith("lsp-"))][0] // ""' \
15495
| sed -n 's/^lsp-\(.*\)-all\.jar$/v\1/p')
15596
156-
title="Tree-sitter ${TS_VERSION}"
97+
title="Tree-sitter (${ts_sha})"
15798
if [ -n "$lsp_ver" ]; then
15899
title="LSP ${lsp_ver} · ${title}"
159100
fi

lua/lf/treesitter.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ local function find_source_path()
142142
local plugin_dir = vim.fn.fnamemodify(plugin_path, ":h:h:h:h")
143143

144144
local possible_paths = {
145+
plugin_dir .. "/tree-sitter-lf", -- bundled in lf.nvim
145146
vim.fn.fnamemodify(plugin_dir, ":h") .. "/tree-sitter-lf",
146-
plugin_dir .. "/tree-sitter-lf",
147-
vim.fn.expand("~/Workspace/lf.nvim/tree-sitter-lf"),
148147
vim.fn.getenv("LF_TREESITTER_PATH"),
149148
}
150149

tree-sitter-lf/Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
VERSION := 0.0.1
2+
3+
LANGUAGE_NAME := tree-sitter-lf
4+
5+
# repository
6+
SRC_DIR := src
7+
8+
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
9+
10+
ifeq ($(PARSER_URL),)
11+
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
12+
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
13+
PARSER_URL := $(subst :,/,$(PARSER_URL))
14+
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
15+
endif
16+
endif
17+
18+
TS ?= tree-sitter
19+
20+
# ABI versioning
21+
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
22+
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
23+
24+
# install directory layout
25+
PREFIX ?= /usr/local
26+
INCLUDEDIR ?= $(PREFIX)/include
27+
LIBDIR ?= $(PREFIX)/lib
28+
PCLIBDIR ?= $(LIBDIR)/pkgconfig
29+
30+
# source/object files
31+
PARSER := $(SRC_DIR)/parser.c
32+
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c))
33+
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS))
34+
35+
# flags
36+
ARFLAGS ?= rcs
37+
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
38+
39+
# OS-specific bits
40+
ifeq ($(OS),Windows_NT)
41+
$(error "Windows is not supported")
42+
else ifeq ($(shell uname),Darwin)
43+
SOEXT = dylib
44+
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
45+
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
46+
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
47+
ifneq ($(ADDITIONAL_LIBS),)
48+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
49+
endif
50+
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
51+
else
52+
SOEXT = so
53+
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
54+
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
55+
LINKSHARED := $(LINKSHARED)-shared -Wl,
56+
ifneq ($(ADDITIONAL_LIBS),)
57+
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
58+
endif
59+
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
60+
endif
61+
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
62+
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
63+
endif
64+
65+
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
66+
67+
lib$(LANGUAGE_NAME).a: $(OBJS)
68+
$(AR) $(ARFLAGS) $@ $^
69+
70+
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
71+
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
72+
ifneq ($(STRIP),)
73+
$(STRIP) $@
74+
endif
75+
76+
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
77+
sed -e 's|@URL@|$(PARSER_URL)|' \
78+
-e 's|@VERSION@|$(VERSION)|' \
79+
-e 's|@LIBDIR@|$(LIBDIR)|' \
80+
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
81+
-e 's|@REQUIRES@|$(REQUIRES)|' \
82+
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
83+
-e 's|=$(PREFIX)|=$${prefix}|' \
84+
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
85+
86+
$(PARSER): $(SRC_DIR)/grammar.json
87+
$(TS) generate --no-bindings $^
88+
89+
install: all
90+
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
91+
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
92+
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
93+
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
94+
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
95+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
96+
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
97+
98+
uninstall:
99+
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
100+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
101+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
102+
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
103+
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
104+
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
105+
106+
clean:
107+
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
108+
109+
test:
110+
$(TS) test
111+
112+
.PHONY: all install uninstall clean test

0 commit comments

Comments
 (0)