diff options
Diffstat (limited to 'clang-tools-extra/clangd/SourceCode.h')
| -rw-r--r-- | clang-tools-extra/clangd/SourceCode.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h index 81b4672b184..53a140fe4ab 100644 --- a/clang-tools-extra/clangd/SourceCode.h +++ b/clang-tools-extra/clangd/SourceCode.h @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H + #include "Context.h" #include "Protocol.h" #include "clang/Basic/Diagnostic.h" @@ -22,7 +23,9 @@ #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Support/Error.h" #include "llvm/Support/SHA1.h" +#include <string> namespace clang { class SourceManager; @@ -197,11 +200,34 @@ format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, llvm::vfs::FileSystem *FS); -// Cleanup and format the given replacements. +/// Cleanup and format the given replacements. llvm::Expected<tooling::Replacements> cleanupAndFormat(StringRef Code, const tooling::Replacements &Replaces, const format::FormatStyle &Style); +/// A set of edits generated for a single file. Can verify whether it is safe to +/// apply these edits to a code block. +struct Edit { + tooling::Replacements Replacements; + std::string InitialCode; + + Edit(llvm::StringRef Code, tooling::Replacements Reps) + : Replacements(std::move(Reps)), InitialCode(Code) {} + + /// Returns the file contents after changes are applied. + llvm::Expected<std::string> apply() const; + + /// Represents Replacements as TextEdits that are available for use in LSP. + std::vector<TextEdit> asTextEdits() const; + + /// Checks whether the Replacements are applicable to given Code. + bool canApplyTo(llvm::StringRef Code) const; +}; + +/// Formats the edits and code around it according to Style. Changes +/// Replacements to formatted ones if succeeds. +llvm::Error reformatEdit(Edit &E, const format::FormatStyle &Style); + /// Collects identifiers with counts in the source code. llvm::StringMap<unsigned> collectIdentifiers(llvm::StringRef Content, const format::FormatStyle &Style); |

