Skip to content

Commit b8452c1

Browse files
committed
chore: unfork go-tree-sitter
This would break other extensions. See bazel-contrib/rules_python#2952
1 parent 2b9476f commit b8452c1

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ bazel_dep(name = "rules_go", version = "0.55.1")
55
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0")
66
bazel_dep(name = "rules_python_gazelle_plugin", version = "1.4.1")
77

8+
single_version_override(
9+
module_name = "rules_python_gazelle_plugin",
10+
version = "1.4.1",
11+
patch_strip = 2,
12+
patches = ["patches/rules_python.patch"],
13+
)
814
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
915

1016
# Download an SDK for the host OS & architecture as well as common remote execution

patches/rules_python.patch

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel
2+
index 6bbc74bc..726e4a6b 100644
3+
--- a/gazelle/MODULE.bazel
4+
+++ b/gazelle/MODULE.bazel
5+
@@ -21,7 +21,7 @@ use_repo(
6+
go_deps,
7+
"com_github_bazelbuild_buildtools",
8+
"com_github_bmatcuk_doublestar_v4",
9+
- "com_github_dougthor42_go_tree_sitter",
10+
+ "com_github_smacker_go_tree_sitter",
11+
"com_github_emirpasic_gods",
12+
"com_github_ghodss_yaml",
13+
"com_github_stretchr_testify",
14+
diff --git a/gazelle/deps.bzl b/gazelle/deps.bzl
15+
index 7253ef81..5ad3559c 100644
16+
--- a/gazelle/deps.bzl
17+
+++ b/gazelle/deps.bzl
18+
@@ -183,10 +183,10 @@ def go_deps():
19+
version = "v0.0.0-20190812154241-14fe0d1b01d4",
20+
)
21+
go_repository(
22+
- name = "com_github_dougthor42_go_tree_sitter",
23+
- importpath = "github.com/dougthor42/go-tree-sitter",
24+
- sum = "h1:b9s96BulIARx0konX36sJ5oZhWvAvjQBBntxp1eUukQ=",
25+
- version = "v0.0.0-20241210060307-2737e1d0de6b",
26+
+ name = "com_github_smacker_go_tree_sitter",
27+
+ importpath = "github.com/smacker/go-tree-sitter",
28+
+ sum = "h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=",
29+
+ version = "v0.0.0-20240827094217-dd81d9e9be82",
30+
)
31+
go_repository(
32+
name = "com_github_stretchr_objx",
33+
diff --git a/gazelle/go.mod b/gazelle/go.mod
34+
index 91d27fdd..6f65ffbc 100644
35+
--- a/gazelle/go.mod
36+
+++ b/gazelle/go.mod
37+
@@ -7,9 +7,9 @@ require (
38+
github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82
39+
github.com/bazelbuild/rules_go v0.41.0
40+
github.com/bmatcuk/doublestar/v4 v4.7.1
41+
- github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b
42+
github.com/emirpasic/gods v1.18.1
43+
github.com/ghodss/yaml v1.0.0
44+
+ github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
45+
github.com/stretchr/testify v1.9.0
46+
golang.org/x/sync v0.2.0
47+
gopkg.in/yaml.v2 v2.4.0
48+
diff --git a/gazelle/go.sum b/gazelle/go.sum
49+
index 5acd4a6d..0aaa1866 100644
50+
--- a/gazelle/go.sum
51+
+++ b/gazelle/go.sum
52+
@@ -6,8 +6,6 @@ github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82 h1:HTepWP/jh
53+
github.com/bazelbuild/buildtools v0.0.0-20231103205921-433ea8554e82/go.mod h1:689QdV3hBP7Vo9dJMmzhoYIyo/9iMhEmHkJcnaPRCbo=
54+
github.com/bazelbuild/rules_go v0.41.0 h1:JzlRxsFNhlX+g4drDRPhIaU5H5LnI978wdMJ0vK4I+k=
55+
github.com/bazelbuild/rules_go v0.41.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
56+
-github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
57+
-github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
58+
github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q=
59+
github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
60+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
61+
@@ -17,8 +15,6 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
62+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
63+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
64+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
65+
-github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b h1:b9s96BulIARx0konX36sJ5oZhWvAvjQBBntxp1eUukQ=
66+
-github.com/dougthor42/go-tree-sitter v0.0.0-20241210060307-2737e1d0de6b/go.mod h1:87UkDyPt18bTH/FvinLc/kj587VNYOdRKZT1la4T8Hg=
67+
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
68+
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
69+
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
70+
@@ -47,6 +43,8 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
71+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
72+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
73+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
74+
+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=
75+
+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=
76+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
77+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
78+
go.starlark.net v0.0.0-20210223155950-e043a3d3c984/go.mod h1:t3mmBBPzAVvK0L0n1drDmrQsJ8FoIx4INCqVMTr/Zo0=
79+
diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel
80+
index eb2d72e5..3092546c 100644
81+
--- a/gazelle/python/BUILD.bazel
82+
+++ b/gazelle/python/BUILD.bazel
83+
@@ -37,13 +37,13 @@ go_library(
84+
"@bazel_gazelle//repo:go_default_library",
85+
"@bazel_gazelle//resolve:go_default_library",
86+
"@bazel_gazelle//rule:go_default_library",
87+
- "@com_github_bazelbuild_buildtools//build:go_default_library",
88+
+ "@com_github_bazelbuild_buildtools//build",
89+
"@com_github_bmatcuk_doublestar_v4//:doublestar",
90+
- "@com_github_dougthor42_go_tree_sitter//:go-tree-sitter",
91+
- "@com_github_dougthor42_go_tree_sitter//python",
92+
"@com_github_emirpasic_gods//lists/singlylinkedlist",
93+
"@com_github_emirpasic_gods//sets/treeset",
94+
"@com_github_emirpasic_gods//utils",
95+
+ "@com_github_smacker_go_tree_sitter//:go-tree-sitter",
96+
+ "@com_github_smacker_go_tree_sitter//python",
97+
"@org_golang_x_sync//errgroup",
98+
],
99+
)
100+
diff --git a/gazelle/python/file_parser.go b/gazelle/python/file_parser.go
101+
index c147984f..a1f47f40 100644
102+
--- a/gazelle/python/file_parser.go
103+
+++ b/gazelle/python/file_parser.go
104+
@@ -22,8 +22,8 @@ import (
105+
"path/filepath"
106+
"strings"
107+
108+
- sitter "github.com/dougthor42/go-tree-sitter"
109+
- "github.com/dougthor42/go-tree-sitter/python"
110+
+ sitter "github.com/smacker/go-tree-sitter"
111+
+ "github.com/smacker/go-tree-sitter/python"
112+
)
113+
114+
const (
115+
@@ -115,10 +115,10 @@ func (p *FileParser) parseMain(ctx context.Context, node *sitter.Node) bool {
116+
a, b = b, a
117+
}
118+
if a.Type() == sitterNodeTypeIdentifier && a.Content(p.code) == "__name__" &&
119+
- // at github.com/dougthor42/go-tree-sitter@latest (after v0.0.0-20240422154435-0628b34cbf9c we used)
120+
+ // at github.com/smacker/go-tree-sitter@latest (after v0.0.0-20240422154435-0628b34cbf9c we used)
121+
// "__main__" is the second child of b. But now, it isn't.
122+
// we cannot use the latest go-tree-sitter because of the top level reference in scanner.c.
123+
- // https://github.com/dougthor42/go-tree-sitter/blob/04d6b33fe138a98075210f5b770482ded024dc0f/python/scanner.c#L1
124+
+ // https://github.com/smacker/go-tree-sitter/blob/04d6b33fe138a98075210f5b770482ded024dc0f/python/scanner.c#L1
125+
b.Type() == sitterNodeTypeString && string(p.code[b.StartByte()+1:b.EndByte()-1]) == "__main__" {
126+
return true
127+
}

0 commit comments

Comments
 (0)