Skip to content

Commit

Permalink
[clangd] Use include_cleaner spelling strategies in clangd.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D152913
  • Loading branch information
VitaNuo committed Jun 14, 2023
1 parent 78a0b2b commit 6a6c7ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
5 changes: 4 additions & 1 deletion clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1223,7 +1224,9 @@ void maybeAddSymbolProviders(ParsedAST &AST, HoverInfo &HI,
// 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)
Expand Down
21 changes: 3 additions & 18 deletions clang-tools-extra/clangd/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
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("<");
Expand Down Expand Up @@ -412,22 +413,6 @@ convertIncludes(const SourceManager &SM,
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});
}

IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
// Interaction is only polished for C/CPP.
if (AST.getLangOpts().ObjC)
Expand Down
5 changes: 0 additions & 5 deletions clang-tools-extra/clangd/IncludeCleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ include_cleaner::Includes
convertIncludes(const SourceManager &SM,
const llvm::ArrayRef<Inclusion> 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<include_cleaner::SymbolReference>
collectMacroReferences(ParsedAST &AST);

Expand Down

0 comments on commit 6a6c7ed

Please sign in to comment.