Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clangd/XRefs.cpp | ||
---|---|---|
1391 | can we put the rest into a separate function (I know this function is already quite long, but I think we shouldn't make it worse, and probably refactor soon). I believe something like below should work? std::vector<Reference> getIncludeUsages(const ParsedAST &AST, const Inclusion &Include); | |
1400 | nit: no need to calculate the file location, if we're not going to emit a reference. so maybe move this into the place where we're going to use the Loc. | |
1400 | this file location might fall outside of the main file when they get expanded through #include directives, so we need something like https://reviews.llvm.org/D147139 | |
1401 | we're implementing and testing this logic twice now, once in here and once in hover. can we instead have a helper in IncludeCleaner.h that looks like: std::optional<include_cleaner::Header> firstSatisfiedProvider(const include_cleaner::Includes& Includes, llvm::ArrayRef<include_cleaner::Header> Providers); // I'd actually return the matching `std::vector<const Include*>` (the highest ranked provider that matched some includes in main file), and check if the include of interest is part of that set for rest of the operations. // Since it represents both the provider and the include in the main file. whereas the provider on it's own doesn't say anything about which include in main file triggered satisfaction. and turn these call sites into auto Provider = firstSatisfiedProvider(ConvertedMainFileIncludes, Providers); if(!Provider || ReferencedInclude.match(Provider).empty()) return; // Include in question provides the symbol, do magic. | |
1411 | no need to re-run the lexer, these references are inside the main file for sure, so you can use token buffer instead. | |
1434 | we can return Results directly here, no need to run rest of the logic | |
2012 | can you revert changes below? I feel like they're unrelated formatting changes | |
clang-tools-extra/clangd/unittests/XRefsTests.cpp | ||
1908 | rather than introducing these into all tests, can we have our own TestTU and whatnot in the relevant test? something like MainFileReferencesOnly test | |
2302 | can you also have a second include header that provides some other symbols and make sure references of those don't get highlighted? | |
2309 | we don't really need rest of these tests, they're testing the "symbol is provided by first provider included in the main file" logic |
Thanks for the comments!
clang-tools-extra/clangd/XRefs.cpp | ||
---|---|---|
1401 | Is the comment under the code in the first snippet a mistake/outdated content? It confused me. |
clang-tools-extra/clangd/IncludeCleaner.cpp | ||
---|---|---|
443 | return std::nullopt | |
clang-tools-extra/clangd/IncludeCleaner.h | ||
87 | can you also move tests related to this functionality from HoverTests into IncludeCleanerTests ? | |
clang-tools-extra/clangd/XRefs.cpp | ||
1320 | can you put this into anon namespace? we should also change the return type to std::optional<ReferencesResult>, as we can "legitimately" have empty result for an include, e.g. it's unused or all of the refs are implicit etc. | |
1324 | const auto &Includes = AST.getIncludeStructure().MainFileIncludes; (& is the important bit, as we're copying all of them otherwise) | |
1325 | let's move this into the for loop, after we've found a matching include to not necessarily create a copy of all the includes again. nit: you can also write the loop below as following and reduce some nesting. auto IncludeOnLine = llvm::find_if(Includes, [&Pos](const Inclusion& Inc) { return Inc.HashLine == Pos.Line; }); if (IncludeOnLine == Includes.end()) return Results; const auto &Inc = *IncludeOnLine; ... | |
1401 | that wasn't supposed to be a comment in the code but rather a comment for the code :D i was suggesting to return the set of Includes matched by the first provider, rather than returning the provider. but feel free to keep it as-is. |
Thanks for the comments!
clang-tools-extra/clangd/IncludeCleaner.h | ||
---|---|---|
87 | Not really, not sure what you mean. This function receives a ranked list of providers that should be a result of include_cleaner analysis. If I just test the function based on a fake list of providers, the test will be trivial. The current hover test seems to provide more value than that. |
clang-tools-extra/clangd/IncludeCleaner.h | ||
---|---|---|
87 |
but that's the "unit" of logic we're trying to test, no? |
clang-tools-extra/clangd/IncludeCleaner.h | ||
---|---|---|
87 | Ok, I've extracted a test. Hopefully that's what you've meant. |
can you also move tests related to this functionality from HoverTests into IncludeCleanerTests ?