Skip to content

Commit

Permalink
refactor(cli): upgrade tree-sitter grammars (#7028)
Browse files Browse the repository at this point in the history
Close #530

### Changes are visible to end-users: no

### Test plan

- Covered by existing test cases

GitOrigin-RevId: 91c1f483e9b74b668ac7690d52e543bb039f09ac
  • Loading branch information
jbedard committed Oct 23, 2024
1 parent 39f5538 commit c5f1019
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
28 changes: 14 additions & 14 deletions gazelle/common/treesitter/grammars/grammars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def fetch_grammars():
http_archive(
name = "tree-sitter-json",
sha256 = "83d89d297c475dceb1865a9eacd8da1008e1aecffb6137161361107665cbdf79",
strip_prefix = "tree-sitter-json-0.21.0",
urls = ["https://github.com/tree-sitter/tree-sitter-json/archive/v0.21.0.tar.gz"],
sha256 = "ecde752640fb6eedd25b63647f016f92b3b63096d08f60742cbf19395c5c6036",
strip_prefix = "tree-sitter-json-0.23.0",
urls = ["https://github.com/tree-sitter/tree-sitter-json/archive/v0.23.0.tar.gz"],
build_file_content = """
filegroup(
name = "srcs",
Expand All @@ -21,9 +21,9 @@ filegroup(

http_archive(
name = "tree-sitter-kotlin",
sha256 = "f8d6f766ff2da1bd411e6d55f4394abbeab808163d5ea6df9daa75ad48eb0834",
strip_prefix = "tree-sitter-kotlin-0.3.5",
urls = ["https://github.com/fwcd/tree-sitter-kotlin/archive/0.3.5.tar.gz"],
sha256 = "7dd60975786bf9cb4be6a5176f5ccb5fed505f9929a012da30762505b1015669",
strip_prefix = "tree-sitter-kotlin-0.3.8",
urls = ["https://github.com/fwcd/tree-sitter-kotlin/archive/0.3.8.tar.gz"],
build_file_content = """
filegroup(
name = "srcs",
Expand All @@ -35,9 +35,9 @@ filegroup(

http_archive(
name = "tree-sitter-starlark",
integrity = "sha256-obJ54UOlqTfd1EInZNkV8ju0CFNh3gmULTvVdJ7uPKU=",
strip_prefix = "tree-sitter-starlark-1.0.0",
urls = ["https://github.com/tree-sitter-grammars/tree-sitter-starlark/archive/v1.0.0.tar.gz"],
integrity = "sha256-STb+4buXAstpVLGTDqwTPCzxzEDz3n1EpqPXdtI7IWw=",
strip_prefix = "tree-sitter-starlark-1.2.0",
urls = ["https://github.com/tree-sitter-grammars/tree-sitter-starlark/archive/v1.2.0.tar.gz"],
build_file_content = """
filegroup(
name = "srcs",
Expand All @@ -49,18 +49,18 @@ filegroup(

http_archive(
name = "tree-sitter-typescript",
sha256 = "fb95a7a78268b3c0aeca86cc376681f1f4f9a1ae97b9bd8167c633bfd41398c6",
strip_prefix = "tree-sitter-typescript-0.20.6",
urls = ["https://github.com/tree-sitter/tree-sitter-typescript/archive/v0.20.6.tar.gz"],
sha256 = "af500e16060b0221db8fb0743a37ca677340f8024127b54f6b6fc1ebfde496f4",
strip_prefix = "tree-sitter-typescript-0.23.0",
urls = ["https://github.com/tree-sitter/tree-sitter-typescript/archive/v0.23.0.tar.gz"],
build_file_content = """
filegroup(
name = "typescript-srcs",
srcs = glob(["**/*.c", "**/*.h"], exclude=["tsx/**"]),
srcs = glob(["common/**/*.h", "typescript/src/**/*.h", "typescript/src/**/*.c"]),
visibility = ["//visibility:public"],
)
filegroup(
name = "tsx-srcs",
srcs = glob(["**/*.c", "**/*.h"], exclude=["typescript/**"]),
srcs = glob(["common/**/*.h", "tsx/src/**/*.h", "tsx/src/**/*.c"]),
visibility = ["//visibility:public"],
)
""",
Expand Down
7 changes: 5 additions & 2 deletions gazelle/kotlin/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ func (p *treeSitterParser) Parse(filePath, source string) (*ParseResult, []error
nodeK := nodeJ.Child(k)
if nodeK.Type() == "identifier" {
isStar := false
for l := k + 1; l < int(nodeJ.ChildCount()); l++ {
if nodeJ.Child(l).Type() == ".*" {
for l := int(nodeJ.ChildCount()) - 1; l > k; l-- {
if nodeJ.Child(l).Type() == "wildcard_import" {
isStar = true
break
}
}

result.Imports = append(result.Imports, readIdentifier(nodeK, sourceCode, !isStar))

// Any remaining nodes within nodeJ are comments or wildcards
break
}
}
}
Expand Down

0 comments on commit c5f1019

Please sign in to comment.