#Resolving Go in Go

11 messages · Page 1 of 1 (latest)

untold lava
#

Hey all,

I'm trying to create a tool in Go that can take a function definition, resolve all of the symbols being referenced in the function, and then locate all of their definitions relative to the project root / vendor directory.

Is there a way to leverage one of the Go language servers to locate the function definitions?
I'm familiar with go-tree-sitter, which can parse Go code and pull out the symbol names, however I need to be able to locate their exact definition locations regardless of where they are in the project.

#

@upbeat quiver Would you happen to know how to accomplish this?

upbeat quiver
#

Is there a way to leverage one of the Go language servers to locate the function definitions?
Most likely, idk how to do it tho.
You can lookup the LSP spec

untold lava
#

Yeah, I put together a bash script earlier which uses the gopls CLI, but I was hoping to call the functions directly from my Go CLI tool so I can avoid writing everything in BASH

upbeat quiver
untold lava
#

I was under the impression that they weren't exporting stuff but let me try again - it may have just been me blindly trusting autocomplete

untold lava
#

Borrowing, I'm not sure about since I'd need to basically fork the entire repo for it to work properly

merry echo
#

There are going to be limits to what you can do. I think running functions will be simplest.
There's a thing called FFI that might help? Or that might just be from C to other languages.