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

Jonathan Gold via clangd-dev clangd-dev at lists.llvm.org
Thu Apr 11 16:15:30 PDT 2019

Sam -- Thanks so much for the reply and for the clarification below on
definition/declaration/implementation. It's not a nitpick and is
definitely helpful. Indeed, I'm setting this all up so I can write some
tools atop Google's OR Tools using the C++ API, and is my chance to
finally learn/encounter C++ :)

I did confirm that option (B) below works as expected with
textDocument/definition, and I get a result after I've previously opened
the appropriate .cc file. 

I tried (D) and ran with -background-index but that alone doesn't seem
to work (verbose logging showed a lot of errors and didn't encounter any
of the files I would have expected before it seems like it gave up). I
don't see clangd-indexer in the macos binary distro (v8), but will see
if I can build llvm from source and give (C) a try anyway against v9.
That may also give me more control over how it runs and I'll learn more
that way.

Thanks for your help (and terminology clarification) so far.


On Thu, Apr 11, 2019 at 09:46:51AM +0200, Sam McCall wrote:
> 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
> >

More information about the clangd-dev mailing list