It's valuable to have document highlights for labels and be able to find
references to them.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks! This looks like a useful addition.
Could you add a test into libIndex for this too? Just for the sake of having better coverage, some folks probably don't run clang-tools-extra tests.
Also, could we add a test that a label does not get indexed if local function indexing is off?
clang/lib/Index/IndexBody.cpp | ||
---|---|---|
148 | IndexingContext::handleReference already has this check, we should call handleReference unconditionally. | |
158 | We should call handleDecl, indexing output can differentiate between a declarations and a references. |
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.
I have also not looked into libIndex for quite a long time, so looping in @kadircet for a second pair of eyes.
According to the commit message of the patch that added this, it was for "go to definition" functionality (which did indeed work already).
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.
clang/lib/Index/IndexBody.cpp | ||
---|---|---|
150 | 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. | |
clang/unittests/Index/IndexTests.cpp | ||
233 ↗ | (On Diff #521577) | 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"). |
sorry for missing this review. Nathan's explanation around targetDecl vs findRefs is absolutely right (btw, thanks a lot Nathan for taking good care of clangd, I don't think I say that enough). hopefully one day we can switch clangd's usage of libindex to our internal find target/explicitrefs implementation, but until then we actually need to address such things in both places to make sure functionality is actually consistent.
clang/lib/Index/IndexBody.cpp | ||
---|---|---|
150 | +1 we shouldn't be setting namereference here. |
clang/lib/Index/IndexBody.cpp | ||
---|---|---|
150 | So set nothing at all here? |
clang/lib/Index/IndexBody.cpp | ||
---|---|---|
150 | Yes, I think we should pass a default constructed SymbolRoleSet() here, and handleReference() will add SymbolRole::Reference into it automatically. |
IndexingContext::handleReference already has this check, we should call handleReference unconditionally.