Skip to content

Commit 3aedb47

Browse files
committed
Migrate to gotreesitter parser
1 parent 44638bc commit 3aedb47

15 files changed

Lines changed: 401 additions & 278 deletions

File tree

.github/workflows/release.yaml

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,18 @@ jobs:
1717
with:
1818
go-version: 1.26.x
1919
- name: Run GoReleaser (dry run)
20-
env:
21-
PACKAGE_NAME: github.com/lets-cli/lets
22-
GOLANG_CROSS_VERSION: v1.26
23-
run: |
24-
docker run \
25-
--rm \
26-
-e CGO_ENABLED=1 \
27-
-v /var/run/docker.sock:/var/run/docker.sock \
28-
-v `pwd`:/go/src/${PACKAGE_NAME}\
29-
-v `pwd`/sysroot:/sysroot \
30-
-w /go/src/${PACKAGE_NAME} \
31-
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
32-
--clean --skip=validate --skip=publish
20+
uses: goreleaser/goreleaser-action@v7
21+
with:
22+
distribution: goreleaser
23+
version: '~> v2' # latest
24+
args: release --clean --skip=validate --skip=publish
3325
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v7
27+
with:
28+
distribution: goreleaser
29+
version: '~> v2' # latest
30+
args: release --clean
3431
env:
35-
PACKAGE_NAME: github.com/lets-cli/lets
36-
GOLANG_CROSS_VERSION: v1.26
37-
run: |
38-
docker run \
39-
--rm \
40-
-e CGO_ENABLED=1 \
41-
-e GITHUB_TOKEN="${{secrets.GITHUB_TOKEN}}" \
42-
-e HOMEBREW_TAP_GITHUB_TOKEN="${{secrets.GH_PAT}}" \
43-
-e AUR_GITHUB_TOKEN="${{secrets.AUR_SSH_PRIVATE_KEY}}" \
44-
-v /var/run/docker.sock:/var/run/docker.sock \
45-
-v `pwd`:/go/src/${PACKAGE_NAME}\
46-
-v `pwd`/sysroot:/sysroot \
47-
-w /go/src/${PACKAGE_NAME} \
48-
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
49-
release --clean
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
34+
AUR_GITHUB_TOKEN: ${{ secrets.AUR_SSH_PRIVATE_KEY }}

.goreleaser.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ builds:
1515
- darwin
1616
goarch:
1717
- amd64
18-
env:
19-
- PKG_CONFIG_SYSROOT_DIR=/sysroot/macos/amd64
20-
- PKG_CONFIG_PATH=/sysroot/macos/amd64/usr/local/lib/pkgconfig
21-
- CC=o64-clang
22-
- CXX=o64-clang++
2318
flags:
2419
- -mod=readonly
2520
ldflags:
@@ -30,11 +25,6 @@ builds:
3025
- darwin
3126
goarch:
3227
- arm64
33-
env:
34-
- PKG_CONFIG_SYSROOT_DIR=/sysroot/macos/arm64
35-
- PKG_CONFIG_PATH=/sysroot/macos/arm64/usr/local/lib/pkgconfig
36-
- CC=oa64-clang
37-
- CXX=oa64-clang++
3828
flags:
3929
- -mod=readonly
4030
ldflags:
@@ -45,9 +35,6 @@ builds:
4535
- linux
4636
goarch:
4737
- amd64
48-
env:
49-
- CC=x86_64-linux-gnu-gcc
50-
- CXX=x86_64-linux-gnu-g++
5138
flags:
5239
- -mod=readonly
5340
ldflags:

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
FROM golang:1.26-bookworm AS builder
22

33
ENV GOPROXY=https://proxy.golang.org
4-
ENV CGO_ENABLED=1
5-
# disable all compiler errors
6-
ENV CGO_CFLAGS=-w
74

85
WORKDIR /app
96

107
RUN apt-get update && apt-get install -y \
11-
git gcc \
8+
git \
129
zsh # for zsh completion tests
1310

1411
RUN cd /tmp && \

cmd/lets/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func main() {
126126
if errors.As(err, &depErr) {
127127
executor.PrintDependencyTree(depErr, os.Stderr)
128128
}
129+
129130
log.Errorf("lets: %s", err.Error())
130131
os.Exit(getExitCode(err, 1))
131132
}

