You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
The example in the docs provides a code snippet to extract the imports from the file. However marshalling nodes into JSON is not a good use case, and I am trying to find a way to get the name of the import without intermediate marhsaling.
python := "import foo"
res, _, err := client.NewParseRequest().Context(ctx).
Language("python").Content(python).UAST()
if err != nil {
panic(err)
}
query := "//*[self::uast:Import or self::uast:RuntimeImport]"
it, _ := tools.Filter(res, query)
var nodeAr nodes.Array
for it.Next() {
fmt.Printf(it.Node().Name()) // <---- how do I do this?
}
It is in the node under Path/Name, but how do I access it?
Btw. if you just need to extract imports then I highly recommend to use https://github.com/src-d/imports project instead. It's based on tree-sitter so it's much faster and does not require any server.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The example in the docs provides a code snippet to extract the imports from the file. However marshalling nodes into JSON is not a good use case, and I am trying to find a way to get the name of the import without intermediate marhsaling.
It is in the node under Path/Name, but how do I access it?
Also while testing it locally with a Go file the following was the output
Somehow Path/Name became Path/Names.
I can not find docs anywhere about how to read data from nodes.
The text was updated successfully, but these errors were encountered: