How to get selected element's full qualified name and it's documentation from source code #911
-
My GoalI'd like to get (or calculate) the full qualified name of the element under caret (or of the selected element) in an LSP-based editor (in my case LSP-based C++ editor), which I hope to get from the language server. Using the qualified name, I'd like to look up the element's documentation from a separate model (which complements the source code). If such a documentation does not exist, I'd like to get the element's documentation from the source code, which I need to find with the language server's help. QuestionDoes anyone has some advice how to do that with LSP4E (or CDT LSP)? I saw, the LSP protocol provides features like document symbols and semantic tokens, but both do not provide qualified names and the document symbols do not cover comments. Besides, there are some LSP protocol extensions for clangd, e.g. symbol info request and the abstract syntax tree. These seem to be the most promising language server interfaces that I could use. It seems, the CDT LSP team started adding support for these clangd LSP extensions. Are there any opinions on that or any advice? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You could create a LS dedicated to this alternative model, and that would contribute a |
Beta Was this translation helpful? Give feedback.
-
I'm not sure, how or if that can work. In my case, the model complementing a C++ file is in a separate file (e.g. an EMF-based model) and contains details for multiple C++ Eclipse projects. Doesn't the hover feature require that model file to be open in a text editor having the cursor at the position corresponding to the element under cursor in the C++ editor? I originally thought of receiving an ID or URI from the language server and using that ID / URI to look up the documentation in the separate model file or picking up the corresponding comment in C++ source code using the AST. |
Beta Was this translation helpful? Give feedback.
-
It turns out, one way of getting an element's (document symbol's) documentation is using the textDocument/hover request type. At least with C++ and clangd, I was able to receive the documentation (and some other details) in a Markdown source code. But I didn't find a promising way to get an element's qualified name from the language server. I think, I'll have to calculate it myself. |
Beta Was this translation helpful? Give feedback.
LSP doesn't have the concept of a "qualified name", it's all UI/text operations. LSP4E will never be able to provide a standard way to get something that has no definition in LSP. So either you can resolve the qualified name from an existing standard operation (eg hover), or you'll need the LS to provide a custom operation to get the data you want; but in any case it's a LS-specific workflow that LSP4E itself won't be able to provide.