[PATCH] D121592: [clangd] Expose include cleaner interface in clangd
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 14 04:21:22 PDT 2022
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121592.415057.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220314/f27a6aa5/attachment.bin>
More information about the cfe-commits
mailing list