<div dir="ltr"><div dir="ltr">Hi Jonathan,<div><br></div><div>Glad things are (mostly) working!</div><div>TL;DR: I think textDocument/definition tries to do what you want, but needs some form of index to work well.</div><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 11, 2019 at 9:25 AM Jonathan Gold via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The one thing I seem to be missing is whether/how to use clangd via the<br>
LPS client to go from a function call under the cursor to its actual<br>
implementation (not just its definition).</blockquote><div>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.</div><div><br></div><div>// foo.h</div><div>void foo(); // this is a declaration, and not a definition</div><div>// foo.cc</div><div>void foo() { printf("hello\n"); } // this is the definition (and also a declaration)</div><div>// bar.cc</div><div>#include "foo.h"</div><div>int main() {</div><div>  foo(); // this is a call site</div><div>}</div><div><br></div><div>If you use "go to definition" in bar.cc (textDocument/definition), clangd will try to show you the definition (in foo.cc).</div><div>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.</div><div>Clangd should be able to find it if:</div><div>A) the definition is in bar.cc itself, or a file it includes</div><div>B) the definition is in a file you have opened recently (it's in the dynamic index)</div><div>C) the definition is within the project, and you've built a static index (using clangd-indexer and clangd -index-file)</div><div>D) the definition is within the project, and the background indexer found it (using clangd -background-index)</div><div>If none of these are true, clangd will show you the declaration instead.</div><div><br></div><div>We plan to enable background indexing by default for LLVM 9, which should make the situation much better.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> I assume that that would be<br>
via textDocument/implementation<br>
(<a href="https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation" rel="noreferrer" target="_blank">https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation</a>),<br>
but IIUC, that method is not implemented in clangd.<br></blockquote><div>The three related methods here are pretty poorly documented in the spec. Clangd's interpretation is:</div><div><br></div><div>textDocument/declaration: shows the primary declaration (the best one we know about).</div><div>textDocument/definition: shows the single definition. If it's unknown (or you're already there), shows you the primary declaration instead.</div><div>textDocument/implementation: not yet implemented: shows all known overrides of a virtual member function, or derived classes of a class.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Is there some other method that I should be using? If not, are there<br>
plans to implement this?<br>
<br>
Apologies too if this list is not the correct place for this. I didn't<br>
want to file this yet as a bugzilla bug if in fact it is a known issue<br>
already. I tried searching bugzilla for "textDocument" and only saw one<br>
result (<a href="https://bugs.llvm.org/show_bug.cgi?id=34497" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=34497</a>), so figured that<br>
might not even be where features like this are requested.<br></blockquote><div>That's the official LLVM bugtracker, and we'll deal with bugs posted there.</div><div>We also use a github tracker a bit for convenience; I filed <a href="https://github.com/clangd/clangd/issues/29">https://github.com/clangd/clangd/issues/29</a> for textDocument/implementation support.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
jonathan<br>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div></div>