diff --git a/clang-tools-extra/clangd/tool/Check.cpp b/clang-tools-extra/clangd/tool/Check.cpp --- a/clang-tools-extra/clangd/tool/Check.cpp +++ b/clang-tools-extra/clangd/tool/Check.cpp @@ -33,6 +33,7 @@ #include "Feature.h" #include "GlobalCompilationDatabase.h" #include "Hover.h" +#include "IncludeCleaner.h" #include "InlayHints.h" #include "ParsedAST.h" #include "Preamble.h" @@ -332,6 +333,15 @@ Inputs.ClangTidyProvider = Opts.ClangTidyProvider; } + void computeUnusedIncludes() { + auto UnusedIncludes = clang::clangd::computeUnusedIncludes(*AST); + log("Computing unused includes"); + for (const auto *Unused : UnusedIncludes) { + log(" - {0} @Line:{1}", Unused->Written, + Unused->HashLine + 1 /*1-based*/); + } + } + // Build Inlay Hints for the entire AST or the specified range void buildInlayHints(llvm::Optional LineRange) { log("Building inlay hints"); @@ -464,6 +474,7 @@ return false; C.buildInlayHints(LineRange); C.buildSemanticHighlighting(LineRange); + C.computeUnusedIncludes(); if (CheckLocations) C.testLocationFeatures(LineRange);