serge-sans-paille created this revision. serge-sans-paille added a reviewer: sammccall. Herald added subscribers: usaxena95, kadircet, arphaman. Herald added a project: All. serge-sans-paille requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This gives it the same status as other pieces of clangd and paves the way for other usage. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121592 Files: clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -243,6 +243,10 @@ void findHover(PathRef File, Position Pos, Callback<llvm::Optional<HoverInfo>> CB); + /// Get information about unused includes. + void findUnusedIncludes(PathRef File, + Callback<std::vector<const Inclusion *>> CB); + /// Get information about type hierarchy for a given position. void typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -14,6 +14,7 @@ #include "FindSymbols.h" #include "Format.h" #include "HeaderSourceSwitch.h" +#include "IncludeCleaner.h" #include "InlayHints.h" #include "ParsedAST.h" #include "Preamble.h" @@ -715,6 +716,19 @@ WorkScheduler->runWithAST("Hover", File, std::move(Action), Transient); } +void ClangdServer::findUnusedIncludes( + PathRef File, Callback<std::vector<const Inclusion *>> CB) { + auto Action = [File = File.str(), CB = std::move(CB)]( + llvm::Expected<InputsAndAST> InpAST) mutable { + if (!InpAST) + return CB(InpAST.takeError()); + CB(clangd::computeUnusedIncludes(InpAST->AST)); + }; + + WorkScheduler->runWithAST("UnusedIncludes", File, std::move(Action), + Transient); +} + void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Callback<Optional<TypeHierarchyItem>> CB) {
Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -243,6 +243,10 @@ void findHover(PathRef File, Position Pos, Callback<llvm::Optional<HoverInfo>> CB); + /// Get information about unused includes. + void findUnusedIncludes(PathRef File, + Callback<std::vector<const Inclusion *>> CB); + /// Get information about type hierarchy for a given position. void typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -14,6 +14,7 @@ #include "FindSymbols.h" #include "Format.h" #include "HeaderSourceSwitch.h" +#include "IncludeCleaner.h" #include "InlayHints.h" #include "ParsedAST.h" #include "Preamble.h" @@ -715,6 +716,19 @@ WorkScheduler->runWithAST("Hover", File, std::move(Action), Transient); } +void ClangdServer::findUnusedIncludes( + PathRef File, Callback<std::vector<const Inclusion *>> CB) { + auto Action = [File = File.str(), CB = std::move(CB)]( + llvm::Expected<InputsAndAST> InpAST) mutable { + if (!InpAST) + return CB(InpAST.takeError()); + CB(clangd::computeUnusedIncludes(InpAST->AST)); + }; + + WorkScheduler->runWithAST("UnusedIncludes", File, std::move(Action), + Transient); +} + void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve, TypeHierarchyDirection Direction, Callback<Optional<TypeHierarchyItem>> CB) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits