This adds an implementation for the "textDocument/documentLink" LSP request.
It returns links for all #include directives to the resolved target files.
Differential D70872
[clangd] Implement "textDocument/documentLink" protocol support MForster on Nov 30 2019, 1:58 PM. Authored by
Details This adds an implementation for the "textDocument/documentLink" LSP request. It returns links for all #include directives to the resolved target files.
Diff Detail
Event Timeline
Comment Actions Thanks, looks nice!
Comment Actions Ping - how do you want to proceed here? I think the only thing that is really missing here is a unit test, I can add it if you don't have cycles. Comment Actions Sorry, I reverted this change in 079ef783dd5530b5f87beefe624b9179547ded7e. The tests depend on builtin headers, which is not intentionally supported in clangd tests; these tests are broken in some build environments. Comment Actions Not intentionally as far as I'm aware :-) |
Eagerly resolving everything means that this request is going to block on the preamble/AST being built. This isn't terrible (clients should be sending their initial requests in parallel) but does mean a delay before the links show up. (And in updating if we insert an include and want to ctrl-click it, because we just invalidated the preamble).
There are a few ways we could improve this:
a) find the links using a quick pass (simple string matching or raw-lexer based), then resolve results from the MainFileIncludes structure (blocking on the AST at that point)
b) use a quick pass to serve results in the first place, e.g. a PreprocessorOnlyAction with SingleFileParseMode (doesn't descend into headers).
c) a combination of these.
I don't particularly think we need to do these at this point, but may be worth a comment.