[PATCH] D97615: [clangd] Include macro expansions in documentSymbol hierarchy

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 27 05:16:09 PST 2021


sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Browsing macro-generated symbols is confusing.
On the one hand, it seems very *useful* to be able to see the summary of
symbols that were generated.
On the other hand, some macros spew a lot of confusing symbols into the
namespace and when used repeatedly (ABSL_FLAG) can create a lot of spam
that's hard to navigate.

Design constraints:

- the macro expansion tree need not align with the AST, though it often does in practice. We address this by defining the nesting based on the *primary* location of decls, rather than their ranges.
- DocumentSymbol.children[*].range should nest within DocumentSymbol.range (This constraint is not in LSP "breadcrumbs" breaks without it) We adjust macro ranges so they cover their "children", rather than just the macro expansion
- LSP does not have a "macro expansion" symbolkind, nor does it allow a symbol to have no kind. I've arbitrarily picked "null" as this is unlikely to conflict with anything useful.

This patch makes all macros and children visible for simplicity+consistency,
though in some cases it may be better to elide the macro node.
We may consider adding heuristics for this in future (e.g. when it expands
to one decl only?) but it doesn't seem clear-cut to me.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97615

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97615.326900.patch
Type: text/x-patch
Size: 12766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210227/201dfdd5/attachment.bin>


More information about the cfe-commits mailing list