13 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H 14 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H 18 #include "clang/Basic/Diagnostic.h" 19 #include "clang/Basic/LangOptions.h" 20 #include "clang/Basic/SourceLocation.h" 21 #include "clang/Basic/SourceManager.h" 22 #include "clang/Format/Format.h" 23 #include "clang/Tooling/Core/Replacement.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/ADT/StringSet.h" 26 #include "llvm/Support/Error.h" 27 #include "llvm/Support/SHA1.h" 40 Optional<FileDigest>
digestFile(
const SourceManager &SM, FileID FID);
59 llvm::Expected<size_t>
61 bool AllowColumnsBeyondLineLength =
true);
73 const LangOptions &LangOpts,
74 SourceLocation TokLoc);
86 const SourceManager &SM,
87 const LangOptions &LangOpts);
100 SourceLocation
includeHashLoc(FileID IncludedFile,
const SourceManager &SM);
124 const LangOptions &LangOpts,
148 llvm::StringRef
toSourceCode(
const SourceManager &SM, SourceRange R);
162 std::pair<llvm::StringRef, llvm::StringRef>
168 const tooling::Replacements &Repls);
171 const LangOptions &L);
184 const SourceManager &SourceMgr);
194 llvm::StringRef Content,
195 llvm::vfs::FileSystem *
FS);
198 llvm::Expected<tooling::Replacements>
208 Edit(llvm::StringRef
Code, tooling::Replacements Reps)
209 : Replacements(std::move(Reps)), InitialCode(Code) {}
212 llvm::Expected<std::string>
apply()
const;
234 llvm::StringRef Content,
235 const LangOptions &LangOpts);
242 llvm::StringSet<>
collectWords(llvm::StringRef Content);
285 llvm::StringRef FullyQualifiedName,
299 llvm::Optional<LangOptions> LangOpts =
llvm::None);
SourceLocation Loc
'#' location in the include directive
llvm::StringSet collectWords(llvm::StringRef Content)
Collects words from the source code.
llvm::Expected< tooling::Replacements > cleanupAndFormat(StringRef Code, const tooling::Replacements &Replaces, const format::FormatStyle &Style)
Cleanup and format the given replacements.
size_t lspLength(llvm::StringRef Code)
std::array< uint8_t, 8 > FileDigest
std::pair< StringRef, StringRef > splitQualifiedName(StringRef QName)
bool isInsideMainFile(SourceLocation Loc, const SourceManager &SM)
Returns true iff Loc is inside the main file.
llvm::Expected< std::string > apply() const
Returns the file contents after changes are applied.
SourceLocation getBeginningOfIdentifier(const Position &Pos, const SourceManager &SM, const LangOptions &LangOpts)
Get the beginning SourceLocation at a specified Pos in the main file.
bool halfOpenRangeContains(const SourceManager &Mgr, SourceRange R, SourceLocation L)
Returns true iff L is contained in R.
Values in a Context are indexed by typed keys.
Documents should not be synced at all.
bool halfOpenRangeTouches(const SourceManager &Mgr, SourceRange R, SourceLocation L)
Returns true iff L is contained in R or L is equal to the end point of R.
bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM)
Returns true if the token at Loc is spelled in the source code.
llvm::Expected< SourceLocation > sourceLocationInMainFile(const SourceManager &SM, Position P)
Return the file location, corresponding to P.
std::vector< std::string > visibleNamespaces(llvm::StringRef Code, const format::FormatStyle &Style)
Heuristically determine namespaces visible at a point, without parsing Code.
bool isRangeConsecutive(const Range &Left, const Range &Right)
bool canApplyTo(llvm::StringRef Code) const
Checks whether the Replacements are applicable to given Code.
bool isValidFileRange(const SourceManager &Mgr, SourceRange R)
Returns true iff all of the following conditions hold:
std::pair< size_t, size_t > offsetToClangLineColumn(llvm::StringRef Code, size_t Offset)
TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M, const LangOptions &L)
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
Turn an offset in Code into a [line, column] pair.
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength)
Turn a [line, column] pair into an offset in Code.
std::string EnclosingNamespace
Namespace that owns all of the EligiblePoints, e.g.
EligibleRegion getEligiblePoints(llvm::StringRef Code, llvm::StringRef FullyQualifiedName, const format::FormatStyle &Style)
Returns most eligible region to insert a definition for FullyQualifiedName in the Code...
Key< OffsetEncoding > kCurrentOffsetEncoding
Represents locations that can accept a definition.
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
llvm::Optional< FileDigest > digestFile(const SourceManager &SM, FileID FID)
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, llvm::vfs::FileSystem *FS)
Choose the clang-format style we should apply to a certain file.
tooling::Replacements Replacements
llvm::StringMap< Edit > FileEdits
A mapping from absolute file path (the one used for accessing the underlying VFS) to edits...
FileDigest digest(llvm::StringRef Content)
llvm::Optional< SourceRange > toHalfOpenFileRange(const SourceManager &SM, const LangOptions &LangOpts, SourceRange R)
Turns a token range into a half-open range and checks its correctness.
SourceLocation includeHashLoc(FileID IncludedFile, const SourceManager &SM)
Returns the #include location through which IncludedFIle was loaded.
llvm::StringRef toSourceCode(const SourceManager &SM, SourceRange R)
Returns the source code covered by the source range.
Edit(llvm::StringRef Code, tooling::Replacements Reps)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
TextEdit replacementToEdit(llvm::StringRef Code, const tooling::Replacement &R)
llvm::Optional< std::string > getCanonicalPath(const FileEntry *F, const SourceManager &SourceMgr)
Get the canonical path of F.
std::vector< TextEdit > replacementsToEdits(llvm::StringRef Code, const tooling::Replacements &Repls)
std::vector< TextEdit > asTextEdits() const
Represents Replacements as TextEdits that are available for use in LSP.
bool isHeaderFile(llvm::StringRef FileName, llvm::Optional< LangOptions > LangOpts)
Infers whether this is a header from the FileName and LangOpts (if presents).
llvm::Optional< FixItHint > FixIt
std::vector< Range > collectIdentifierRanges(llvm::StringRef Identifier, llvm::StringRef Content, const LangOptions &LangOpts)
Collects all ranges of the given identifier in the source code.
llvm::StringMap< unsigned > collectIdentifiers(llvm::StringRef Content, const format::FormatStyle &Style)
Collects identifiers with counts in the source code.
llvm::Optional< DefinedMacro > locateMacroAt(SourceLocation Loc, Preprocessor &PP)
Gets the macro at a specified Loc.
A set of edits generated for a single file.
llvm::Error reformatEdit(Edit &E, const format::FormatStyle &Style)
Formats the edits and code around it according to Style.
std::vector< Position > EligiblePoints
Offsets into the code marking eligible points to insert a function definition.
Range halfOpenToRange(const SourceManager &SM, CharSourceRange R)
static cl::opt< std::string > FormatStyle("format-style", cl::desc(R"(
Style for formatting code around applied fixes:
- 'none' (default) turns off formatting
- 'file' (literally 'file', not a placeholder)
uses .clang-format file in the closest parent
directory
- '{ <json> }' specifies options inline, e.g.
-format-style='{BasedOnStyle: llvm, IndentWidth: 8}'
- 'llvm', 'google', 'webkit', 'mozilla'
See clang-format documentation for the up-to-date
information about formatting styles and options.
This option overrides the 'FormatStyle` option in
.clang-tidy file, if any.
)"), cl::init("none"), cl::cat(ClangTidyCategory))