[clangd-dev] Are there plans to support textDocument/implementation?

Sam McCall via clangd-dev clangd-dev at lists.llvm.org
Thu Apr 11 00:46:51 PDT 2019


Hi Jonathan,

Glad things are (mostly) working!
TL;DR: I think textDocument/definition tries to do what you want, but needs
some form of index to work well.

On Thu, Apr 11, 2019 at 9:25 AM Jonathan Gold via clangd-dev <
clangd-dev at lists.llvm.org> wrote:

> The one thing I seem to be missing is whether/how to use clangd via the
> LPS client to go from a function call under the cursor to its actual
> implementation (not just its definition).

I'm not trying to nitpick, but just to understand precisely: I think you're
using "implementation" to mean what the c++ standard calls a definition,
and "definition" to mean a declaration.

// foo.h
void foo(); // this is a declaration, and not a definition
// foo.cc
void foo() { printf("hello\n"); } // this is the definition (and also a
declaration)
// bar.cc
#include "foo.h"
int main() {
  foo(); // this is a call site
}

If you use "go to definition" in bar.cc (textDocument/definition), clangd
will try to show you the definition (in foo.cc).
However, there's no systematic way to find it - the declaration must be in
a file #included by bar.cc, but the definition could be anywhere.
Clangd should be able to find it if:
A) the definition is in bar.cc itself, or a file it includes
B) the definition is in a file you have opened recently (it's in the
dynamic index)
C) the definition is within the project, and you've built a static index
(using clangd-indexer and clangd -index-file)
D) the definition is within the project, and the background indexer found
it (using clangd -background-index)
If none of these are true, clangd will show you the declaration instead.

We plan to enable background indexing by default for LLVM 9, which should
make the situation much better.

I assume that that would be
> via textDocument/implementation
> (
> https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation
> ),
> but IIUC, that method is not implemented in clangd.
>
The three related methods here are pretty poorly documented in the spec.
Clangd's interpretation is:

textDocument/declaration: shows the primary declaration (the best one we
know about).
textDocument/definition: shows the single definition. If it's unknown (or
you're already there), shows you the primary declaration instead.
textDocument/implementation: not yet implemented: shows all known overrides
of a virtual member function, or derived classes of a class.


> Is there some other method that I should be using? If not, are there
> plans to implement this?
>
> Apologies too if this list is not the correct place for this. I didn't
> want to file this yet as a bugzilla bug if in fact it is a known issue
> already. I tried searching bugzilla for "textDocument" and only saw one
> result (https://bugs.llvm.org/show_bug.cgi?id=34497), so figured that
> might not even be where features like this are requested.
>
That's the official LLVM bugtracker, and we'll deal with bugs posted there.
We also use a github tracker a bit for convenience; I filed
https://github.com/clangd/clangd/issues/29 for textDocument/implementation
support.


> jonathan
> _______________________________________________
> clangd-dev mailing list
> clangd-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20190411/6108fc4b/attachment.html>


More information about the clangd-dev mailing list