clang-tools 19.0.0git
Classes | Namespaces | Typedefs | Functions
SourceCode.h File Reference
#include "Protocol.h"
#include "support/Context.h"
#include "support/ThreadsafeFS.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Error.h"
#include <optional>
#include <string>

Go to the source code of this file.


struct  clang::clangd::Edit
 A set of edits generated for a single file. More...
struct  clang::clangd::SpelledWord
struct  clang::clangd::EligibleRegion
 Represents locations that can accept a definition. More...
struct  clang::clangd::DefinedMacro


namespace  clang
 ===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
namespace  clang::clangd


using clang::clangd::FileDigest = std::array< uint8_t, 8 >
using clang::clangd::FileEdits = llvm::StringMap< Edit >
 A mapping from absolute file path (the one used for accessing the underlying VFS) to edits.


FileDigest clang::clangd::digest (StringRef Content)
std::optional< FileDigest > clang::clangd::digestFile (const SourceManager &SM, FileID FID)
size_t clang::clangd::lspLength (StringRef Code)
llvm::Expected< size_t > clang::clangd::positionToOffset (llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength=true)
 Turn a [line, column] pair into an offset in Code.
Position clang::clangd::offsetToPosition (llvm::StringRef Code, size_t Offset)
 Turn an offset in Code into a [line, column] pair.
Position clang::clangd::sourceLocToPosition (const SourceManager &SM, SourceLocation Loc)
 Turn a SourceLocation into a [line, column] pair.
llvm::Expected< SourceLocation > clang::clangd::sourceLocationInMainFile (const SourceManager &SM, Position P)
 Return the file location, corresponding to P.
bool clang::clangd::isInsideMainFile (SourceLocation Loc, const SourceManager &SM)
 Returns true iff Loc is inside the main file.
SourceLocation clang::clangd::includeHashLoc (FileID IncludedFile, const SourceManager &SM)
 Returns the #include location through which IncludedFIle was loaded.
bool clang::clangd::isSpelledInSource (SourceLocation Loc, const SourceManager &SM)
 Returns true if the token at Loc is spelled in the source code.
std::optional< SourceRange > clang::clangd::toHalfOpenFileRange (const SourceManager &Mgr, const LangOptions &LangOpts, SourceRange R)
 Turns a token range into a half-open range and checks its correctness.
bool clang::clangd::isValidFileRange (const SourceManager &Mgr, SourceRange R)
 Returns true iff all of the following conditions hold:
llvm::StringRef clang::clangd::toSourceCode (const SourceManager &SM, SourceRange R)
 Returns the source code covered by the source range.
Range clang::clangd::halfOpenToRange (const SourceManager &SM, CharSourceRange R)
void clang::clangd::unionRanges (Range &A, Range B)
std::pair< size_t, size_t > clang::clangd::offsetToClangLineColumn (llvm::StringRef Code, size_t Offset)
std::pair< llvm::StringRef, llvm::StringRef > clang::clangd::splitQualifiedName (llvm::StringRef QName)
 From "a::b::c", return {"a::b::", "c"}.
TextEdit clang::clangd::replacementToEdit (StringRef Code, const tooling::Replacement &R)
std::vector< TextEdit > clang::clangd::replacementsToEdits (StringRef Code, const tooling::Replacements &Repls)
TextEdit clang::clangd::toTextEdit (const FixItHint &FixIt, const SourceManager &M, const LangOptions &L)
std::optional< std::string > clang::clangd::getCanonicalPath (const FileEntryRef F, FileManager &FileMgr)
 Get the canonical path of F.
format::FormatStyle clang::clangd::getFormatStyleForFile (llvm::StringRef File, llvm::StringRef Content, const ThreadsafeFS &TFS, bool FormatFile)
 Choose the clang-format style we should apply to a certain file.
llvm::Expected< tooling::Replacements > clang::clangd::cleanupAndFormat (StringRef Code, const tooling::Replacements &Replaces, const format::FormatStyle &Style)
 Cleanup and format the given replacements.
llvm::Error clang::clangd::reformatEdit (Edit &E, const format::FormatStyle &Style)
 Formats the edits and code around it according to Style.
llvm::Error clang::clangd::applyChange (std::string &Contents, const TextDocumentContentChangeEvent &Change)
 Apply an incremental update to a text document.
llvm::StringMap< unsigned > clang::clangd::collectIdentifiers (llvm::StringRef Content, const format::FormatStyle &Style)
 Collects identifiers with counts in the source code.
std::vector< Rangeclang::clangd::collectIdentifierRanges (llvm::StringRef Identifier, llvm::StringRef Content, const LangOptions &LangOpts)
 Collects all ranges of the given identifier in the source code.
llvm::StringSet clang::clangd::collectWords (llvm::StringRef Content)
 Collects words from the source code.
bool clang::clangd::isKeyword (llvm::StringRef TokenName, const LangOptions &LangOpts)
 Return true if the TokenName is in the list of reversed keywords of the language.
std::vector< std::string > clang::clangd::visibleNamespaces (llvm::StringRef Code, const LangOptions &LangOpts)
 Heuristically determine namespaces visible at a point, without parsing Code.
EligibleRegion clang::clangd::getEligiblePoints (llvm::StringRef Code, llvm::StringRef FullyQualifiedName, const LangOptions &LangOpts)
 Returns most eligible region to insert a definition for FullyQualifiedName in the Code.
std::optional< DefinedMacro > clang::clangd::locateMacroAt (const syntax::Token &SpelledTok, Preprocessor &PP)
 Gets the macro referenced by SpelledTok.
bool clang::clangd::isHeaderFile (llvm::StringRef FileName, std::optional< LangOptions > LangOpts=std::nullopt)
 Infers whether this is a header from the FileName and LangOpts (if presents).
bool clang::clangd::isProtoFile (SourceLocation Loc, const SourceManager &SourceMgr)
 Returns true if the given location is in a generated protobuf file.
bool clang::clangd::isReservedName (llvm::StringRef Name)
 Returns true if Name is reserved, like _Foo or __Vector_base.
SourceLocation clang::clangd::translatePreamblePatchLocation (SourceLocation Loc, const SourceManager &SM)
 Translates locations inside preamble patch to their main-file equivalent using presumed locations.
clangd::Range clang::clangd::rangeTillEOL (llvm::StringRef Code, unsigned HashOffset)
 Returns the range starting at offset and spanning the whole line.