[clangd] Sort GoToDefinition results.
authorHaojian Wu <hokein@google.com>
Wed, 5 Sep 2018 12:00:15 +0000 (12:00 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 5 Sep 2018 12:00:15 +0000 (12:00 +0000)
commit53e91c1b086267f9c77e9dcb3f7f54b0b17ae1b0
tree88d6f363d74586a4f007878db6b1873d1db16e3b
parent1ad142fe260566f9d14e65cb2a48a2123e2edee0
[clangd] Sort GoToDefinition results.

Summary:
GoToDefinition returns all declaration results (implicit/explicit) that are
in the same location, and the results are returned in arbitrary order.

Some LSP clients defaultly take the first result as the final result, which
might present a bad result (implicit decl) to users.

This patch ranks the result based on whether the declarations are
referenced explicitly/implicitly. We put explicit declarations first.

This also improves the "hover" (which just take the first result) feature
in some cases.

Reviewers: ilya-biryukov

Subscribers: kadircet, ioeric, MaskRay, jkorous, mgrang, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50438

llvm-svn: 341463
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/unittests/clangd/XRefsTests.cpp