[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 00:35:03 PDT 2023


nridge added a comment.

In D150124#4329163 <https://reviews.llvm.org/D150124#4329163>, @ilya-biryukov wrote:

> In `clangd` we also have `findExplicitReferences` and `targetDecl` functions that seem to handle the `GoToStmt`.
> In fact, I believe they are used in `findDocumentHighlights`, so I'm not sure why your test did not work before this patch.
> findDocumentHighlights

I can explain this part: `findDocumentHighlights` uses `targetDecl` to associate the input cursor position with a symbol, but then it uses `findRefs` (which uses `libIndex`) to locate //other// usages of the symbol in the file.



================
Comment at: clang/lib/Index/IndexBody.cpp:150
+                                    ParentDC,
+                                    unsigned(SymbolRole::NameReference));
+  }
----------------
`NameReference` was introduced in https://github.com/llvm/llvm-project/commit/e7eb27a9a0edd859de49bcc9af7ca27dbb435886 to handle the somewhat unique situation with constructors and destructors where the constructor/destructor references the class by name but semantically denotes a separate entity.

Why is that applicable here?

Note that `handleReference()` will automatically add `SymbolRole::Reference` [here](https://searchfox.org/llvm/rev/cea72fe34194d58ac1ba9485ee9c9a63cf98a4e6/clang/lib/Index/IndexingContext.cpp#404).


================
Comment at: clang/unittests/Index/IndexTests.cpp:233
+  tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("theLabel"),
+                                                   WrittenAt(Position(3, 16)),
----------------
I think the outer `AllOf()` here is a no-op, since it has only one argument. (`AllOf(x, y, z)` means "each of the matchers `x`, `y`, and `z` match").


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150124/new/

https://reviews.llvm.org/D150124



More information about the cfe-commits mailing list