diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -18,6 +18,7 @@ #include "Selection.h" #include "SourceCode.h" #include "clang-include-cleaner/Analysis.h" +#include "clang-include-cleaner/IncludeSpeller.h" #include "clang-include-cleaner/Types.h" #include "index/SymbolCollector.h" #include "support/Logger.h" @@ -1223,7 +1224,9 @@ // on local variables, etc. return; - HI.Provider = spellHeader(AST, SM.getFileEntryForID(SM.getMainFileID()), H); + HI.Provider = include_cleaner::spellHeader( + {H, AST.getPreprocessor().getHeaderSearchInfo(), + SM.getFileEntryForID(SM.getMainFileID())}); } // FIXME: similar functions are present in FindHeaders.cpp (symbolName) diff --git a/clang-tools-extra/clangd/IncludeCleaner.h b/clang-tools-extra/clangd/IncludeCleaner.h --- a/clang-tools-extra/clangd/IncludeCleaner.h +++ b/clang-tools-extra/clangd/IncludeCleaner.h @@ -74,11 +74,6 @@ convertIncludes(const SourceManager &SM, const llvm::ArrayRef Includes); -/// Determines the header spelling of an include-cleaner header -/// representation. The spelling contains the ""<> characters. -std::string spellHeader(ParsedAST &AST, const FileEntry *MainFile, - include_cleaner::Header Provider); - std::vector collectMacroReferences(ParsedAST &AST); diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -198,8 +198,9 @@ continue; } - std::string Spelling = - spellHeader(AST, MainFile, SymbolWithMissingInclude.Providers.front()); + std::string Spelling = include_cleaner::spellHeader( + {SymbolWithMissingInclude.Providers.front(), + AST.getPreprocessor().getHeaderSearchInfo(), MainFile}); llvm::StringRef HeaderRef{Spelling}; bool Angled = HeaderRef.starts_with("<"); @@ -334,22 +335,6 @@ return ConvertedIncludes; } -std::string spellHeader(ParsedAST &AST, const FileEntry *MainFile, - include_cleaner::Header Provider) { - if (Provider.kind() == include_cleaner::Header::Physical) { - if (auto CanonicalPath = - getCanonicalPath(Provider.physical()->getLastRef(), - AST.getSourceManager().getFileManager())) { - std::string SpelledHeader = - llvm::cantFail(URI::includeSpelling(URI::create(*CanonicalPath))); - if (!SpelledHeader.empty()) - return SpelledHeader; - } - } - return include_cleaner::spellHeader( - {Provider, AST.getPreprocessor().getHeaderSearchInfo(), MainFile}); -} - std::vector getUnused(ParsedAST &AST, const llvm::DenseSet &ReferencedFiles,