docs/docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ title: Changelog
1212
* `[Removed]` Drop deprecated `eval_env` directive. Use `env` with `sh` execution mode instead.
1313
* `[Added]` When a command or its `depends` chain fails, print an indented tree to stderr showing the full chain with the failing command highlighted
1414
* `[Added]` Support `env_file` in global config and commands. File names are expanded after `env` is resolved, and values loaded from env files override values from `env`.
15+
* `[Changed]` Migrate the LSP YAML parser from the CGO-based tree-sitter bindings to pure-Go [`gotreesitter`](https://github.com/odvcencio/gotreesitter), removing the C toolchain requirement from normal builds and release packaging.
1516

1617
## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59)
1718

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ require (
99
github.com/coreos/go-semver v0.3.1
1010
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
1111
github.com/fatih/color v1.16.0
12+
github.com/odvcencio/gotreesitter v0.9.2
1213
github.com/pkg/errors v0.9.1
1314
github.com/sirupsen/logrus v1.9.3
1415
github.com/spf13/cobra v1.8.0
1516
github.com/tliron/commonlog v0.2.8
1617
github.com/tliron/glsp v0.2.2
17-
github.com/tree-sitter-grammars/tree-sitter-yaml v0.7.0
18-
github.com/tree-sitter/go-tree-sitter v0.24.0
1918
golang.org/x/sync v0.3.0
2019
)
2120

@@ -26,7 +25,6 @@ require (
2625
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
2726
github.com/mattn/go-colorable v0.1.13 // indirect
2827
github.com/mattn/go-isatty v0.0.20 // indirect
29-
github.com/mattn/go-pointer v0.0.1 // indirect
3028
github.com/mattn/go-runewidth v0.0.14 // indirect
3129
github.com/muesli/termenv v0.15.2 // indirect
3230
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect

go.sum

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBq
7272
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
7373
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
7474
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
75-
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
76-
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
7775
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
7876
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
7977
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
8078
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
8179
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
8280
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
8381
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
82+
github.com/odvcencio/gotreesitter v0.9.2 h1:ZROpRS+bTcC1mwofBp53l66Jv00FH0ccViSwGVmaBBM=
83+
github.com/odvcencio/gotreesitter v0.9.2/go.mod h1:Sx+iYJBfw5xSWkSttLSuFvguJctlH+ma1BTxZ0MPCqo=
8484
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
8585
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
8686
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -101,43 +101,14 @@ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyh
101101
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
102102
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
103103
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
104+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
104105
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
105-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
106-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
107106
github.com/tliron/commonlog v0.2.8 h1:vpKrEsZX4nlneC9673pXpeKqv3cFLxwpzNEZF1qiaQQ=
108107
github.com/tliron/commonlog v0.2.8/go.mod h1:HgQZrJEuiKLLRvUixtPWGcmTmWWtKkCtywF6x9X5Spw=
109108
github.com/tliron/glsp v0.2.2 h1:IKPfwpE8Lu8yB6Dayta+IyRMAbTVunudeauEgjXBt+c=
110109
github.com/tliron/glsp v0.2.2/go.mod h1:GMVWDNeODxHzmDPvYbYTCs7yHVaEATfYtXiYJ9w1nBg=
111110
github.com/tliron/kutil v0.3.11 h1:kongR0dhrrn9FR/3QRFoUfQe27t78/xQvrU9aXIy5bk=
112111
github.com/tliron/kutil v0.3.11/go.mod h1:4IqOAAdpJuDxYbJxMv4nL8LSH0mPofSrdwIv8u99PDc=
113-
github.com/tree-sitter-grammars/tree-sitter-yaml v0.7.0 h1:bfSjXf9nNPbZH09as6k9+/fbMPyQEHD9IJXzGMdQc0o=
114-
github.com/tree-sitter-grammars/tree-sitter-yaml v0.7.0/go.mod h1:ioP5ekY1SBtpcsagA3mQ4GNUBunkPhtVgqplC5Nffc8=
115-
github.com/tree-sitter/go-tree-sitter v0.24.0 h1:kRZb6aBNfcI/u0Qh8XEt3zjNVnmxTisDBN+kXK0xRYQ=
116-
github.com/tree-sitter/go-tree-sitter v0.24.0/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk=
117-
github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb h1:A8425heRM8mylnv4H58FPUiH+aYivyitre0PzxrfmWs=
118-
github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb/go.mod h1:dOF6gtQiF9UwNh995T5OphYmtIypkjsp3ap7r9AN/iA=
119-
github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148 h1:AfFPZwtwGN01BW1jDdqBVqscTwetvMpydqYZz57RSlc=
120-
github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148/go.mod h1:Bh6U3viD57rFXRYIQ+kmiYtr+1Bx0AceypDLJJSyi9s=
121-
github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33 h1:TwqSV3qLp3tKSqirGLRHnjFk9Tc2oy57LIl+FQ4GjI4=
122-
github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33/go.mod h1:CvCKCt3v04Ufos1zZnNCelBDeCGRpPucaN8QczoUsN4=
123-
github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012 h1:Xvxck3tE5FW7F7bTS97iNM2ADMyCMJztVqn5HYKdJGo=
124-
github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012/go.mod h1:T40D0O1cPvUU/+AmiXVXy1cncYQT6wem4Z0g4SfAYvY=
125-
github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0 h1:c46K6uh5Dz00zJeU9BfjXdb8I+E4RkUdfnWJpQADXFo=
126-
github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0/go.mod h1:hcNt/kOJHcIcuMvouE7LJcYdeFUFbVpBJ6d4wmOA+tU=
127-
github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495 h1:jrt4qbJVEFs4H93/ITxygHc6u0TGqAkkate7TQ4wFSA=
128-
github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495/go.mod h1:oyaR7fLnRV0hT9z6qwE9GkaeTom/hTDwK3H2idcOJFc=
129-
github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5 h1:om4X9AVg3asL8gxNJDcz4e/Wp+VpQj1PY3uJXKr6EOg=
130-
github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5/go.mod h1:nNqgPoV/h9uYWk6kYEFdEAhNVOacpfpRW5SFmdaP4tU=
131-
github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5 h1:pfV3G3k7NCKqKk8THBmyuh2zA33lgYHS3GVrzRR8ry4=
132-
github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5/go.mod h1:GbMKRjLfk0H+PI7nLi1Sx5lHf5wCpLz9al8tQYSxpEk=
133-
github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1 h1:ZXZMDwE+IhUtGug4Brv6NjJWUU3rfkZBKpemf6RY8/g=
134-
github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1/go.mod h1:UKCLuYnJ312Mei+3cyTmGOHzn0YAnaPRECgJmHtzrqs=
135-
github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb h1:EXEM82lFM7JjJb6qiKZXkpIDaCcbV2obNn82ghwj9lw=
136-
github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb/go.mod h1:lXCF1nGG5Dr4J3BTS0ObN4xJCCICiSu/b+Xe/VqMV7g=
137-
github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d h1:fcYCvoXdcP1uRQYXqJHRy6Hec+uKScQdKVtMwK9JeCI=
138-
github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d/go.mod h1:T1nShQ4v5AJtozZ8YyAS4uzUtDAJj/iv4YfwXSbUHzg=
139-
github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447 h1:o9alBu1J/WjrcTKEthYtXmdkDc5OVXD+PqlvnEZ0Lzc=
140-
github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447/go.mod h1:1Oh95COkkTn6Ezp0vcMbvfhRP5gLeqqljR0BYnBzWvc=
141112
golang.org/x/crypto v0.0.0-20180214000028-650f4a345ab4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
142113
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
143114
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

internal/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func PrintRootHelpMessage(cmd *cobra.Command) error {
228228

229229
// General
230230
builder.WriteString("Usage:\n")
231+
231232
if cmd.Runnable() {
232233
fmt.Fprintf(&builder, " %s\n", cmd.UseLine())
233234
}

internal/config/config/command.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"maps"
89
"path/filepath"
910
"strings"
1011

@@ -92,6 +93,7 @@ func (c *Command) UnmarshalYAML(unmarshal func(any) error) error {
9293
if c.Env == nil {
9394
c.Env = &Envs{}
9495
}
96+
9597
c.EnvFiles = cmd.EnvFiles
9698
if c.EnvFiles == nil {
9799
c.EnvFiles = &EnvFiles{}
@@ -145,30 +147,26 @@ func (c *Command) GetEnv(cfg Config, builtinEnv map[string]string) (map[string]s
145147
if baseEnv == nil {
146148
baseEnv = make(map[string]string)
147149
}
148-
for key, value := range cfg.GetEnv() {
149-
baseEnv[key] = value
150-
}
150+
151+
maps.Copy(baseEnv, cfg.GetEnv())
151152

152153
envs := c.Env.Clone()
153154
if err := envs.Execute(cfg, baseEnv); err != nil {
154155
return nil, err
155156
}
156157

157158
filenameEnv := cloneMap(baseEnv)
158-
for key, value := range envs.Dump() {
159-
filenameEnv[key] = value
160-
}
159+
maps.Copy(filenameEnv, envs.Dump())
161160

162161
envFiles := c.EnvFiles.Clone()
162+
163163
envFileEnv, err := envFiles.Load(cfg, filenameEnv)
164164
if err != nil {
165165
return nil, fmt.Errorf("lets: failed to resolve env_file for command '%s': %w", c.Name, err)
166166
}
167167

168168
resolvedEnv := envs.Dump()
169-
for key, value := range envFileEnv {
170-
resolvedEnv[key] = value
171-
}
169+
maps.Copy(resolvedEnv, envFileEnv)
172170

173171
return resolvedEnv, nil
174172
}

internal/config/config/config.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"maps"
78
"os"
89
"path/filepath"
910
"strings"
@@ -100,6 +101,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(any) error) error {
100101
if c.Env == nil {
101102
c.Env = &Envs{}
102103
}
104+
103105
c.EnvFiles = config.EnvFiles
104106
if c.EnvFiles == nil {
105107
c.EnvFiles = &EnvFiles{}
@@ -314,19 +316,15 @@ func (c *Config) SetupEnv() error {
314316
}
315317

316318
filenameEnv := c.BuiltinEnv(c.Shell)
317-
for key, value := range c.Env.Dump() {
318-
filenameEnv[key] = value
319-
}
319+
maps.Copy(filenameEnv, c.Env.Dump())
320320

321321
envFileEnv, err := c.EnvFiles.Load(*c, filenameEnv)
322322
if err != nil {
323323
return fmt.Errorf("failed to resolve global env_file: %w", err)
324324
}
325325

326326
c.cachedEnv = c.Env.Dump()
327-
for key, value := range envFileEnv {
328-
c.cachedEnv[key] = value
329-
}
327+
maps.Copy(c.cachedEnv, envFileEnv)
330328

331329
// expand env for args
332330
for _, cmd := range c.Commands {

0 commit comments

Comments
 (0)