clang-tools  15.0.0git
Public Member Functions | List of all members
clang::clangd::IncludeInserter Class Reference

#include <Headers.h>

Public Member Functions

 IncludeInserter (StringRef FileName, StringRef Code, const format::FormatStyle &Style, StringRef BuildDir, HeaderSearch *HeaderSearchInfo)
 
void addExisting (const Inclusion &Inc)
 
bool shouldInsertInclude (PathRef DeclaringHeader, const HeaderFile &InsertedHeader) const
 Checks whether to add an #include of the header into File. More...
 
llvm::Optional< std::string > calculateIncludePath (const HeaderFile &InsertedHeader, llvm::StringRef IncludingFile) const
 Determines the preferred way to #include a file, taking into account the search path. More...
 
llvm::Optional< TextEditinsert (llvm::StringRef VerbatimHeader) const
 Calculates an edit that inserts VerbatimHeader into code. More...
 

Detailed Description

Definition at line 198 of file Headers.h.

Constructor & Destructor Documentation

◆ IncludeInserter()

clang::clangd::IncludeInserter::IncludeInserter ( StringRef  FileName,
StringRef  Code,
const format::FormatStyle Style,
StringRef  BuildDir,
HeaderSearch *  HeaderSearchInfo 
)
inline

Definition at line 203 of file Headers.h.

Member Function Documentation

◆ addExisting()

void clang::clangd::IncludeInserter::addExisting ( const Inclusion Inc)

◆ calculateIncludePath()

llvm::Optional< std::string > clang::clangd::IncludeInserter::calculateIncludePath ( const HeaderFile InsertedHeader,
llvm::StringRef  IncludingFile 
) const

Determines the preferred way to #include a file, taking into account the search path.

Usually this will prefer a shorter representation like 'Foo/Bar.h' over a longer one like 'Baz/include/Foo/Bar.h'.

Parameters
InsertedHeaderThe preferred header to be inserted.
IncludingFileis the absolute path of the file that InsertedHeader will be inserted.
Returns
A quoted "path" or <path> to be included, or None if it couldn't be shortened.

Definition at line 324 of file Headers.cpp.

References clang::clangd::HeaderFile::File, clang::clangd::HeaderFile::valid(), and clang::clangd::HeaderFile::Verbatim.

◆ insert()

llvm::Optional< TextEdit > clang::clangd::IncludeInserter::insert ( llvm::StringRef  VerbatimHeader) const

Calculates an edit that inserts VerbatimHeader into code.

If the header is already included, this returns None.

Definition at line 354 of file Headers.cpp.

References clang::clangd::replacementToEdit().

◆ shouldInsertInclude()

bool clang::clangd::IncludeInserter::shouldInsertInclude ( PathRef  DeclaringHeader,
const HeaderFile InsertedHeader 
) const

Checks whether to add an #include of the header into File.

FIXME(ioeric): we might not want to insert an absolute include path if the path is not shortened.

An #include will not be added if:

  • Either DeclaringHeader or InsertedHeader is already (directly) in Inclusions (including those included via different paths).
  • DeclaringHeader or InsertedHeader is the same as File.
Parameters
DeclaringHeaderis path of the original header corresponding to InsertedHeader e.g. the header that declares a symbol.
InsertedHeaderThe preferred header to be inserted. This could be the same as DeclaringHeader but must be provided.

Definition at line 310 of file Headers.cpp.

References clang::clangd::HeaderFile::File, clang::clangd::HeaderFile::valid(), and clang::clangd::HeaderFile::Verbatim.


The documentation for this class was generated from the following files: