[clangd] targetDecl() returns only NamedDecls.
authorSam McCall <sam.mccall@gmail.com>
Fri, 3 Jan 2020 16:26:33 +0000 (17:26 +0100)
committerSam McCall <sam.mccall@gmail.com>
Fri, 3 Jan 2020 17:18:40 +0000 (18:18 +0100)
commitf06f439fadf740ea9019f2eb7f26ff88198ed375
tree3fd67a55947d42c7ac35e803cd766617b0819b66
parentadd743b4348095c0d2e407c7a2b8a87a5f8194b0
[clangd] targetDecl() returns only NamedDecls.

Summary:
While it's perfectly reasonable for non-named decls such as
static_assert to resolve to themselves:
 - nothing else ever resolves to them
 - features based on references (hover, highlight, find refs etc) tend
   to be uninteresting where only trivial references are possible
 - returning NamedDecl is a more convenient API (we cast to it in many places)
 - this aligns closer to findExplicitReferences/explicitReferenceTargets

This fixes a crash in explicitReferenceTargets: if the target is a
non-named decl then there's an invalid unchecked cast to NamedDecl.

In practice this means when hovering over e.g. a static_assert:
 - before ac3f9e4842, we would show a (boring) hover card
 - after ac3f9e4842, we would crash
 - after this patch, we will show nothing

Reviewers: kadircet, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72163
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/FindTarget.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp