This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Publish xref for macros from Index and AST.
ClosedPublic

Authored by usaxena95 on Jan 8 2020, 5:21 AM.

Details

Summary

With this patch the findReferences API will return Xref for macros.
If the symbol under the cursor is a macro then we collect the references to it from:

  1. Main file by looking at the ParsedAST. (These were added to the ParsedAST in https://reviews.llvm.org/D70008)
  2. Files other than the mainfile by looking at the:

This patch collects all the xref from the above places and outputs it in findReferences API.

Diff Detail

Event Timeline

usaxena95 created this revision.Jan 8 2020, 5:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 8 2020, 5:21 AM

Unit tests: pass. 61306 tests passed, 0 failed and 736 were skipped.

clang-tidy: pass.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

kadircet added inline comments.Jan 8 2020, 6:27 AM
clang-tools-extra/clangd/XRefs.cpp
462

could we merge this and the code for decls by only populating Req.IDs with MacroSID here and with the symbol id below and by finally making the query in the end ? i.e.

RefsRequest Req;
Req.Limit = Limit;
if (macro) {
 handleMainFileMacros;
 Req.IDs.insert(*MacroID);
} else {
 handleMainFileDecls;
 populateReqIDs(Req);
}
handleIndexResults(Req);
kadircet added inline comments.Jan 8 2020, 6:36 AM
clang-tools-extra/clangd/unittests/XRefsTests.cpp
1021–1022

nit: i don't think there's much benefit in combining refs for macros and symbols in a single test. their handling in the code is disjoint, whereas this test is not. so it makes the test a little bit harder to read and also failures would be harder to reason about. but the test is currently small, so up to you whether you want to separate it or not.

1023

nit: redundant parentheses around R"cpp

usaxena95 updated this revision to Diff 236829.Jan 8 2020, 7:50 AM
usaxena95 marked 3 inline comments as done.

Addressed comments.

usaxena95 marked 2 inline comments as done.Jan 8 2020, 7:51 AM
usaxena95 added inline comments.
clang-tools-extra/clangd/XRefs.cpp
462

Tried to do something on those lines.

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1021–1022

Added the test for macros as a separate test.

Unit tests: pass. 61307 tests passed, 0 failed and 736 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

kadircet accepted this revision.Jan 9 2020, 12:23 AM

thanks, LGTM!

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1092

i know the comment is copied over, but it doesn't reflect what's going on.

as this check makes sure we prever results from AST rather than index for main file, not the duplicate handling(which actually de-dups references on the *same* location).

since this is handled in the common code path, it is OK to check only in one of the tests(up to you though). but please update the comments.

This revision is now accepted and ready to land.Jan 9 2020, 12:23 AM
usaxena95 updated this revision to Diff 237596.Jan 13 2020, 1:55 AM
usaxena95 marked 3 inline comments as done.

Removed repeated check from the test.

usaxena95 added inline comments.Jan 13 2020, 1:57 AM
clang-tools-extra/clangd/unittests/XRefsTests.cpp
1092

Updated the old comment to show the correct intent.
Also removed the check from the macros test since this was on the common code path.

This revision was automatically updated to reflect the committed changes.

Unit tests: pass. 61641 tests passed, 0 failed and 777 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml