ioeric updated this revision to Diff 146082.
ioeric added a comment.
- [clangd] Add helper for collecting #include directives in file.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D46670
Files:
clangd/ClangdLSPServer.cpp
clangd/SourceCode.cpp
clangd/SourceCode.h
Index: clangd/SourceCode.h
===================================================================
--- clangd/SourceCode.h
+++ clangd/SourceCode.h
@@ -15,6 +15,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
#include "Protocol.h"
#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Core/Replacement.h"
namespace clang {
class SourceManager;
@@ -55,6 +56,15 @@
std::pair<llvm::StringRef, llvm::StringRef>
splitQualifiedName(llvm::StringRef QName);
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R);
+
+std::vector<TextEdit>
+replacementsToEdits(StringRef Code,
+ const std::vector<tooling::Replacement> &Replacements);
+
+std::vector<TextEdit> replacementsToEdits(StringRef Code,
+ const tooling::Replacements &Repls);
+
} // namespace clangd
} // namespace clang
#endif
Index: clangd/SourceCode.cpp
===================================================================
--- clangd/SourceCode.cpp
+++ clangd/SourceCode.cpp
@@ -166,5 +166,31 @@
return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)};
}
+TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) {
+ Range ReplacementRange = {
+ offsetToPosition(Code, R.getOffset()),
+ offsetToPosition(Code, R.getOffset() + R.getLength())};
+ return {ReplacementRange, R.getReplacementText()};
+}
+
+std::vector<TextEdit>
+replacementsToEdits(StringRef Code,
+ const std::vector<tooling::Replacement> &Replacements) {
+ // Turn the replacements into the format specified by the Language Server
+ // Protocol. Fuse them into one big JSON array.
+ std::vector<TextEdit> Edits;
+ for (const auto &R : Replacements)
+ Edits.push_back(replacementToEdit(Code, R));
+ return Edits;
+}
+
+std::vector<TextEdit> replacementsToEdits(StringRef Code,
+ const tooling::Replacements &Repls) {
+ std::vector<TextEdit> Edits;
+ for (const auto &R : Repls)
+ Edits.push_back(replacementToEdit(Code, R));
+ return Edits;
+}
+
} // namespace clangd
} // namespace clang
Index: clangd/ClangdLSPServer.cpp
===================================================================
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -60,32 +60,6 @@
static URISchemeRegistry::Add<TestScheme>
X("test", "Test scheme for clangd lit tests.");
-TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) {
- Range ReplacementRange = {
- offsetToPosition(Code, R.getOffset()),
- offsetToPosition(Code, R.getOffset() + R.getLength())};
- return {ReplacementRange, R.getReplacementText()};
-}
-
-std::vector<TextEdit>
-replacementsToEdits(StringRef Code,
- const std::vector<tooling::Replacement> &Replacements) {
- // Turn the replacements into the format specified by the Language Server
- // Protocol. Fuse them into one big JSON array.
- std::vector<TextEdit> Edits;
- for (const auto &R : Replacements)
- Edits.push_back(replacementToEdit(Code, R));
- return Edits;
-}
-
-std::vector<TextEdit> replacementsToEdits(StringRef Code,
- const tooling::Replacements &Repls) {
- std::vector<TextEdit> Edits;
- for (const auto &R : Repls)
- Edits.push_back(replacementToEdit(Code, R));
- return Edits;
-}
-
SymbolKindBitset defaultSymbolKinds() {
SymbolKindBitset Defaults;
for (size_t I = SymbolKindMin; I <= static_cast<size_t>(SymbolKind::Array);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits