Details
- Reviewers
kadircet - Commits
- rGe028c9742897: Move the BySpelling map to IncludeStructure.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clangd/Headers.h | ||
---|---|---|
164 | instead of building this on-demand, what about building it as we're collecting directives around https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Headers.cpp#L52 ? afterwards we can just have a lookup function exposed here, that returns an ArrayRef<HeaderID> ? |
Thanks for review!
clang-tools-extra/clangd/Headers.h | ||
---|---|---|
164 | That's a great idea. I was thinking about this, but didn't know where to put it, so I thought if it was possible, you'd point out in review ;-) |
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
76 ↗ | (On Diff #496463) | right now we're only storing "resolved" includes from the main file and not all, this is creating a discrepancy between the view one gets through MainFileIncludes and through this map. so instead of storing the HeaderID in the map values, we can actually store indexes into MainFileIncludes. later on during the lookup, we can build a SmallVector<Inclusion *> that contains pointers to the relevant includes. WDYT? |
clang-tools-extra/clangd/Headers.h | ||
164 | what about renaming lookupHeaderIDsBySpelling to mainFileIncludesWithSpelling. with a comment explaining Returns includes inside the main file with the given Spelling. Spelling should include brackets or quotes, e.g. <foo>. |
oh forgot to mention, could you also please add some tests into llvm-project/clang-tools-extra/clangd/unittests/HeadersTests.cpp ?
Thanks for the review!
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
76 ↗ | (On Diff #496463) | Ok sure. |
clang-tools-extra/clangd/Headers.h | ||
---|---|---|
165 | we're still returning just the HeaderID, the suggestion was to return llvm::SmallVector<Inclusion*> so that applications can work with other information available in the Inclusion. we also won't have any requirements around include being resolved that way. the application should figure out what to do if HeaderID is missing. also can you move this function body to source file instead? |
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
303 ↗ | (On Diff #498428) | nit: llvm::SmallVector<Inclusion*> Includes; for (auto Idx : MainFileIncludesBySpelling.lookup(Spelling)) Includes.push_back(&MainFileIncludes[Idx]); return Includes; |
clang-tools-extra/clangd/Headers.h | ||
165 | almost, but not right. we're returning copies of Inclusions here, not pointers to Inclusions inside the main file. the suggested signature was llvm::SmallVector<Inclusion*> any reason for returning by value? | |
clang-tools-extra/clangd/IncludeCleaner.cpp | ||
518 | nit: if(!Inc.HeaderID.has_value()) continue; Used.insert(static_cast<IncludeStructure::HeaderID>(*Inc.HeaderID)); |
Thanks for the comments!
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
303 ↗ | (On Diff #498428) | But lookup will return 0 if it doesn't find the spelling in the map (default value of int). And at the same time 0 is a valid index. Isn't that just wrong? |
clang-tools-extra/clangd/Headers.h | ||
165 | Sure, thanks. No particular reason. |
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
303 ↗ | (On Diff #498428) | MainFileIncludesBySpelling is a map with values of type vector, not int. hence it'll be an empty vector, not 0. |
clang-tools-extra/clangd/Headers.cpp | ||
---|---|---|
303 ↗ | (On Diff #498428) | Oh right. Sorry I guess I got confused. |
instead of building this on-demand, what about building it as we're collecting directives around https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Headers.cpp#L52 ?
afterwards we can just have a lookup function exposed here, that returns an ArrayRef<HeaderID> ?