build: Bump go-tree-sitter version and fix Squirrel queries (#59847)

Changes needed due to Tree-sitter grammar updates (implicitly updated
when updating the smacker/go-tree-sitter bindings since it bundles the
grammars)

- Previously, the Java grammar lumped all comments under the 'comment'
  marker, but it changed the queries to use 'line_comment' and
  'block_comment', which broke one of the tests for locating hovers.
- We need to extract the identifier out of an as_pattern,
  because the way the grammar is written, the 'as' in the
  exception clause is no longer treated as a separate anonymous
  keyword but as an 'as' expression.
This commit is contained in:
Varun Gandhi 2024-01-25 06:15:30 -06:00 committed by GitHub
parent de90f491b6
commit 7f705ecb2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 12 deletions

View File

@ -84,14 +84,24 @@ func (s *SquirrelService) getDefPython(ctx context.Context, node Node) (ret *Nod
continue
case "except_clause":
if cur.NamedChildCount() < 3 {
if cur.NamedChildCount() < 1 {
continue
}
// (except_clause
// (as_pattern (identifier) alias: (as_pattern_target (identifier) @definition)))
// vvvvvvvvv identifier
// v identifier
// v block
// except Exception as e:
exceptIdent := cur.NamedChild(1)
asPattern := cur.NamedChild(0)
if asPattern == nil || asPattern.Type() != "as_pattern" {
continue
}
asPatternTarget := asPattern.ChildByFieldName("alias")
if asPatternTarget == nil || asPatternTarget.Type() != "as_pattern_target" {
continue
}
exceptIdent := asPatternTarget.Child(0)
if exceptIdent == nil || exceptIdent.Type() != "identifier" {
continue
}
@ -260,9 +270,6 @@ func (s *SquirrelService) findNodeInScopePython(block Node, ident string) (ret *
exceptChild := tryChild.NamedChild(k)
if exceptChild.Type() == "block" {
next := exceptChild
if next == nil {
return nil
}
found := s.findNodeInScopePython(swapNode(block, next), ident)
if found != nil {
return found

View File

@ -73,7 +73,7 @@ var langToLangSpec = map[string]LangSpec{
name: "java",
language: java.GetLanguage(),
commentStyle: CommentStyle{
nodeTypes: []string{"comment"},
nodeTypes: []string{"line_comment", "block_comment"},
stripRegex: javaStyleStripRegex,
ignoreRegex: javaStyleIgnoreRegex,
codeFenceName: "java",
@ -302,7 +302,8 @@ var pythonLocalsQuery = `
(typed_parameter (identifier) @definition) ; def f(x: bool): ...
(default_parameter name: (identifier) @definition) ; def f(x = False): ...
(typed_default_parameter name: (identifier) @definition) ; def f(x: bool = False): ...
(except_clause (identifier) (identifier) @definition) ; except Exception as e: ...
(except_clause
(as_pattern (identifier) alias: (as_pattern_target (identifier) @definition))) ; except Exception as e: ...
(expression_statement (assignment left: (identifier) @definition)) ; x = ...
(expression_statement (assignment left: (pattern_list (identifier) @definition))) ; x, y = ...
(for_statement left: (identifier) @definition) ; for x in ...: ...

View File

@ -125,6 +125,17 @@ namespace Foo {
}
}
}
`}, {
path: "exception.py",
contents: `
def f():
try:
pass
# v f.e def
# v f.e ref
except Exception as e:
# v f.e ref
print(e)
`}, {
path: "test.py",
contents: `

View File

@ -5569,8 +5569,8 @@ def go_dependencies():
name = "com_github_smacker_go_tree_sitter",
build_file_proto_mode = "disable_global",
importpath = "github.com/smacker/go-tree-sitter",
sum = "h1:WrsSqod9T70HFyq8hjL6wambOKb4ISUXzFUuNTJHDwo=",
version = "v0.0.0-20220209044044-0d3022e933c3",
sum = "h1:PeBjmUlvTGvg6SyM4u7pyk8YCmdbgdFcGrwf7dRBV80=",
version = "v0.0.0-20231219031718-233c2f923ac7",
)
go_repository(
name = "com_github_smartystreets_assertions",

2
go.mod
View File

@ -168,7 +168,7 @@ require (
github.com/sergi/go-diff v1.3.1
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
github.com/slack-go/slack v0.10.1
github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3
github.com/smacker/go-tree-sitter v0.0.0-20231219031718-233c2f923ac7
github.com/sourcegraph/go-ctags v0.0.0-20231024141911-299d0263dc95
github.com/sourcegraph/go-diff v0.6.2-0.20221123165719-f8cd299c40f3
github.com/sourcegraph/go-jsonschema v0.0.0-20221230021921-34aaf28fc4ac

5
go.sum
View File

@ -1617,8 +1617,8 @@ github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/slack-go/slack v0.10.1 h1:BGbxa0kMsGEvLOEoZmYs8T1wWfoZXwmQFBb6FgYCXUA=
github.com/slack-go/slack v0.10.1/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ=
github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3 h1:WrsSqod9T70HFyq8hjL6wambOKb4ISUXzFUuNTJHDwo=
github.com/smacker/go-tree-sitter v0.0.0-20220209044044-0d3022e933c3/go.mod h1:EiUuVMUfLQj8Sul+S8aKWJwQy7FRYnJCO2EWzf8F5hk=
github.com/smacker/go-tree-sitter v0.0.0-20231219031718-233c2f923ac7 h1:PeBjmUlvTGvg6SyM4u7pyk8YCmdbgdFcGrwf7dRBV80=
github.com/smacker/go-tree-sitter v0.0.0-20231219031718-233c2f923ac7/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.13.0 h1:Dx1kYM01xsSqKPno3aqLnrwac2LetPvN23diwyr69Qs=
github.com/smartystreets/assertions v1.13.0/go.mod h1:wDmR7qL282YbGsPy6H/yAsesrxfxaaSlJazyFLYVFx8=
@ -1713,6 +1713,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=