Skip to content

Commit

Permalink
chore(golang): further improve engine for go (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski authored Nov 6, 2023
1 parent 672abc5 commit 1ca1358
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/languages/golang/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (analyzer *analyzer) Analyze(node *sitter.Node, visitChildren func() error)
return analyzer.analyzeSwitch(node, visitChildren)
case "expression_case", "default_case":
return analyzer.analyzeGenericConstruct(node, visitChildren)
case "argument_list", "binary_expression", "expression_list":
case "qualified_type":
return analyzer.analyzeQualifiedType(node, visitChildren)
case "argument_list", "binary_expression", "expression_list", "unary_expression":
return analyzer.analyzeGenericOperation(node, visitChildren)
case "return_statement", "go_statement", "defer_statement", "if_statement": // statements don't have results
return visitChildren()
Expand All @@ -63,6 +65,13 @@ func (analyzer *analyzer) Analyze(node *sitter.Node, visitChildren func() error)
}
}

// big.Rat{}
func (analyzer *analyzer) analyzeQualifiedType(node *sitter.Node, visitChildren func() error) error {
analyzer.lookupVariable(node.ChildByFieldName("package"))

return visitChildren()
}

// for i, j := range x {}
func (analyzer *analyzer) analyzeRangeClause(node *sitter.Node, visitChildren func() error) error {
left := node.ChildByFieldName("left")
Expand Down Expand Up @@ -217,7 +226,7 @@ func (analyzer *analyzer) withScope(newScope *language.Scope, body func() error)
}

func (analyzer *analyzer) lookupVariable(node *sitter.Node) {
if node == nil || node.Type() != "identifier" {
if node == nil || !slices.Contains([]string{"identifier", "package_identifier"}, node.Type()) {
return
}

Expand Down
8 changes: 8 additions & 0 deletions internal/languages/golang/pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
ellipsisRegex = regexp.MustCompile(`\$<\.\.\.>`)
unanchoredPatternNodeTypes = []string{"import_spec"}
patternMatchNodeContainerTypes = []string{
"range_clause",
"parameter_declaration",
"argument_list",
"expression_list",
Expand Down Expand Up @@ -97,6 +98,13 @@ func (*Pattern) IsLeaf(node *tree.Node) bool {
return false
}

func (*Pattern) AnonymousParentTypes() []string {
return []string{
"unary_expression",
"binary_expression",
}
}

func (*Pattern) LeafContentTypes() []string {
return []string{
"identifier",
Expand Down

0 comments on commit 1ca1358

Please sign in to comment.