This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Implement textDocument/implementation (Xref layer)
ClosedPublic

Authored by usaxena95 on Nov 17 2020, 6:12 AM.

Details

Reviewers
hokein
Summary

Xref layer changes for textdocument/implementation (https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation)

This currently shows all functions (implementations) that overrides a virtual function.

Diff Detail

Event Timeline

usaxena95 created this revision.Nov 17 2020, 6:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2020, 6:12 AM
usaxena95 requested review of this revision.Nov 17 2020, 6:12 AM
usaxena95 edited the summary of this revision. (Show Details)Nov 17 2020, 9:29 AM
usaxena95 added a reviewer: hokein.
usaxena95 updated this revision to Diff 305835.Nov 17 2020, 9:46 AM
usaxena95 edited the summary of this revision. (Show Details)

Minor fixes.

nridge added a subscriber: nridge.Nov 17 2020, 5:19 PM
usaxena95 updated this revision to Diff 305972.Nov 17 2020, 9:50 PM

Addressed final comments. Ready to land.

usaxena95 updated this revision to Diff 305974.Nov 17 2020, 9:52 PM

Remove unintended change.

thanks, just reviewed at the xrefs code. I think we can narrow the scope of the patch by splitting it into two patches

  • find-implementation in xrefs.cpp
  • LSP & clangd server layer (needs a smoke lit test)
clang-tools-extra/clangd/XRefs.cpp
1147

I think we should restrict to virtual method only.

1153

symbolToLocation will prefer definition location over declaration location.

there are a few options:

  1. just return declaration location
  2. just return definition location
  3. return both

in the find-implementaiton case, I think the declaration location is more? interesting than the definition location, I would slightly prefer 1), what do you think?

clang-tools-extra/clangd/XRefs.h
87

not sure ReferenceResult is the best fit -- we never set the HasMore field.

I'd use std::vector<LocatedSymbol>, this returns richer information, and the client (LSPServer can choose which location they want to return).

usaxena95 updated this revision to Diff 306076.Nov 18 2020, 5:56 AM
usaxena95 marked 3 inline comments as done.

Addressed comments.

clang-tools-extra/clangd/XRefs.cpp
1153

You are right. I experienced this while playing with it in VSCode. Sorry to not explicitly mention this.
I too prefer declaration in such case.

usaxena95 updated this revision to Diff 306079.Nov 18 2020, 6:02 AM

Added test for no implementation for concrete methods.

hokein accepted this revision.Nov 18 2020, 6:35 AM

The patch description is a bit stale now.

clang-tools-extra/clangd/XRefs.cpp
1130

The current way is probably ok -- the index may be stale (if the index is not finished yet by the time we call find-implementation), so we might loose some latest results for the current main file. I think we need some comments describing the behavior. Maybe in future, we'll reconsider it

1140

nit: we need to verify CurLoc is available.

1160

I think we can leave the Definition if !DefLoc.

This revision is now accepted and ready to land.Nov 18 2020, 6:35 AM
usaxena95 updated this revision to Diff 306115.Nov 18 2020, 8:03 AM
usaxena95 marked 2 inline comments as done.

Addressed comments.

usaxena95 marked an inline comment as done.Nov 18 2020, 8:03 AM
usaxena95 retitled this revision from [clangd] Implement textDocument/implementation. to [clangd] Implement textDocument/implementation (Xref layer).
usaxena95 edited the summary of this revision. (Show Details)
usaxena95 closed this revision.Nov 18 2020, 8:32 AM