Can I query a Language Server for arbitrary metadata of a project?

Is there any kind of query I can make to a typical LS that would allow me to get, say, something like all callers of a given function, or the functions contained in some module? All the examples of LS’s and Clients I see in tutorials are more about the interactivity bits (like highlighting certain character sequences), but I’m interested in being able to get metadata about a project. Is looking at LS’s perhaps the wrong direction? Would something like TreeSitter possibly have more of what I want?

1 Like

AFAIK you cannot ask a language server to answer arbitrary queries, but if your needs can be satisfied by answering one or more of the requests defined in the LSP specification and if your language server supports those requests, then you should be able to do what you want. I expect this won’t be trivial and would need writing your own handlers, though.

TreeSitter may or may not be enough for your use-case. At heart it is a parser which generates a syntax tree from your code, and I believe you can write custom queries to answer any question you might have about the code. The caveat is that AFAIK it only works on one file at a time, so you cannot answer project-wide queries (at least not just with TS).