stakwork / stak-bounties

0 stars 2 forks source link

tree sitter queries for Go #11

Open Evanfeenstra opened 1 week ago

Evanfeenstra commented 1 week ago

Here is some python code:

from something.log import logger
from dotenv import load_dotenv

class Thing():
    def __init__(self) -> None:
        self.hi = "hello"
    def method():
        val = a_function("hi")
        return val
    def another_method(self):
        self.method()

def a_function(arg: string):
    return "return value " + arg

And here are some treesitter queries. You can play with them at https://tree-sitter.github.io/tree-sitter/playground

# class_definition_query
(class_definition name: (identifier) @class-name) @class-definition
# function_definition_query
((function_definition name: (identifier) @function-name parameters: (parameters) @parameters) @function-definition)
# function_call_query
((call function: (identifier) @function-name) @function-call)
# function_attr_call_query
((call function: (attribute object: (identifier) attribute: (identifier) @function-name )) @function-call)

Write similar queries for Go:

type Thing struct {}

func (thing Thing) Init() {}

func (thing Thing) Method(arg string) {
    val := a_function(arg)
}

func (thing Thing) Method2(arg string) {
    thing.Method("hi")
}

func a_function(a: string) {
    return "return value " + a
}

Here's some docs about tree-sitter queries https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax

Ekep-Obasi commented 1 week ago

@Evanfeenstra, I'd love to work on this, could you please assign me?

Ekep-Obasi commented 1 week ago

Also, it seems like the links is broken https://tree-sitter.github.io/tree-sitter/playground