[PATCH] D57388: [clangd] Implement textDocument/declaration from LSP 3.14

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 29 07:40:09 PST 2019


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ioeric, javed.absar, ilya-biryukov.

LSP now reflects the declaration/definition distinction.

Language server changes:

- textDocument/definition now returns a definition if one is found, otherwise the declaration. It no longer returns declaration + definition if they are distinct.
- textDocument/declaration returns the best declaration we can find.
- For macros, the active macro definition is returned for both methods.
- For include directive, the top of the target file is returned for both.

There doesn't appear to be a discovery mechanism (we can't return everything to
clients that only know about definition), so this changes existing behavior.
In practice, it should greatly reduce the fraction of the time we need to show
the user a menu of options.

C++ API changes:

- findDefinitions is replaced by locateSymbolAt, which returns a vector<LocatedSymbol> - one for each symbol under the cursor.
- this contains the preferred declaration, the definition (if found), and the symbol name

This API enables some potentially-neat extensions, like swapping between decl
and def, and exposing the symbol name to the UI in the case of multiple symbols.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D57388

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/XRefs.cpp
  clangd/XRefs.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/XRefsTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57388.184088.patch
Type: text/x-patch
Size: 36884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190129/ca967607/attachment-0001.bin>


More information about the cfe-commits mailing list