[llvm] [mlir] [LLVM][MLIR] Move LSP server support library from MLIR into LLVM (PR #155572)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 05:03:11 PDT 2025
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>,
Albert =?utf-8?q?Havliček?= <ahavlicek at azul.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/155572 at github.com>
https://github.com/Bertik23 updated https://github.com/llvm/llvm-project/pull/155572
>From 1144402b168c6297af46de11862a75d254760317 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 15:34:57 +0000
Subject: [PATCH 1/8] Move MLIR LSP server support into LLVM
---
.../include/llvm/Support/LSP}/Logging.h | 3 +-
.../include/llvm/Support/LSP}/Protocol.h | 18 ++-
.../include/llvm/Support/LSP}/Transport.h | 18 ++-
llvm/lib/Support/CMakeLists.txt | 2 +
llvm/lib/Support/LSP/CMakeLists.txt | 17 +++
.../lib/Support/LSP}/Logging.cpp | 6 +-
.../lib/Support/LSP}/Protocol.cpp | 142 +++++++++---------
.../lib/Support/LSP}/Transport.cpp | 14 +-
.../Tools/lsp-server-support/SourceMgrUtils.h | 4 +-
.../Tools/lsp-server-support/CMakeLists.txt | 3 -
.../CompilationDatabase.cpp | 5 +-
11 files changed, 131 insertions(+), 101 deletions(-)
rename {mlir/include/mlir/Tools/lsp-server-support => llvm/include/llvm/Support/LSP}/Logging.h (97%)
rename {mlir/include/mlir/Tools/lsp-server-support => llvm/include/llvm/Support/LSP}/Protocol.h (98%)
rename {mlir/include/mlir/Tools/lsp-server-support => llvm/include/llvm/Support/LSP}/Transport.h (96%)
create mode 100644 llvm/lib/Support/LSP/CMakeLists.txt
rename {mlir/lib/Tools/lsp-server-support => llvm/lib/Support/LSP}/Logging.cpp (92%)
rename {mlir/lib/Tools/lsp-server-support => llvm/lib/Support/LSP}/Protocol.cpp (88%)
rename {mlir/lib/Tools/lsp-server-support => llvm/lib/Support/LSP}/Transport.cpp (97%)
diff --git a/mlir/include/mlir/Tools/lsp-server-support/Logging.h b/llvm/include/llvm/Support/LSP/Logging.h
similarity index 97%
rename from mlir/include/mlir/Tools/lsp-server-support/Logging.h
rename to llvm/include/llvm/Support/LSP/Logging.h
index 9b090d05f7fa4..c9631d0f58fa1 100644
--- a/mlir/include/mlir/Tools/lsp-server-support/Logging.h
+++ b/llvm/include/llvm/Support/LSP/Logging.h
@@ -9,13 +9,12 @@
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
#define MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
-#include "mlir/Support/LLVM.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
#include <memory>
#include <mutex>
-namespace mlir {
+namespace llvm {
namespace lsp {
/// This class represents the main interface for logging, and allows for
diff --git a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h b/llvm/include/llvm/Support/LSP/Protocol.h
similarity index 98%
rename from mlir/include/mlir/Tools/lsp-server-support/Protocol.h
rename to llvm/include/llvm/Support/LSP/Protocol.h
index cc06dbfedb42a..3da13a8a44680 100644
--- a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h
+++ b/llvm/include/llvm/Support/LSP/Protocol.h
@@ -23,17 +23,21 @@
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
#define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
-#include "mlir/Support/LLVM.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/LogicalResult.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <bitset>
#include <optional>
#include <string>
#include <utility>
-#include <vector>
-namespace mlir {
+// This file is using the LSP syntax for identifier names which is different
+// from the LLVM coding standard. To avoid the clang-tidy warnings, we're
+// disabling one check here.
+// NOLINTBEGIN(readability-identifier-naming)
+
+namespace llvm {
namespace lsp {
enum class ErrorCode {
@@ -1241,12 +1245,12 @@ struct CodeAction {
llvm::json::Value toJSON(const CodeAction &);
} // namespace lsp
-} // namespace mlir
+} // namespace llvm
namespace llvm {
template <>
-struct format_provider<mlir::lsp::Position> {
- static void format(const mlir::lsp::Position &pos, raw_ostream &os,
+struct format_provider<llvm::lsp::Position> {
+ static void format(const llvm::lsp::Position &pos, raw_ostream &os,
StringRef style) {
assert(style.empty() && "style modifiers for this type are not supported");
os << pos;
@@ -1255,3 +1259,5 @@ struct format_provider<mlir::lsp::Position> {
} // namespace llvm
#endif
+
+// NOLINTEND(readability-identifier-naming)
diff --git a/mlir/include/mlir/Tools/lsp-server-support/Transport.h b/llvm/include/llvm/Support/LSP/Transport.h
similarity index 96%
rename from mlir/include/mlir/Tools/lsp-server-support/Transport.h
rename to llvm/include/llvm/Support/LSP/Transport.h
index 0010a475fedd2..6cb4388a7732d 100644
--- a/mlir/include/mlir/Tools/lsp-server-support/Transport.h
+++ b/llvm/include/llvm/Support/LSP/Transport.h
@@ -15,19 +15,25 @@
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
-#include "mlir/Support/DebugStringHelper.h"
-#include "mlir/Support/LLVM.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Logging.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormatAdapters.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/Support/raw_ostream.h"
-#include <atomic>
+#include <memory>
-namespace mlir {
+namespace llvm {
+// Simple helper function that returns a string as printed from a op.
+template <typename T>
+static std::string debugString(T &&op) {
+ std::string instrStr;
+ llvm::raw_string_ostream os(instrStr);
+ os << op;
+ return os.str();
+ }
namespace lsp {
class MessageHandler;
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 6646af6db5d3c..82a32ba817b10 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -135,6 +135,7 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
endif()
add_subdirectory(BLAKE3)
+add_subdirectory(LSP)
add_llvm_component_library(LLVMSupport
ABIBreak.cpp
@@ -288,6 +289,7 @@ add_llvm_component_library(LLVMSupport
${ALLOCATOR_FILES}
$<TARGET_OBJECTS:LLVMSupportBlake3>
+ $<TARGET_OBJECTS:LLVMSupportLSP>
# System
Atomic.cpp
diff --git a/llvm/lib/Support/LSP/CMakeLists.txt b/llvm/lib/Support/LSP/CMakeLists.txt
new file mode 100644
index 0000000000000..353e649105c17
--- /dev/null
+++ b/llvm/lib/Support/LSP/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_llvm_library(LLVMSupportLSP STATIC
+ Protocol.cpp
+ Transport.cpp
+ Logging.cpp
+)
+
+target_include_directories(LLVMSupportLSP
+ PUBLIC
+ $<BUILD_INTERFACE:${LLVM_MAIN_INCLUDE_DIR}>
+ $<BUILD_INTERFACE:${LLVM_LIBRARY_DIR}/Support/LSP>
+ $<INSTALL_INTERFACE:include> # for installation
+)
+
+target_link_libraries(LLVMSupportLSP
+ PUBLIC
+ LLVMSupport
+)
diff --git a/mlir/lib/Tools/lsp-server-support/Logging.cpp b/llvm/lib/Support/LSP/Logging.cpp
similarity index 92%
rename from mlir/lib/Tools/lsp-server-support/Logging.cpp
rename to llvm/lib/Support/LSP/Logging.cpp
index 373e2165c244d..36916395375cc 100644
--- a/mlir/lib/Tools/lsp-server-support/Logging.cpp
+++ b/llvm/lib/Support/LSP/Logging.cpp
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Tools/lsp-server-support/Logging.h"
+#include "llvm/Support/LSP/Logging.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/raw_ostream.h"
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
void Logger::setLogLevel(Level logLevel) { get().logLevel = logLevel; }
diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.cpp b/llvm/lib/Support/LSP/Protocol.cpp
similarity index 88%
rename from mlir/lib/Tools/lsp-server-support/Protocol.cpp
rename to llvm/lib/Support/LSP/Protocol.cpp
index 98287048355c1..c2494dcf841c0 100644
--- a/mlir/lib/Tools/lsp-server-support/Protocol.cpp
+++ b/llvm/lib/Support/LSP/Protocol.cpp
@@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/ErrorHandling.h"
@@ -19,8 +19,8 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
// Helper that doesn't treat `null` and absent fields as failures.
template <typename T>
@@ -239,7 +239,7 @@ void URIForFile::registerSupportedScheme(StringRef scheme) {
getSupportedSchemes().insert(scheme);
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, URIForFile &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, URIForFile &result,
llvm::json::Path path) {
if (std::optional<StringRef> str = value.getAsString()) {
llvm::Expected<URIForFile> expectedURI = URIForFile::fromURI(*str);
@@ -254,11 +254,11 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value, URIForFile &result,
return false;
}
-llvm::json::Value mlir::lsp::toJSON(const URIForFile &value) {
+llvm::json::Value llvm::lsp::toJSON(const URIForFile &value) {
return value.uri();
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const URIForFile &value) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const URIForFile &value) {
return os << value.uri();
}
@@ -266,7 +266,7 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const URIForFile &value) {
// ClientCapabilities
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
ClientCapabilities &result, llvm::json::Path path) {
const llvm::json::Object *o = value.getAsObject();
if (!o) {
@@ -297,7 +297,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// ClientInfo
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, ClientInfo &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, ClientInfo &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
if (!o || !o.map("name", result.name))
@@ -312,7 +312,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value, ClientInfo &result,
// InitializeParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, TraceLevel &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, TraceLevel &result,
llvm::json::Path path) {
if (std::optional<StringRef> str = value.getAsString()) {
if (*str == "off") {
@@ -331,7 +331,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value, TraceLevel &result,
return false;
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
InitializeParams &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
if (!o)
@@ -348,7 +348,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// TextDocumentItem
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
TextDocumentItem &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("uri", result.uri) &&
@@ -360,11 +360,11 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// TextDocumentIdentifier
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const TextDocumentIdentifier &value) {
+llvm::json::Value llvm::lsp::toJSON(const TextDocumentIdentifier &value) {
return llvm::json::Object{{"uri", value.uri}};
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
TextDocumentIdentifier &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -376,14 +376,14 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
//===----------------------------------------------------------------------===//
llvm::json::Value
-mlir::lsp::toJSON(const VersionedTextDocumentIdentifier &value) {
+llvm::lsp::toJSON(const VersionedTextDocumentIdentifier &value) {
return llvm::json::Object{
{"uri", value.uri},
{"version", value.version},
};
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
VersionedTextDocumentIdentifier &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -394,21 +394,21 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// Position
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, Position &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, Position &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("line", result.line) &&
o.map("character", result.character);
}
-llvm::json::Value mlir::lsp::toJSON(const Position &value) {
+llvm::json::Value llvm::lsp::toJSON(const Position &value) {
return llvm::json::Object{
{"line", value.line},
{"character", value.character},
};
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Position &value) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Position &value) {
return os << value.line << ':' << value.character;
}
@@ -416,20 +416,20 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Position &value) {
// Range
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, Range &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, Range &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("start", result.start) && o.map("end", result.end);
}
-llvm::json::Value mlir::lsp::toJSON(const Range &value) {
+llvm::json::Value llvm::lsp::toJSON(const Range &value) {
return llvm::json::Object{
{"start", value.start},
{"end", value.end},
};
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Range &value) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Range &value) {
return os << value.start << '-' << value.end;
}
@@ -437,20 +437,20 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Range &value) {
// Location
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, Location &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, Location &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("uri", result.uri) && o.map("range", result.range);
}
-llvm::json::Value mlir::lsp::toJSON(const Location &value) {
+llvm::json::Value llvm::lsp::toJSON(const Location &value) {
return llvm::json::Object{
{"uri", value.uri},
{"range", value.range},
};
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Location &value) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Location &value) {
return os << value.range << '@' << value.uri;
}
@@ -458,7 +458,7 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const Location &value) {
// TextDocumentPositionParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
TextDocumentPositionParams &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -470,13 +470,13 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// ReferenceParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
ReferenceContext &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.mapOptional("includeDeclaration", result.includeDeclaration);
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
ReferenceParams &result, llvm::json::Path path) {
TextDocumentPositionParams &base = result;
llvm::json::ObjectMapper o(value, path);
@@ -488,7 +488,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// DidOpenTextDocumentParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DidOpenTextDocumentParams &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -499,7 +499,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// DidCloseTextDocumentParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DidCloseTextDocumentParams &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -540,7 +540,7 @@ LogicalResult TextDocumentContentChangeEvent::applyTo(
return success();
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
TextDocumentContentChangeEvent &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -548,7 +548,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
o.map("rangeLength", result.rangeLength) && o.map("text", result.text);
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DidChangeTextDocumentParams &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -570,11 +570,11 @@ static llvm::StringRef toTextKind(MarkupKind kind) {
llvm_unreachable("Invalid MarkupKind");
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, MarkupKind kind) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, MarkupKind kind) {
return os << toTextKind(kind);
}
-llvm::json::Value mlir::lsp::toJSON(const MarkupContent &mc) {
+llvm::json::Value llvm::lsp::toJSON(const MarkupContent &mc) {
if (mc.value.empty())
return nullptr;
@@ -588,7 +588,7 @@ llvm::json::Value mlir::lsp::toJSON(const MarkupContent &mc) {
// Hover
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const Hover &hover) {
+llvm::json::Value llvm::lsp::toJSON(const Hover &hover) {
llvm::json::Object result{{"contents", toJSON(hover.contents)}};
if (hover.range)
result["range"] = toJSON(*hover.range);
@@ -599,7 +599,7 @@ llvm::json::Value mlir::lsp::toJSON(const Hover &hover) {
// DocumentSymbol
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const DocumentSymbol &symbol) {
+llvm::json::Value llvm::lsp::toJSON(const DocumentSymbol &symbol) {
llvm::json::Object result{{"name", symbol.name},
{"kind", static_cast<int>(symbol.kind)},
{"range", symbol.range},
@@ -616,7 +616,7 @@ llvm::json::Value mlir::lsp::toJSON(const DocumentSymbol &symbol) {
// DocumentSymbolParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DocumentSymbolParams &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("textDocument", result.textDocument);
@@ -626,7 +626,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// DiagnosticRelatedInformation
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DiagnosticRelatedInformation &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -634,7 +634,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
o.map("message", result.message);
}
-llvm::json::Value mlir::lsp::toJSON(const DiagnosticRelatedInformation &info) {
+llvm::json::Value llvm::lsp::toJSON(const DiagnosticRelatedInformation &info) {
return llvm::json::Object{
{"location", info.location},
{"message", info.message},
@@ -645,11 +645,11 @@ llvm::json::Value mlir::lsp::toJSON(const DiagnosticRelatedInformation &info) {
// Diagnostic
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(DiagnosticTag tag) {
+llvm::json::Value llvm::lsp::toJSON(DiagnosticTag tag) {
return static_cast<int>(tag);
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, DiagnosticTag &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, DiagnosticTag &result,
llvm::json::Path path) {
if (std::optional<int64_t> i = value.getAsInteger()) {
result = (DiagnosticTag)*i;
@@ -659,7 +659,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value, DiagnosticTag &result,
return false;
}
-llvm::json::Value mlir::lsp::toJSON(const Diagnostic &diag) {
+llvm::json::Value llvm::lsp::toJSON(const Diagnostic &diag) {
llvm::json::Object result{
{"range", diag.range},
{"severity", (int)diag.severity},
@@ -676,7 +676,7 @@ llvm::json::Value mlir::lsp::toJSON(const Diagnostic &diag) {
return std::move(result);
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, Diagnostic &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, Diagnostic &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
if (!o)
@@ -698,7 +698,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value, Diagnostic &result,
// PublishDiagnosticsParams
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const PublishDiagnosticsParams ¶ms) {
+llvm::json::Value llvm::lsp::toJSON(const PublishDiagnosticsParams ¶ms) {
return llvm::json::Object{
{"uri", params.uri},
{"diagnostics", params.diagnostics},
@@ -710,20 +710,20 @@ llvm::json::Value mlir::lsp::toJSON(const PublishDiagnosticsParams ¶ms) {
// TextEdit
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, TextEdit &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, TextEdit &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("range", result.range) && o.map("newText", result.newText);
}
-llvm::json::Value mlir::lsp::toJSON(const TextEdit &value) {
+llvm::json::Value llvm::lsp::toJSON(const TextEdit &value) {
return llvm::json::Object{
{"range", value.range},
{"newText", value.newText},
};
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const TextEdit &value) {
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const TextEdit &value) {
os << value.range << " => \"";
llvm::printEscapedString(value.newText, os);
return os << '"';
@@ -733,7 +733,7 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const TextEdit &value) {
// CompletionItemKind
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CompletionItemKind &result, llvm::json::Path path) {
if (std::optional<int64_t> intValue = value.getAsInteger()) {
if (*intValue < static_cast<int>(CompletionItemKind::Text) ||
@@ -745,7 +745,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
return false;
}
-CompletionItemKind mlir::lsp::adjustKindToCapability(
+CompletionItemKind llvm::lsp::adjustKindToCapability(
CompletionItemKind kind,
CompletionItemKindBitset &supportedCompletionItemKinds) {
size_t kindVal = static_cast<size_t>(kind);
@@ -767,7 +767,7 @@ CompletionItemKind mlir::lsp::adjustKindToCapability(
}
}
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CompletionItemKindBitset &result,
llvm::json::Path path) {
if (const llvm::json::Array *arrayValue = value.getAsArray()) {
@@ -785,7 +785,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// CompletionItem
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const CompletionItem &value) {
+llvm::json::Value llvm::lsp::toJSON(const CompletionItem &value) {
assert(!value.label.empty() && "completion item label is required");
llvm::json::Object result{{"label", value.label}};
if (value.kind != CompletionItemKind::Missing)
@@ -813,12 +813,12 @@ llvm::json::Value mlir::lsp::toJSON(const CompletionItem &value) {
return std::move(result);
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os,
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os,
const CompletionItem &value) {
return os << value.label << " - " << toJSON(value);
}
-bool mlir::lsp::operator<(const CompletionItem &lhs,
+bool llvm::lsp::operator<(const CompletionItem &lhs,
const CompletionItem &rhs) {
return (lhs.sortText.empty() ? lhs.label : lhs.sortText) <
(rhs.sortText.empty() ? rhs.label : rhs.sortText);
@@ -828,7 +828,7 @@ bool mlir::lsp::operator<(const CompletionItem &lhs,
// CompletionList
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const CompletionList &value) {
+llvm::json::Value llvm::lsp::toJSON(const CompletionList &value) {
return llvm::json::Object{
{"isIncomplete", value.isIncomplete},
{"items", llvm::json::Array(value.items)},
@@ -839,7 +839,7 @@ llvm::json::Value mlir::lsp::toJSON(const CompletionList &value) {
// CompletionContext
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CompletionContext &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
int triggerKind;
@@ -854,7 +854,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// CompletionParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CompletionParams &result, llvm::json::Path path) {
if (!fromJSON(value, static_cast<TextDocumentPositionParams &>(result), path))
return false;
@@ -867,7 +867,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// ParameterInformation
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const ParameterInformation &value) {
+llvm::json::Value llvm::lsp::toJSON(const ParameterInformation &value) {
assert((value.labelOffsets || !value.labelString.empty()) &&
"parameter information label is required");
llvm::json::Object result;
@@ -885,7 +885,7 @@ llvm::json::Value mlir::lsp::toJSON(const ParameterInformation &value) {
// SignatureInformation
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const SignatureInformation &value) {
+llvm::json::Value llvm::lsp::toJSON(const SignatureInformation &value) {
assert(!value.label.empty() && "signature information label is required");
llvm::json::Object result{
{"label", value.label},
@@ -896,7 +896,7 @@ llvm::json::Value mlir::lsp::toJSON(const SignatureInformation &value) {
return std::move(result);
}
-raw_ostream &mlir::lsp::operator<<(raw_ostream &os,
+raw_ostream &llvm::lsp::operator<<(raw_ostream &os,
const SignatureInformation &value) {
return os << value.label << " - " << toJSON(value);
}
@@ -905,7 +905,7 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os,
// SignatureHelp
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const SignatureHelp &value) {
+llvm::json::Value llvm::lsp::toJSON(const SignatureHelp &value) {
assert(value.activeSignature >= 0 &&
"Unexpected negative value for number of active signatures.");
assert(value.activeParameter >= 0 &&
@@ -921,7 +921,7 @@ llvm::json::Value mlir::lsp::toJSON(const SignatureHelp &value) {
// DocumentLinkParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
DocumentLinkParams &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("textDocument", result.textDocument);
@@ -931,7 +931,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// DocumentLink
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const DocumentLink &value) {
+llvm::json::Value llvm::lsp::toJSON(const DocumentLink &value) {
return llvm::json::Object{
{"range", value.range},
{"target", value.target},
@@ -942,7 +942,7 @@ llvm::json::Value mlir::lsp::toJSON(const DocumentLink &value) {
// InlayHintsParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
InlayHintsParams &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("textDocument", result.textDocument) &&
@@ -953,23 +953,23 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// InlayHint
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const InlayHint &value) {
+llvm::json::Value llvm::lsp::toJSON(const InlayHint &value) {
return llvm::json::Object{{"position", value.position},
{"kind", (int)value.kind},
{"label", value.label},
{"paddingLeft", value.paddingLeft},
{"paddingRight", value.paddingRight}};
}
-bool mlir::lsp::operator==(const InlayHint &lhs, const InlayHint &rhs) {
+bool llvm::lsp::operator==(const InlayHint &lhs, const InlayHint &rhs) {
return std::tie(lhs.position, lhs.kind, lhs.label) ==
std::tie(rhs.position, rhs.kind, rhs.label);
}
-bool mlir::lsp::operator<(const InlayHint &lhs, const InlayHint &rhs) {
+bool llvm::lsp::operator<(const InlayHint &lhs, const InlayHint &rhs) {
return std::tie(lhs.position, lhs.kind, lhs.label) <
std::tie(rhs.position, rhs.kind, rhs.label);
}
-llvm::raw_ostream &mlir::lsp::operator<<(llvm::raw_ostream &os,
+llvm::raw_ostream &llvm::lsp::operator<<(llvm::raw_ostream &os,
InlayHintKind value) {
switch (value) {
case InlayHintKind::Parameter:
@@ -984,7 +984,7 @@ llvm::raw_ostream &mlir::lsp::operator<<(llvm::raw_ostream &os,
// CodeActionContext
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CodeActionContext &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
if (!o || !o.map("diagnostics", result.diagnostics))
@@ -997,7 +997,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// CodeActionParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
CodeActionParams &result, llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("textDocument", result.textDocument) &&
@@ -1008,13 +1008,13 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// WorkspaceEdit
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value, WorkspaceEdit &result,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value, WorkspaceEdit &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
return o && o.map("changes", result.changes);
}
-llvm::json::Value mlir::lsp::toJSON(const WorkspaceEdit &value) {
+llvm::json::Value llvm::lsp::toJSON(const WorkspaceEdit &value) {
llvm::json::Object fileChanges;
for (auto &change : value.changes)
fileChanges[change.first] = llvm::json::Array(change.second);
@@ -1029,7 +1029,7 @@ const llvm::StringLiteral CodeAction::kQuickFix = "quickfix";
const llvm::StringLiteral CodeAction::kRefactor = "refactor";
const llvm::StringLiteral CodeAction::kInfo = "info";
-llvm::json::Value mlir::lsp::toJSON(const CodeAction &value) {
+llvm::json::Value llvm::lsp::toJSON(const CodeAction &value) {
llvm::json::Object codeAction{{"title", value.title}};
if (value.kind)
codeAction["kind"] = *value.kind;
diff --git a/mlir/lib/Tools/lsp-server-support/Transport.cpp b/llvm/lib/Support/LSP/Transport.cpp
similarity index 97%
rename from mlir/lib/Tools/lsp-server-support/Transport.cpp
rename to llvm/lib/Support/LSP/Transport.cpp
index 5a098b2841f4b..3f13a9ee0bf8c 100644
--- a/mlir/lib/Tools/lsp-server-support/Transport.cpp
+++ b/llvm/lib/Support/LSP/Transport.cpp
@@ -6,18 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Tools/lsp-server-support/Transport.h"
-#include "mlir/Support/ToolUtilities.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Transport.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Error.h"
#include <optional>
#include <system_error>
#include <utility>
+#include <atomic>
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// Reply
@@ -357,7 +357,7 @@ JSONTransportInputOverFile::readDelimitedMessage(std::string &json) {
StringRef lineRef = line.str().trim();
if (lineRef.starts_with("//")) {
// Found a delimiter for the message.
- if (lineRef == kDefaultSplitMarker)
+ if (lineRef == "// -----")
break;
continue;
}
diff --git a/mlir/include/mlir/Tools/lsp-server-support/SourceMgrUtils.h b/mlir/include/mlir/Tools/lsp-server-support/SourceMgrUtils.h
index 9ed8326a602e6..b4dc5956778d1 100644
--- a/mlir/include/mlir/Tools/lsp-server-support/SourceMgrUtils.h
+++ b/mlir/include/mlir/Tools/lsp-server-support/SourceMgrUtils.h
@@ -14,12 +14,14 @@
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_SOURCEMGRUTILS_H
#define MLIR_TOOLS_LSPSERVERSUPPORT_SOURCEMGRUTILS_H
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
namespace mlir {
namespace lsp {
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// Utils
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Tools/lsp-server-support/CMakeLists.txt b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
index 48a96016b792f..a76c7f3de6809 100644
--- a/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
+++ b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt
@@ -1,9 +1,6 @@
add_mlir_library(MLIRLspServerSupportLib
CompilationDatabase.cpp
- Logging.cpp
- Protocol.cpp
SourceMgrUtils.cpp
- Transport.cpp
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server-support
diff --git a/mlir/lib/Tools/lsp-server-support/CompilationDatabase.cpp b/mlir/lib/Tools/lsp-server-support/CompilationDatabase.cpp
index 9ae0674383a1d..99fa84e824e25 100644
--- a/mlir/lib/Tools/lsp-server-support/CompilationDatabase.cpp
+++ b/mlir/lib/Tools/lsp-server-support/CompilationDatabase.cpp
@@ -8,14 +8,15 @@
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
#include "mlir/Support/FileUtilities.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/Support/YAMLTraits.h"
using namespace mlir;
using namespace mlir::lsp;
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// YamlFileInfo
>From f50695d9ee0e0a5dd880365fffebccfd9a836211 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 15:36:45 +0000
Subject: [PATCH 2/8] Fix MLIR LSP server after move of lsp support
---
.../mlir-lsp-server/MlirLspRegistryFunction.h | 6 +++--
mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp | 5 ++--
mlir/lib/Tools/mlir-lsp-server/LSPServer.h | 6 +++--
mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp | 24 +++++++++----------
mlir/lib/Tools/mlir-lsp-server/MLIRServer.h | 12 ++--------
.../mlir-lsp-server/MlirLspServerMain.cpp | 4 ++--
mlir/lib/Tools/mlir-lsp-server/Protocol.cpp | 8 +++----
mlir/lib/Tools/mlir-lsp-server/Protocol.h | 6 ++---
.../tools/mlir-lsp-server/mlir-lsp-server.cpp | 6 ++---
9 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspRegistryFunction.h b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspRegistryFunction.h
index 4811ecb5e92b7..0d9ba2a0d1607 100644
--- a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspRegistryFunction.h
+++ b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspRegistryFunction.h
@@ -16,14 +16,16 @@
namespace llvm {
template <typename Fn>
class function_ref;
+namespace lsp {
+class URIForFile;
+} // namespace lsp
} // namespace llvm
namespace mlir {
class DialectRegistry;
namespace lsp {
-class URIForFile;
using DialectRegistryFn =
- llvm::function_ref<DialectRegistry &(const URIForFile &uri)>;
+ llvm::function_ref<DialectRegistry &(const llvm::lsp::URIForFile &uri)>;
} // namespace lsp
} // namespace mlir
diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
index 9b937db0c6a7a..fe1bbe4e750a7 100644
--- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
@@ -9,14 +9,15 @@
#include "LSPServer.h"
#include "MLIRServer.h"
#include "Protocol.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Transport.h"
#include <optional>
#define DEBUG_TYPE "mlir-lsp-server"
using namespace mlir;
using namespace mlir::lsp;
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// LSPServer
diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h
index 2c50c6b4ac6f5..d652899633255 100644
--- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h
+++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h
@@ -13,17 +13,19 @@
namespace llvm {
struct LogicalResult;
+namespace lsp {
+class JSONTransport;
+} // namespace lsp
} // namespace llvm
namespace mlir {
namespace lsp {
-class JSONTransport;
class MLIRServer;
/// Run the main loop of the LSP server using the given MLIR server and
/// transport.
llvm::LogicalResult runMlirLSPServer(MLIRServer &server,
- JSONTransport &transport);
+ llvm::lsp::JSONTransport &transport);
} // namespace lsp
} // namespace mlir
diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
index 61987525a5ca5..594e2e3d1c47b 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
@@ -16,10 +16,10 @@
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Parser/Parser.h"
#include "mlir/Support/ToolUtilities.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Base64.h"
+#include "llvm/Support/LSP/Logging.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
@@ -217,15 +217,15 @@ static lsp::Diagnostic getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr,
// Convert the severity for the diagnostic.
switch (diag.getSeverity()) {
- case DiagnosticSeverity::Note:
+ case mlir::DiagnosticSeverity::Note:
llvm_unreachable("expected notes to be handled separately");
- case DiagnosticSeverity::Warning:
+ case mlir::DiagnosticSeverity::Warning:
lspDiag.severity = lsp::DiagnosticSeverity::Warning;
break;
- case DiagnosticSeverity::Error:
+ case mlir::DiagnosticSeverity::Error:
lspDiag.severity = lsp::DiagnosticSeverity::Error;
break;
- case DiagnosticSeverity::Remark:
+ case mlir::DiagnosticSeverity::Remark:
lspDiag.severity = lsp::DiagnosticSeverity::Information;
break;
}
@@ -1283,7 +1283,7 @@ lsp::MLIRServer::~MLIRServer() = default;
void lsp::MLIRServer::addOrUpdateDocument(
const URIForFile &uri, StringRef contents, int64_t version,
- std::vector<Diagnostic> &diagnostics) {
+ std::vector<llvm::lsp::Diagnostic> &diagnostics) {
impl->files[uri.file()] = std::make_unique<MLIRTextFile>(
uri, contents, version, impl->registry_fn, diagnostics);
}
@@ -1298,17 +1298,17 @@ std::optional<int64_t> lsp::MLIRServer::removeDocument(const URIForFile &uri) {
return version;
}
-void lsp::MLIRServer::getLocationsOf(const URIForFile &uri,
- const Position &defPos,
- std::vector<Location> &locations) {
+void lsp::MLIRServer::getLocationsOf(
+ const URIForFile &uri, const Position &defPos,
+ std::vector<llvm::lsp::Location> &locations) {
auto fileIt = impl->files.find(uri.file());
if (fileIt != impl->files.end())
fileIt->second->getLocationsOf(uri, defPos, locations);
}
-void lsp::MLIRServer::findReferencesOf(const URIForFile &uri,
- const Position &pos,
- std::vector<Location> &references) {
+void lsp::MLIRServer::findReferencesOf(
+ const URIForFile &uri, const Position &pos,
+ std::vector<llvm::lsp::Location> &references) {
auto fileIt = impl->files.find(uri.file());
if (fileIt != impl->files.end())
fileIt->second->findReferencesOf(uri, pos, references);
diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
index 85e69e69f6631..d681cbb3de0d4 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
+++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
@@ -9,6 +9,7 @@
#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
#define LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
+#include "Protocol.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Tools/mlir-lsp-server/MlirLspRegistryFunction.h"
#include "llvm/Support/Error.h"
@@ -19,16 +20,7 @@ namespace mlir {
class DialectRegistry;
namespace lsp {
-struct CodeAction;
-struct CodeActionContext;
-struct CompletionList;
-struct Diagnostic;
-struct DocumentSymbol;
-struct Hover;
-struct Location;
-struct MLIRConvertBytecodeResult;
-struct Position;
-struct Range;
+using namespace llvm::lsp;
/// This class implements all of the MLIR related functionality necessary for a
/// language server. This class allows for keeping the MLIR specific logic
diff --git a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
index f1dc32615c6a3..ed20dd5bd62d5 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp
@@ -9,9 +9,9 @@
#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
#include "LSPServer.h"
#include "MLIRServer.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Transport.h"
#include "llvm/Support/Program.h"
using namespace mlir;
diff --git a/mlir/lib/Tools/mlir-lsp-server/Protocol.cpp b/mlir/lib/Tools/mlir-lsp-server/Protocol.cpp
index a56e9a10f03f1..215d49ea44ff3 100644
--- a/mlir/lib/Tools/mlir-lsp-server/Protocol.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/Protocol.cpp
@@ -13,14 +13,14 @@
#include "Protocol.h"
#include "llvm/Support/JSON.h"
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// MLIRConvertBytecodeParams
//===----------------------------------------------------------------------===//
-bool mlir::lsp::fromJSON(const llvm::json::Value &value,
+bool llvm::lsp::fromJSON(const llvm::json::Value &value,
MLIRConvertBytecodeParams &result,
llvm::json::Path path) {
llvm::json::ObjectMapper o(value, path);
@@ -31,6 +31,6 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
// MLIRConvertBytecodeResult
//===----------------------------------------------------------------------===//
-llvm::json::Value mlir::lsp::toJSON(const MLIRConvertBytecodeResult &value) {
+llvm::json::Value llvm::lsp::toJSON(const MLIRConvertBytecodeResult &value) {
return llvm::json::Object{{"output", value.output}};
}
diff --git a/mlir/lib/Tools/mlir-lsp-server/Protocol.h b/mlir/lib/Tools/mlir-lsp-server/Protocol.h
index d910780e1ee92..ed0db4e591d8f 100644
--- a/mlir/lib/Tools/mlir-lsp-server/Protocol.h
+++ b/mlir/lib/Tools/mlir-lsp-server/Protocol.h
@@ -20,9 +20,9 @@
#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
#define LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Protocol.h"
-namespace mlir {
+namespace llvm {
namespace lsp {
//===----------------------------------------------------------------------===//
// MLIRConvertBytecodeParams
@@ -54,6 +54,6 @@ struct MLIRConvertBytecodeResult {
llvm::json::Value toJSON(const MLIRConvertBytecodeResult &value);
} // namespace lsp
-} // namespace mlir
+} // namespace llvm
#endif
diff --git a/mlir/tools/mlir-lsp-server/mlir-lsp-server.cpp b/mlir/tools/mlir-lsp-server/mlir-lsp-server.cpp
index 10d602fdfe728..712237bbbbca6 100644
--- a/mlir/tools/mlir-lsp-server/mlir-lsp-server.cpp
+++ b/mlir/tools/mlir-lsp-server/mlir-lsp-server.cpp
@@ -10,8 +10,8 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/InitAllDialects.h"
#include "mlir/InitAllExtensions.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
+#include "llvm/Support/LSP/Protocol.h"
using namespace mlir;
@@ -37,8 +37,8 @@ int main(int argc, char **argv) {
// Returns the registry, except in testing mode when the URI contains
// "-disable-lsp-registration". Testing for/example of registering dialects
// based on URI.
- auto registryFn = [®istry,
- &empty](const lsp::URIForFile &uri) -> DialectRegistry & {
+ auto registryFn = [®istry, &empty](
+ const llvm::lsp::URIForFile &uri) -> DialectRegistry & {
(void)empty;
#ifdef MLIR_INCLUDE_TESTS
if (uri.uri().contains("-disable-lsp-registration"))
>From 1fb65a1c2ed77f8340fad8c15d9f634b6e46010a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 15:37:20 +0000
Subject: [PATCH 3/8] Fix MLIR PDLL LSP server after move of lsp support
---
.../Tools/mlir-pdll-lsp-server/LSPServer.cpp | 4 ++--
.../Tools/mlir-pdll-lsp-server/LSPServer.h | 6 +++--
.../MlirPdllLspServerMain.cpp | 7 +++---
.../Tools/mlir-pdll-lsp-server/PDLLServer.cpp | 22 +++++++++----------
.../Tools/mlir-pdll-lsp-server/PDLLServer.h | 14 ++----------
.../Tools/mlir-pdll-lsp-server/Protocol.cpp | 1 +
.../lib/Tools/mlir-pdll-lsp-server/Protocol.h | 3 ++-
7 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
index 82542a12a1807..f7a8a127c246b 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
@@ -10,8 +10,8 @@
#include "PDLLServer.h"
#include "Protocol.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Transport.h"
#include <optional>
#define DEBUG_TYPE "pdll-lsp-server"
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h
index 78c4c31100cbc..42c0a5d7b6d2b 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h
@@ -13,17 +13,19 @@
namespace llvm {
struct LogicalResult;
+namespace lsp {
+class JSONTransport;
+} // namespace lsp
} // namespace llvm
namespace mlir {
namespace lsp {
-class JSONTransport;
class PDLLServer;
/// Run the main loop of the LSP server using the given PDLL server and
/// transport.
llvm::LogicalResult runPdllLSPServer(PDLLServer &server,
- JSONTransport &transport);
+ llvm::lsp::JSONTransport &transport);
} // namespace lsp
} // namespace mlir
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.cpp
index 287a131ecd17d..1a0560694b132 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.cpp
@@ -9,9 +9,9 @@
#include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h"
#include "LSPServer.h"
#include "PDLLServer.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Transport.h"
#include "llvm/Support/Program.h"
using namespace mlir;
@@ -72,7 +72,8 @@ LogicalResult mlir::MlirPdllLspServerMain(int argc, char **argv) {
// Configure the transport used for communication.
llvm::sys::ChangeStdinToBinary();
- JSONTransport transport(stdin, llvm::outs(), inputStyle, prettyPrint);
+ llvm::lsp::JSONTransport transport(stdin, llvm::outs(), inputStyle,
+ prettyPrint);
// Configure the servers and start the main language server.
PDLLServer::Options options(compilationDatabases, extraIncludeDirs);
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
index 84f529ae16401..5443dc3ec7da1 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
@@ -23,13 +23,13 @@
#include "mlir/Tools/PDLL/Parser/CodeComplete.h"
#include "mlir/Tools/PDLL/Parser/Parser.h"
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/LSP/Logging.h"
#include "llvm/Support/Path.h"
#include <optional>
@@ -1710,9 +1710,9 @@ lsp::PDLLServer::PDLLServer(const Options &options)
: impl(std::make_unique<Impl>(options)) {}
lsp::PDLLServer::~PDLLServer() = default;
-void lsp::PDLLServer::addDocument(const URIForFile &uri, StringRef contents,
- int64_t version,
- std::vector<Diagnostic> &diagnostics) {
+void lsp::PDLLServer::addDocument(
+ const URIForFile &uri, StringRef contents, int64_t version,
+ std::vector<llvm::lsp::Diagnostic> &diagnostics) {
// Build the set of additional include directories.
std::vector<std::string> additionalIncludeDirs = impl->options.extraDirs;
const auto &fileInfo = impl->compilationDatabase.getFileInfo(uri.file());
@@ -1724,7 +1724,7 @@ void lsp::PDLLServer::addDocument(const URIForFile &uri, StringRef contents,
void lsp::PDLLServer::updateDocument(
const URIForFile &uri, ArrayRef<TextDocumentContentChangeEvent> changes,
- int64_t version, std::vector<Diagnostic> &diagnostics) {
+ int64_t version, std::vector<llvm::lsp::Diagnostic> &diagnostics) {
// Check that we actually have a document for this uri.
auto it = impl->files.find(uri.file());
if (it == impl->files.end())
@@ -1746,17 +1746,17 @@ std::optional<int64_t> lsp::PDLLServer::removeDocument(const URIForFile &uri) {
return version;
}
-void lsp::PDLLServer::getLocationsOf(const URIForFile &uri,
- const Position &defPos,
- std::vector<Location> &locations) {
+void lsp::PDLLServer::getLocationsOf(
+ const URIForFile &uri, const Position &defPos,
+ std::vector<llvm::lsp::Location> &locations) {
auto fileIt = impl->files.find(uri.file());
if (fileIt != impl->files.end())
fileIt->second->getLocationsOf(uri, defPos, locations);
}
-void lsp::PDLLServer::findReferencesOf(const URIForFile &uri,
- const Position &pos,
- std::vector<Location> &references) {
+void lsp::PDLLServer::findReferencesOf(
+ const URIForFile &uri, const Position &pos,
+ std::vector<llvm::lsp::Location> &references) {
auto fileIt = impl->files.find(uri.file());
if (fileIt != impl->files.end())
fileIt->second->findReferencesOf(uri, pos, references);
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
index 134431fa63bf8..981ded0756860 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
@@ -11,6 +11,7 @@
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/LSP/Protocol.h"
#include <memory>
#include <optional>
#include <string>
@@ -18,21 +19,10 @@
namespace mlir {
namespace lsp {
-struct Diagnostic;
+using namespace llvm::lsp;
class CompilationDatabase;
struct PDLLViewOutputResult;
enum class PDLLViewOutputKind;
-struct CompletionList;
-struct DocumentLink;
-struct DocumentSymbol;
-struct Hover;
-struct InlayHint;
-struct Location;
-struct Position;
-struct Range;
-struct SignatureHelp;
-struct TextDocumentContentChangeEvent;
-class URIForFile;
/// This class implements all of the PDLL related functionality necessary for a
/// language server. This class allows for keeping the PDLL specific logic
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
index 0c9896e3ec1b4..ace460536aa1b 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "Protocol.h"
+#include "mlir/Support/LLVM.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/JSON.h"
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.h b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.h
index 0706316631851..68f145597e519 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.h
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.h
@@ -20,10 +20,11 @@
#ifndef LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
#define LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Protocol.h"
namespace mlir {
namespace lsp {
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// PDLLViewOutputParams
//===----------------------------------------------------------------------===//
>From 4645f93f32aeae91f52287d8573379262a5ec6ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 15:38:03 +0000
Subject: [PATCH 4/8] Fix TBLGEN LSP server after move of lsp support
---
mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp | 7 ++++---
mlir/lib/Tools/tblgen-lsp-server/LSPServer.h | 6 ++++--
.../Tools/tblgen-lsp-server/TableGenLspServerMain.cpp | 4 ++--
mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp | 4 ++--
mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h | 9 ++-------
5 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
index bb3c0a77747aa..015d185a7d667 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
@@ -9,13 +9,14 @@
#include "LSPServer.h"
#include "TableGenServer.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
+#include "llvm/Support/LSP/Transport.h"
#include <optional>
using namespace mlir;
using namespace mlir::lsp;
+using namespace llvm::lsp;
//===----------------------------------------------------------------------===//
// LSPServer
diff --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h
index 501a9dada8aab..596688b62f8da 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h
+++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h
@@ -13,17 +13,19 @@
namespace llvm {
struct LogicalResult;
+namespace lsp {
+class JSONTransport;
+} // namespace lsp
} // namespace llvm
namespace mlir {
namespace lsp {
-class JSONTransport;
class TableGenServer;
/// Run the main loop of the LSP server using the given TableGen server and
/// transport.
llvm::LogicalResult runTableGenLSPServer(TableGenServer &server,
- JSONTransport &transport);
+ llvm::lsp::JSONTransport &transport);
} // namespace lsp
} // namespace mlir
diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenLspServerMain.cpp b/mlir/lib/Tools/tblgen-lsp-server/TableGenLspServerMain.cpp
index 21af78c9a506c..b581acbaa6e5b 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/TableGenLspServerMain.cpp
+++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenLspServerMain.cpp
@@ -9,9 +9,9 @@
#include "mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h"
#include "LSPServer.h"
#include "TableGenServer.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Transport.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Transport.h"
#include "llvm/Support/Program.h"
using namespace mlir;
diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
index 5faeeae839f44..8cdb73e26cd39 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
+++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
@@ -10,12 +10,12 @@
#include "mlir/Support/IndentedOstream.h"
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "llvm/Support/Path.h"
#include "llvm/TableGen/Parser.h"
#include "llvm/TableGen/Record.h"
diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
index bdc851024a818..27bfe3dd699cc 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
+++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
@@ -11,6 +11,7 @@
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/LSP/Protocol.h"
#include <memory>
#include <optional>
#include <string>
@@ -18,13 +19,7 @@
namespace mlir {
namespace lsp {
-struct Diagnostic;
-struct DocumentLink;
-struct Hover;
-struct Location;
-struct Position;
-struct TextDocumentContentChangeEvent;
-class URIForFile;
+using namespace llvm::lsp;
/// This class implements all of the TableGen related functionality necessary
/// for a language server. This class allows for keeping the TableGen specific
>From d7e4ada40208e2e036a8c3a3018f1743fe4606af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 15:38:43 +0000
Subject: [PATCH 5/8] Move unittests for LSP server support
---
llvm/unittests/Support/CMakeLists.txt | 2 ++
llvm/unittests/Support/LSP/CMakeLists.txt | 7 +++++++
.../unittests/Support/LSP}/Protocol.cpp | 6 +++---
.../unittests/Support/LSP}/Transport.cpp | 12 ++++++------
mlir/unittests/CMakeLists.txt | 1 -
mlir/unittests/Tools/CMakeLists.txt | 1 -
.../Tools/lsp-server-support/CMakeLists.txt | 7 -------
7 files changed, 18 insertions(+), 18 deletions(-)
create mode 100644 llvm/unittests/Support/LSP/CMakeLists.txt
rename {mlir/unittests/Tools/lsp-server-support => llvm/unittests/Support/LSP}/Protocol.cpp (93%)
rename {mlir/unittests/Tools/lsp-server-support => llvm/unittests/Support/LSP}/Transport.cpp (96%)
delete mode 100644 mlir/unittests/Tools/CMakeLists.txt
delete mode 100644 mlir/unittests/Tools/lsp-server-support/CMakeLists.txt
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index 868c40b13b9b2..85ff21bfda883 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -120,6 +120,8 @@ add_llvm_unittest(SupportTests
intrinsics_gen
)
+add_subdirectory(LSP)
+
target_link_libraries(SupportTests PRIVATE LLVMTestingSupport)
# Disable all warning for AlignOfTest.cpp,
diff --git a/llvm/unittests/Support/LSP/CMakeLists.txt b/llvm/unittests/Support/LSP/CMakeLists.txt
new file mode 100644
index 0000000000000..31c8fe100d2f9
--- /dev/null
+++ b/llvm/unittests/Support/LSP/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_llvm_unittest(LLVMSupportLSPTests
+ Protocol.cpp
+ Transport.cpp
+)
+target_link_libraries(LLVMSupportLSPTests
+ PRIVATE
+ LLVMSupportLSP)
diff --git a/mlir/unittests/Tools/lsp-server-support/Protocol.cpp b/llvm/unittests/Support/LSP/Protocol.cpp
similarity index 93%
rename from mlir/unittests/Tools/lsp-server-support/Protocol.cpp
rename to llvm/unittests/Support/LSP/Protocol.cpp
index 04d7b2fbb440f..43c548c24b38b 100644
--- a/mlir/unittests/Tools/lsp-server-support/Protocol.cpp
+++ b/llvm/unittests/Support/LSP/Protocol.cpp
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "gtest/gtest.h"
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
using namespace testing;
namespace {
diff --git a/mlir/unittests/Tools/lsp-server-support/Transport.cpp b/llvm/unittests/Support/LSP/Transport.cpp
similarity index 96%
rename from mlir/unittests/Tools/lsp-server-support/Transport.cpp
rename to llvm/unittests/Support/LSP/Transport.cpp
index 0303c1cba8bc8..c9b575e5b1316 100644
--- a/mlir/unittests/Tools/lsp-server-support/Transport.cpp
+++ b/llvm/unittests/Support/LSP/Transport.cpp
@@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Tools/lsp-server-support/Transport.h"
-#include "mlir/Tools/lsp-server-support/Logging.h"
-#include "mlir/Tools/lsp-server-support/Protocol.h"
+#include "llvm/Support/LSP/Transport.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-using namespace mlir;
-using namespace mlir::lsp;
+using namespace llvm;
+using namespace llvm::lsp;
using namespace testing;
namespace {
@@ -88,7 +88,7 @@ class TransportInputTest : public Test {
TEST_F(TransportInputTest, RequestWithInvalidParams) {
struct Handler {
void onMethod(const TextDocumentItem ¶ms,
- mlir::lsp::Callback<TextDocumentIdentifier> callback) {}
+ llvm::lsp::Callback<TextDocumentIdentifier> callback) {}
} handler;
getMessageHandler().method("invalid-params-request", &handler,
&Handler::onMethod);
diff --git a/mlir/unittests/CMakeLists.txt b/mlir/unittests/CMakeLists.txt
index c5f0d7e384d01..89332bce5fe05 100644
--- a/mlir/unittests/CMakeLists.txt
+++ b/mlir/unittests/CMakeLists.txt
@@ -18,7 +18,6 @@ add_subdirectory(Support)
add_subdirectory(Rewrite)
add_subdirectory(TableGen)
add_subdirectory(Target)
-add_subdirectory(Tools)
add_subdirectory(Transforms)
if(MLIR_ENABLE_EXECUTION_ENGINE)
diff --git a/mlir/unittests/Tools/CMakeLists.txt b/mlir/unittests/Tools/CMakeLists.txt
deleted file mode 100644
index a97588d928668..0000000000000
--- a/mlir/unittests/Tools/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-add_subdirectory(lsp-server-support)
diff --git a/mlir/unittests/Tools/lsp-server-support/CMakeLists.txt b/mlir/unittests/Tools/lsp-server-support/CMakeLists.txt
deleted file mode 100644
index c539c9bc5101f..0000000000000
--- a/mlir/unittests/Tools/lsp-server-support/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-add_mlir_unittest(MLIRLspServerSupportTests
- Protocol.cpp
- Transport.cpp
-)
-mlir_target_link_libraries(MLIRLspServerSupportTests
- PRIVATE
- MLIRLspServerSupportLib)
>From e84a2eb41af0d742f57bf88dec9dd6c14a2676bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Tue, 26 Aug 2025 16:28:36 +0000
Subject: [PATCH 6/8] Fix linter warnings
---
llvm/include/llvm/Support/LSP/Logging.h | 30 +-
llvm/include/llvm/Support/LSP/Protocol.h | 4 +-
llvm/include/llvm/Support/LSP/Transport.h | 224 ++---
llvm/lib/Support/LSP/Logging.cpp | 22 +-
llvm/lib/Support/LSP/Protocol.cpp | 994 +++++++++++-----------
llvm/lib/Support/LSP/Transport.cpp | 330 +++----
6 files changed, 802 insertions(+), 802 deletions(-)
diff --git a/llvm/include/llvm/Support/LSP/Logging.h b/llvm/include/llvm/Support/LSP/Logging.h
index c9631d0f58fa1..6930a7cf246df 100644
--- a/llvm/include/llvm/Support/LSP/Logging.h
+++ b/llvm/include/llvm/Support/LSP/Logging.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
-#define MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
+#ifndef LLVM_SUPPORT_LSP_LOGGING_H
+#define LLVM_SUPPORT_LSP_LOGGING_H
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
@@ -25,21 +25,21 @@ class Logger {
enum class Level { Debug, Info, Error };
/// Set the severity level of the logger.
- static void setLogLevel(Level logLevel);
+ static void setLogLevel(Level LogLevel);
/// Initiate a log message at various severity levels. These should be called
/// after a call to `initialize`.
template <typename... Ts>
- static void debug(const char *fmt, Ts &&...vals) {
- log(Level::Debug, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
+ static void debug(const char *Fmt, Ts &&...Vals) {
+ log(Level::Debug, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
template <typename... Ts>
- static void info(const char *fmt, Ts &&...vals) {
- log(Level::Info, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
+ static void info(const char *Fmt, Ts &&...Vals) {
+ log(Level::Info, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
template <typename... Ts>
- static void error(const char *fmt, Ts &&...vals) {
- log(Level::Error, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
+ static void error(const char *Fmt, Ts &&...Vals) {
+ log(Level::Error, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
private:
@@ -49,16 +49,16 @@ class Logger {
static Logger &get();
/// Start a log message with the given severity level.
- static void log(Level logLevel, const char *fmt,
- const llvm::formatv_object_base &message);
+ static void log(Level LogLevel, const char *Fmt,
+ const llvm::formatv_object_base &Message);
/// The minimum logging level. Messages with lower level are ignored.
- Level logLevel = Level::Error;
+ Level LogLevel = Level::Error;
/// A mutex used to guard logging.
- std::mutex mutex;
+ std::mutex Mutex;
};
} // namespace lsp
-} // namespace mlir
+} // namespace llvm
-#endif // MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
+#endif // LLVM_SUPPORT_LSP_LOGGING_H
diff --git a/llvm/include/llvm/Support/LSP/Protocol.h b/llvm/include/llvm/Support/LSP/Protocol.h
index 3da13a8a44680..a01a1a0a00ef2 100644
--- a/llvm/include/llvm/Support/LSP/Protocol.h
+++ b/llvm/include/llvm/Support/LSP/Protocol.h
@@ -20,8 +20,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
-#define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
+#ifndef LLVM_SUPPORT_LSP_PROTOCOL_H
+#define LLVM_SUPPORT_LSP_PROTOCOL_H
#include "llvm/Support/JSON.h"
#include "llvm/Support/LogicalResult.h"
diff --git a/llvm/include/llvm/Support/LSP/Transport.h b/llvm/include/llvm/Support/LSP/Transport.h
index 6cb4388a7732d..45a0b6a78e304 100644
--- a/llvm/include/llvm/Support/LSP/Transport.h
+++ b/llvm/include/llvm/Support/LSP/Transport.h
@@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
-#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
+#ifndef LLVM_SUPPORT_LSP_TRANSPORT_H
+#define LLVM_SUPPORT_LSP_TRANSPORT_H
#include "llvm/Support/LSP/Logging.h"
#include "llvm/ADT/FunctionExtras.h"
@@ -27,13 +27,12 @@
namespace llvm {
// Simple helper function that returns a string as printed from a op.
-template <typename T>
-static std::string debugString(T &&op) {
- std::string instrStr;
- llvm::raw_string_ostream os(instrStr);
- os << op;
- return os.str();
- }
+template <typename T> static std::string debugString(T &&Op) {
+ std::string InstrStr;
+ llvm::raw_string_ostream Os(InstrStr);
+ Os << Op;
+ return Os.str();
+}
namespace lsp {
class MessageHandler;
@@ -52,79 +51,79 @@ enum JSONStreamStyle {
/// An abstract class used by the JSONTransport to read JSON message.
class JSONTransportInput {
public:
- explicit JSONTransportInput(JSONStreamStyle style = JSONStreamStyle::Standard)
- : style(style) {}
+ explicit JSONTransportInput(JSONStreamStyle Style = JSONStreamStyle::Standard)
+ : Style(Style) {}
virtual ~JSONTransportInput() = default;
virtual bool hasError() const = 0;
virtual bool isEndOfInput() const = 0;
/// Read in a message from the input stream.
- LogicalResult readMessage(std::string &json) {
- return style == JSONStreamStyle::Delimited ? readDelimitedMessage(json)
- : readStandardMessage(json);
+ LogicalResult readMessage(std::string &Json) {
+ return Style == JSONStreamStyle::Delimited ? readDelimitedMessage(Json)
+ : readStandardMessage(Json);
}
- virtual LogicalResult readDelimitedMessage(std::string &json) = 0;
- virtual LogicalResult readStandardMessage(std::string &json) = 0;
+ virtual LogicalResult readDelimitedMessage(std::string &Json) = 0;
+ virtual LogicalResult readStandardMessage(std::string &Json) = 0;
private:
/// The JSON stream style to use.
- JSONStreamStyle style;
+ JSONStreamStyle Style;
};
/// Concrete implementation of the JSONTransportInput that reads from a file.
class JSONTransportInputOverFile : public JSONTransportInput {
public:
explicit JSONTransportInputOverFile(
- std::FILE *in, JSONStreamStyle style = JSONStreamStyle::Standard)
- : JSONTransportInput(style), in(in) {}
+ std::FILE *In, JSONStreamStyle Style = JSONStreamStyle::Standard)
+ : JSONTransportInput(Style), In(In) {}
- bool hasError() const final { return ferror(in); }
- bool isEndOfInput() const final { return feof(in); }
+ bool hasError() const final { return ferror(In); }
+ bool isEndOfInput() const final { return feof(In); }
- LogicalResult readDelimitedMessage(std::string &json) final;
- LogicalResult readStandardMessage(std::string &json) final;
+ LogicalResult readDelimitedMessage(std::string &Json) final;
+ LogicalResult readStandardMessage(std::string &Json) final;
private:
- std::FILE *in;
+ std::FILE *In;
};
/// A transport class that performs the JSON-RPC communication with the LSP
/// client.
class JSONTransport {
public:
- JSONTransport(std::unique_ptr<JSONTransportInput> in, raw_ostream &out,
- bool prettyOutput = false)
- : in(std::move(in)), out(out), prettyOutput(prettyOutput) {}
+ JSONTransport(std::unique_ptr<JSONTransportInput> In, raw_ostream &Out,
+ bool PrettyOutput = false)
+ : In(std::move(In)), Out(Out), PrettyOutput(PrettyOutput) {}
- JSONTransport(std::FILE *in, raw_ostream &out,
- JSONStreamStyle style = JSONStreamStyle::Standard,
- bool prettyOutput = false)
- : in(std::make_unique<JSONTransportInputOverFile>(in, style)), out(out),
- prettyOutput(prettyOutput) {}
+ JSONTransport(std::FILE *In, raw_ostream &Out,
+ JSONStreamStyle Style = JSONStreamStyle::Standard,
+ bool PrettyOutput = false)
+ : In(std::make_unique<JSONTransportInputOverFile>(In, Style)), Out(Out),
+ PrettyOutput(PrettyOutput) {}
/// The following methods are used to send a message to the LSP client.
- void notify(StringRef method, llvm::json::Value params);
- void call(StringRef method, llvm::json::Value params, llvm::json::Value id);
- void reply(llvm::json::Value id, llvm::Expected<llvm::json::Value> result);
+ void notify(StringRef Method, llvm::json::Value Params);
+ void call(StringRef Method, llvm::json::Value Params, llvm::json::Value Id);
+ void reply(llvm::json::Value Id, llvm::Expected<llvm::json::Value> Result);
/// Start executing the JSON-RPC transport.
- llvm::Error run(MessageHandler &handler);
+ llvm::Error run(MessageHandler &Handler);
private:
/// Dispatches the given incoming json message to the message handler.
- bool handleMessage(llvm::json::Value msg, MessageHandler &handler);
+ bool handleMessage(llvm::json::Value Msg, MessageHandler &Handler);
/// Writes the given message to the output stream.
- void sendMessage(llvm::json::Value msg);
+ void sendMessage(llvm::json::Value Msg);
private:
/// The input to read a message from.
- std::unique_ptr<JSONTransportInput> in;
- SmallVector<char, 0> outputBuffer;
+ std::unique_ptr<JSONTransportInput> In;
+ SmallVector<char, 0> OutputBuffer;
/// The output file stream.
- raw_ostream &out;
+ raw_ostream &Out;
/// If the output JSON should be formatted for easier readability.
- bool prettyOutput;
+ bool PrettyOutput;
};
//===----------------------------------------------------------------------===//
@@ -145,7 +144,7 @@ using OutgoingNotification = llvm::unique_function<void(const T &)>;
/// the client.
template <typename T>
using OutgoingRequest =
- llvm::unique_function<void(const T &, llvm::json::Value id)>;
+ llvm::unique_function<void(const T &, llvm::json::Value Id)>;
/// An `OutgoingRequestCallback` is invoked when an outgoing request to the
/// client receives a response in turn. It is passed the original request's ID,
@@ -157,70 +156,71 @@ using OutgoingRequestCallback =
/// A handler used to process the incoming transport messages.
class MessageHandler {
public:
- MessageHandler(JSONTransport &transport) : transport(transport) {}
+ MessageHandler(JSONTransport &Transport) : Transport(Transport) {}
- bool onNotify(StringRef method, llvm::json::Value value);
- bool onCall(StringRef method, llvm::json::Value params, llvm::json::Value id);
- bool onReply(llvm::json::Value id, llvm::Expected<llvm::json::Value> result);
+ bool onNotify(StringRef Method, llvm::json::Value Value);
+ bool onCall(StringRef Method, llvm::json::Value Params, llvm::json::Value Id);
+ bool onReply(llvm::json::Value Id, llvm::Expected<llvm::json::Value> Result);
template <typename T>
- static llvm::Expected<T> parse(const llvm::json::Value &raw,
- StringRef payloadName, StringRef payloadKind) {
- T result;
- llvm::json::Path::Root root;
- if (fromJSON(raw, result, root))
- return std::move(result);
+ static llvm::Expected<T> parse(const llvm::json::Value &Raw,
+ StringRef PayloadName, StringRef PayloadKind) {
+ T Result;
+ llvm::json::Path::Root Root;
+ if (fromJSON(Raw, Result, Root))
+ return std::move(Result);
// Dump the relevant parts of the broken message.
- std::string context;
- llvm::raw_string_ostream os(context);
- root.printErrorContext(raw, os);
+ std::string Context;
+ llvm::raw_string_ostream Os(Context);
+ Root.printErrorContext(Raw, Os);
// Report the error (e.g. to the client).
return llvm::make_error<LSPError>(
- llvm::formatv("failed to decode {0} {1}: {2}", payloadName, payloadKind,
- fmt_consume(root.getError())),
+ llvm::formatv("failed to decode {0} {1}: {2}", PayloadName, PayloadKind,
+ fmt_consume(Root.getError())),
ErrorCode::InvalidParams);
}
template <typename Param, typename Result, typename ThisT>
- void method(llvm::StringLiteral method, ThisT *thisPtr,
- void (ThisT::*handler)(const Param &, Callback<Result>)) {
- methodHandlers[method] = [method, handler,
- thisPtr](llvm::json::Value rawParams,
- Callback<llvm::json::Value> reply) {
- llvm::Expected<Param> param = parse<Param>(rawParams, method, "request");
- if (!param)
- return reply(param.takeError());
- (thisPtr->*handler)(*param, std::move(reply));
+ void method(llvm::StringLiteral Method, ThisT *ThisPtr,
+ void (ThisT::*Handler)(const Param &, Callback<Result>)) {
+ MethodHandlers[Method] = [Method, Handler,
+ ThisPtr](llvm::json::Value RawParams,
+ Callback<llvm::json::Value> Reply) {
+ llvm::Expected<Param> Parameter =
+ parse<Param>(RawParams, Method, "request");
+ if (!Parameter)
+ return Reply(Parameter.takeError());
+ (ThisPtr->*Handler)(*Parameter, std::move(Reply));
};
}
template <typename Param, typename ThisT>
- void notification(llvm::StringLiteral method, ThisT *thisPtr,
- void (ThisT::*handler)(const Param &)) {
- notificationHandlers[method] = [method, handler,
- thisPtr](llvm::json::Value rawParams) {
- llvm::Expected<Param> param =
- parse<Param>(rawParams, method, "notification");
- if (!param) {
- return llvm::consumeError(
- llvm::handleErrors(param.takeError(), [](const LSPError &lspError) {
+ void notification(llvm::StringLiteral Method, ThisT *ThisPtr,
+ void (ThisT::*Handler)(const Param &)) {
+ NotificationHandlers[Method] = [Method, Handler,
+ ThisPtr](llvm::json::Value RawParams) {
+ llvm::Expected<Param> Parameter =
+ parse<Param>(RawParams, Method, "notification");
+ if (!Parameter) {
+ return llvm::consumeError(llvm::handleErrors(
+ Parameter.takeError(), [](const LSPError &LspError) {
Logger::error("JSON parsing error: {0}",
- lspError.message.c_str());
+ LspError.message.c_str());
}));
}
- (thisPtr->*handler)(*param);
+ (ThisPtr->*Handler)(*Parameter);
};
}
/// Create an OutgoingNotification object used for the given method.
template <typename T>
- OutgoingNotification<T> outgoingNotification(llvm::StringLiteral method) {
- return [&, method](const T ¶ms) {
- std::lock_guard<std::mutex> transportLock(transportOutputMutex);
- Logger::info("--> {0}", method);
- transport.notify(method, llvm::json::Value(params));
+ OutgoingNotification<T> outgoingNotification(llvm::StringLiteral Method) {
+ return [&, Method](const T &Params) {
+ std::lock_guard<std::mutex> TransportLock(TransportOutputMutex);
+ Logger::info("--> {0}", Method);
+ Transport.notify(Method, llvm::json::Value(Params));
};
}
@@ -230,33 +230,33 @@ class MessageHandler {
/// is invoked.
template <typename Param, typename Result>
OutgoingRequest<Param>
- outgoingRequest(llvm::StringLiteral method,
- OutgoingRequestCallback<Result> callback) {
- return [&, method, callback](const Param ¶m, llvm::json::Value id) {
- auto callbackWrapper = [method, callback = std::move(callback)](
- llvm::json::Value id,
- llvm::Expected<llvm::json::Value> value) {
- if (!value)
- return callback(std::move(id), value.takeError());
-
- std::string responseName = llvm::formatv("reply:{0}({1})", method, id);
- llvm::Expected<Result> result =
- parse<Result>(*value, responseName, "response");
- if (!result)
- return callback(std::move(id), result.takeError());
-
- return callback(std::move(id), *result);
+ outgoingRequest(llvm::StringLiteral Method,
+ OutgoingRequestCallback<Result> Callback) {
+ return [&, Method, Callback](const Param &Parameter, llvm::json::Value Id) {
+ auto CallbackWrapper = [Method, Callback = std::move(Callback)](
+ llvm::json::Value Id,
+ llvm::Expected<llvm::json::Value> Value) {
+ if (!Value)
+ return Callback(std::move(Id), Value.takeError());
+
+ std::string ResponseName = llvm::formatv("reply:{0}({1})", Method, Id);
+ llvm::Expected<Result> ParseResult =
+ parse<Result>(*Value, ResponseName, "response");
+ if (!ParseResult)
+ return Callback(std::move(Id), ParseResult.takeError());
+
+ return Callback(std::move(Id), *ParseResult);
};
{
- std::lock_guard<std::mutex> lock(responseHandlersMutex);
- responseHandlers.insert(
- {debugString(id), std::make_pair(method.str(), callbackWrapper)});
+ std::lock_guard<std::mutex> Lock(ResponseHandlersMutex);
+ ResponseHandlers.insert(
+ {debugString(Id), std::make_pair(Method.str(), CallbackWrapper)});
}
- std::lock_guard<std::mutex> transportLock(transportOutputMutex);
- Logger::info("--> {0}({1})", method, id);
- transport.call(method, llvm::json::Value(param), id);
+ std::lock_guard<std::mutex> TransportLock(TransportOutputMutex);
+ Logger::info("--> {0}({1})", Method, Id);
+ Transport.call(Method, llvm::json::Value(Parameter), Id);
};
}
@@ -264,26 +264,26 @@ class MessageHandler {
template <typename HandlerT>
using HandlerMap = llvm::StringMap<llvm::unique_function<HandlerT>>;
- HandlerMap<void(llvm::json::Value)> notificationHandlers;
+ HandlerMap<void(llvm::json::Value)> NotificationHandlers;
HandlerMap<void(llvm::json::Value, Callback<llvm::json::Value>)>
- methodHandlers;
+ MethodHandlers;
/// A pair of (1) the original request's method name, and (2) the callback
/// function to be invoked for responses.
using ResponseHandlerTy =
std::pair<std::string, OutgoingRequestCallback<llvm::json::Value>>;
/// A mapping from request/response ID to response handler.
- llvm::StringMap<ResponseHandlerTy> responseHandlers;
+ llvm::StringMap<ResponseHandlerTy> ResponseHandlers;
/// Mutex to guard insertion into the response handler map.
- std::mutex responseHandlersMutex;
+ std::mutex ResponseHandlersMutex;
- JSONTransport &transport;
+ JSONTransport &Transport;
/// Mutex to guard sending output messages to the transport.
- std::mutex transportOutputMutex;
+ std::mutex TransportOutputMutex;
};
} // namespace lsp
-} // namespace mlir
+} // namespace llvm
#endif
diff --git a/llvm/lib/Support/LSP/Logging.cpp b/llvm/lib/Support/LSP/Logging.cpp
index 36916395375cc..b36621ae1c6c6 100644
--- a/llvm/lib/Support/LSP/Logging.cpp
+++ b/llvm/lib/Support/LSP/Logging.cpp
@@ -13,29 +13,29 @@
using namespace llvm;
using namespace llvm::lsp;
-void Logger::setLogLevel(Level logLevel) { get().logLevel = logLevel; }
+void Logger::setLogLevel(Level LogLevel) { get().LogLevel = LogLevel; }
Logger &Logger::get() {
- static Logger logger;
- return logger;
+ static Logger Logger;
+ return Logger;
}
-void Logger::log(Level logLevel, const char *fmt,
- const llvm::formatv_object_base &message) {
- Logger &logger = get();
+void Logger::log(Level LogLevel, const char *Fmt,
+ const llvm::formatv_object_base &Message) {
+ Logger &Logger = get();
// Ignore messages with log levels below the current setting in the logger.
- if (logLevel < logger.logLevel)
+ if (LogLevel < Logger.LogLevel)
return;
// An indicator character for each log level.
- const char *logLevelIndicators = "DIE";
+ const char *LogLevelIndicators = "DIE";
// Format the message and print to errs.
- llvm::sys::TimePoint<> timestamp = std::chrono::system_clock::now();
- std::lock_guard<std::mutex> logGuard(logger.mutex);
+ llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
+ std::lock_guard<std::mutex> LogGuard(Logger.Mutex);
llvm::errs() << llvm::formatv(
"{0}[{1:%H:%M:%S.%L}] {2}\n",
- logLevelIndicators[static_cast<unsigned>(logLevel)], timestamp, message);
+ LogLevelIndicators[static_cast<unsigned>(LogLevel)], Timestamp, Message);
llvm::errs().flush();
}
diff --git a/llvm/lib/Support/LSP/Protocol.cpp b/llvm/lib/Support/LSP/Protocol.cpp
index c2494dcf841c0..f22126345a435 100644
--- a/llvm/lib/Support/LSP/Protocol.cpp
+++ b/llvm/lib/Support/LSP/Protocol.cpp
@@ -24,17 +24,17 @@ using namespace llvm::lsp;
// Helper that doesn't treat `null` and absent fields as failures.
template <typename T>
-static bool mapOptOrNull(const llvm::json::Value ¶ms,
- llvm::StringLiteral prop, T &out,
- llvm::json::Path path) {
- const llvm::json::Object *o = params.getAsObject();
- assert(o);
+static bool mapOptOrNull(const llvm::json::Value &Params,
+ llvm::StringLiteral Prop, T &Out,
+ llvm::json::Path Path) {
+ const llvm::json::Object *O = Params.getAsObject();
+ assert(O);
// Field is missing or null.
- auto *v = o->get(prop);
- if (!v || v->getAsNull())
+ auto *V = O->get(Prop);
+ if (!V || V->getAsNull())
return true;
- return fromJSON(*v, out, path.field(prop));
+ return fromJSON(*V, Out, Path.field(Prop));
}
//===----------------------------------------------------------------------===//
@@ -47,22 +47,22 @@ char LSPError::ID;
// URIForFile
//===----------------------------------------------------------------------===//
-static bool isWindowsPath(StringRef path) {
- return path.size() > 1 && llvm::isAlpha(path[0]) && path[1] == ':';
+static bool isWindowsPath(StringRef Path) {
+ return Path.size() > 1 && llvm::isAlpha(Path[0]) && Path[1] == ':';
}
-static bool isNetworkPath(StringRef path) {
- return path.size() > 2 && path[0] == path[1] &&
- llvm::sys::path::is_separator(path[0]);
+static bool isNetworkPath(StringRef Path) {
+ return Path.size() > 2 && Path[0] == Path[1] &&
+ llvm::sys::path::is_separator(Path[0]);
}
-static bool shouldEscapeInURI(unsigned char c) {
+static bool shouldEscapeInURI(unsigned char C) {
// Unreserved characters.
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9'))
+ if ((C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
+ (C >= '0' && C <= '9'))
return false;
- switch (c) {
+ switch (C) {
case '-':
case '_':
case '.':
@@ -80,215 +80,215 @@ static bool shouldEscapeInURI(unsigned char c) {
/// - Unreserved characters are not escaped.
/// - Reserved characters always escaped with exceptions like '/'.
/// - All other characters are escaped.
-static void percentEncode(StringRef content, std::string &out) {
- for (unsigned char c : content) {
- if (shouldEscapeInURI(c)) {
- out.push_back('%');
- out.push_back(llvm::hexdigit(c / 16));
- out.push_back(llvm::hexdigit(c % 16));
+static void percentEncode(StringRef Content, std::string &Out) {
+ for (unsigned char C : Content) {
+ if (shouldEscapeInURI(C)) {
+ Out.push_back('%');
+ Out.push_back(llvm::hexdigit(C / 16));
+ Out.push_back(llvm::hexdigit(C % 16));
} else {
- out.push_back(c);
+ Out.push_back(C);
}
}
}
/// Decodes a string according to percent-encoding.
-static std::string percentDecode(StringRef content) {
- std::string result;
- for (auto i = content.begin(), e = content.end(); i != e; ++i) {
- if (*i != '%') {
- result += *i;
+static std::string percentDecode(StringRef Content) {
+ std::string Result;
+ for (auto I = Content.begin(), E = Content.end(); I != E; ++I) {
+ if (*I != '%') {
+ Result += *I;
continue;
}
- if (*i == '%' && i + 2 < content.end() && llvm::isHexDigit(*(i + 1)) &&
- llvm::isHexDigit(*(i + 2))) {
- result.push_back(llvm::hexFromNibbles(*(i + 1), *(i + 2)));
- i += 2;
+ if (*I == '%' && I + 2 < Content.end() && llvm::isHexDigit(*(I + 1)) &&
+ llvm::isHexDigit(*(I + 2))) {
+ Result.push_back(llvm::hexFromNibbles(*(I + 1), *(I + 2)));
+ I += 2;
} else {
- result.push_back(*i);
+ Result.push_back(*I);
}
}
- return result;
+ return Result;
}
/// Return the set containing the supported URI schemes.
static StringSet<> &getSupportedSchemes() {
- static StringSet<> schemes({"file", "test"});
- return schemes;
+ static StringSet<> Schemes({"file", "test"});
+ return Schemes;
}
/// Returns true if the given scheme is structurally valid, i.e. it does not
/// contain any invalid scheme characters. This does not check that the scheme
/// is actually supported.
-static bool isStructurallyValidScheme(StringRef scheme) {
- if (scheme.empty())
+static bool isStructurallyValidScheme(StringRef Scheme) {
+ if (Scheme.empty())
return false;
- if (!llvm::isAlpha(scheme[0]))
+ if (!llvm::isAlpha(Scheme[0]))
return false;
- return llvm::all_of(llvm::drop_begin(scheme), [](char c) {
- return llvm::isAlnum(c) || c == '+' || c == '.' || c == '-';
+ return llvm::all_of(llvm::drop_begin(Scheme), [](char C) {
+ return llvm::isAlnum(C) || C == '+' || C == '.' || C == '-';
});
}
-static llvm::Expected<std::string> uriFromAbsolutePath(StringRef absolutePath,
- StringRef scheme) {
- std::string body;
- StringRef authority;
- StringRef root = llvm::sys::path::root_name(absolutePath);
- if (isNetworkPath(root)) {
+static llvm::Expected<std::string> uriFromAbsolutePath(StringRef AbsolutePath,
+ StringRef Scheme) {
+ std::string Body;
+ StringRef Authority;
+ StringRef Root = llvm::sys::path::root_name(AbsolutePath);
+ if (isNetworkPath(Root)) {
// Windows UNC paths e.g. \\server\share => file://server/share
- authority = root.drop_front(2);
- absolutePath.consume_front(root);
- } else if (isWindowsPath(root)) {
+ Authority = Root.drop_front(2);
+ AbsolutePath.consume_front(Root);
+ } else if (isWindowsPath(Root)) {
// Windows paths e.g. X:\path => file:///X:/path
- body = "/";
+ Body = "/";
}
- body += llvm::sys::path::convert_to_slash(absolutePath);
+ Body += llvm::sys::path::convert_to_slash(AbsolutePath);
- std::string uri = scheme.str() + ":";
- if (authority.empty() && body.empty())
- return uri;
+ std::string Uri = Scheme.str() + ":";
+ if (Authority.empty() && Body.empty())
+ return Uri;
// If authority if empty, we only print body if it starts with "/"; otherwise,
// the URI is invalid.
- if (!authority.empty() || StringRef(body).starts_with("/")) {
- uri.append("//");
- percentEncode(authority, uri);
+ if (!Authority.empty() || StringRef(Body).starts_with("/")) {
+ Uri.append("//");
+ percentEncode(Authority, Uri);
}
- percentEncode(body, uri);
- return uri;
+ percentEncode(Body, Uri);
+ return Uri;
}
-static llvm::Expected<std::string> getAbsolutePath(StringRef authority,
- StringRef body) {
- if (!body.starts_with("/"))
+static llvm::Expected<std::string> getAbsolutePath(StringRef Authority,
+ StringRef Body) {
+ if (!Body.starts_with("/"))
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"File scheme: expect body to be an absolute path starting "
"with '/': " +
- body);
- SmallString<128> path;
- if (!authority.empty()) {
+ Body);
+ SmallString<128> Path;
+ if (!Authority.empty()) {
// Windows UNC paths e.g. file://server/share => \\server\share
- ("//" + authority).toVector(path);
- } else if (isWindowsPath(body.substr(1))) {
+ ("//" + Authority).toVector(Path);
+ } else if (isWindowsPath(Body.substr(1))) {
// Windows paths e.g. file:///X:/path => X:\path
- body.consume_front("/");
+ Body.consume_front("/");
}
- path.append(body);
- llvm::sys::path::native(path);
- return std::string(path);
+ Path.append(Body);
+ llvm::sys::path::native(Path);
+ return std::string(Path);
}
-static llvm::Expected<std::string> parseFilePathFromURI(StringRef origUri) {
- StringRef uri = origUri;
+static llvm::Expected<std::string> parseFilePathFromURI(StringRef OrigUri) {
+ StringRef Uri = OrigUri;
// Decode the scheme of the URI.
- size_t pos = uri.find(':');
- if (pos == StringRef::npos)
+ size_t Pos = Uri.find(':');
+ if (Pos == StringRef::npos)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Scheme must be provided in URI: " +
- origUri);
- StringRef schemeStr = uri.substr(0, pos);
- std::string uriScheme = percentDecode(schemeStr);
- if (!isStructurallyValidScheme(uriScheme))
+ OrigUri);
+ StringRef SchemeStr = Uri.substr(0, Pos);
+ std::string UriScheme = percentDecode(SchemeStr);
+ if (!isStructurallyValidScheme(UriScheme))
return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Invalid scheme: " + schemeStr +
- " (decoded: " + uriScheme + ")");
- uri = uri.substr(pos + 1);
+ "Invalid scheme: " + SchemeStr +
+ " (decoded: " + UriScheme + ")");
+ Uri = Uri.substr(Pos + 1);
// Decode the authority of the URI.
- std::string uriAuthority;
- if (uri.consume_front("//")) {
- pos = uri.find('/');
- uriAuthority = percentDecode(uri.substr(0, pos));
- uri = uri.substr(pos);
+ std::string UriAuthority;
+ if (Uri.consume_front("//")) {
+ Pos = Uri.find('/');
+ UriAuthority = percentDecode(Uri.substr(0, Pos));
+ Uri = Uri.substr(Pos);
}
// Decode the body of the URI.
- std::string uriBody = percentDecode(uri);
+ std::string UriBody = percentDecode(Uri);
// Compute the absolute path for this uri.
- if (!getSupportedSchemes().contains(uriScheme)) {
+ if (!getSupportedSchemes().contains(UriScheme)) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "unsupported URI scheme `" + uriScheme +
+ "unsupported URI scheme `" + UriScheme +
"' for workspace files");
}
- return getAbsolutePath(uriAuthority, uriBody);
+ return getAbsolutePath(UriAuthority, UriBody);
}
-llvm::Expected<URIForFile> URIForFile::fromURI(StringRef uri) {
- llvm::Expected<std::string> filePath = parseFilePathFromURI(uri);
- if (!filePath)
- return filePath.takeError();
- return URIForFile(std::move(*filePath), uri.str());
+llvm::Expected<URIForFile> URIForFile::fromURI(StringRef Uri) {
+ llvm::Expected<std::string> FilePath = parseFilePathFromURI(Uri);
+ if (!FilePath)
+ return FilePath.takeError();
+ return URIForFile(std::move(*FilePath), Uri.str());
}
-llvm::Expected<URIForFile> URIForFile::fromFile(StringRef absoluteFilepath,
- StringRef scheme) {
- llvm::Expected<std::string> uri =
- uriFromAbsolutePath(absoluteFilepath, scheme);
- if (!uri)
- return uri.takeError();
- return fromURI(*uri);
+llvm::Expected<URIForFile> URIForFile::fromFile(StringRef AbsoluteFilepath,
+ StringRef Scheme) {
+ llvm::Expected<std::string> Uri =
+ uriFromAbsolutePath(AbsoluteFilepath, Scheme);
+ if (!Uri)
+ return Uri.takeError();
+ return fromURI(*Uri);
}
StringRef URIForFile::scheme() const { return uri().split(':').first; }
-void URIForFile::registerSupportedScheme(StringRef scheme) {
- getSupportedSchemes().insert(scheme);
+void URIForFile::registerSupportedScheme(StringRef Scheme) {
+ getSupportedSchemes().insert(Scheme);
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, URIForFile &result,
- llvm::json::Path path) {
- if (std::optional<StringRef> str = value.getAsString()) {
- llvm::Expected<URIForFile> expectedURI = URIForFile::fromURI(*str);
- if (!expectedURI) {
- path.report("unresolvable URI");
- consumeError(expectedURI.takeError());
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, URIForFile &Result,
+ llvm::json::Path Path) {
+ if (std::optional<StringRef> Str = Value.getAsString()) {
+ llvm::Expected<URIForFile> ExpectedUri = URIForFile::fromURI(*Str);
+ if (!ExpectedUri) {
+ Path.report("unresolvable URI");
+ consumeError(ExpectedUri.takeError());
return false;
}
- result = std::move(*expectedURI);
+ Result = std::move(*ExpectedUri);
return true;
}
return false;
}
-llvm::json::Value llvm::lsp::toJSON(const URIForFile &value) {
- return value.uri();
+llvm::json::Value llvm::lsp::toJSON(const URIForFile &Value) {
+ return Value.uri();
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const URIForFile &value) {
- return os << value.uri();
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, const URIForFile &Value) {
+ return Os << Value.uri();
}
//===----------------------------------------------------------------------===//
// ClientCapabilities
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- ClientCapabilities &result, llvm::json::Path path) {
- const llvm::json::Object *o = value.getAsObject();
- if (!o) {
- path.report("expected object");
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ ClientCapabilities &Result, llvm::json::Path Path) {
+ const llvm::json::Object *O = Value.getAsObject();
+ if (!O) {
+ Path.report("expected object");
return false;
}
- if (const llvm::json::Object *textDocument = o->getObject("textDocument")) {
- if (const llvm::json::Object *documentSymbol =
- textDocument->getObject("documentSymbol")) {
- if (std::optional<bool> hierarchicalSupport =
- documentSymbol->getBoolean("hierarchicalDocumentSymbolSupport"))
- result.hierarchicalDocumentSymbol = *hierarchicalSupport;
+ if (const llvm::json::Object *TextDocument = O->getObject("textDocument")) {
+ if (const llvm::json::Object *DocumentSymbol =
+ TextDocument->getObject("documentSymbol")) {
+ if (std::optional<bool> HierarchicalSupport =
+ DocumentSymbol->getBoolean("hierarchicalDocumentSymbolSupport"))
+ Result.hierarchicalDocumentSymbol = *HierarchicalSupport;
}
- if (auto *codeAction = textDocument->getObject("codeAction")) {
- if (codeAction->getObject("codeActionLiteralSupport"))
- result.codeActionStructure = true;
+ if (auto *CodeAction = TextDocument->getObject("codeAction")) {
+ if (CodeAction->getObject("codeActionLiteralSupport"))
+ Result.codeActionStructure = true;
}
}
- if (auto *window = o->getObject("window")) {
- if (std::optional<bool> workDoneProgressSupport =
- window->getBoolean("workDoneProgress"))
- result.workDoneProgress = *workDoneProgressSupport;
+ if (auto *Window = O->getObject("window")) {
+ if (std::optional<bool> WorkDoneProgressSupport =
+ Window->getBoolean("workDoneProgress"))
+ Result.workDoneProgress = *WorkDoneProgressSupport;
}
return true;
}
@@ -297,14 +297,14 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// ClientInfo
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, ClientInfo &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- if (!o || !o.map("name", result.name))
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, ClientInfo &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ if (!O || !O.map("name", Result.name))
return false;
// Don't fail if we can't parse version.
- o.map("version", result.version);
+ O.map("version", Result.version);
return true;
}
@@ -312,34 +312,34 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value, ClientInfo &result,
// InitializeParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, TraceLevel &result,
- llvm::json::Path path) {
- if (std::optional<StringRef> str = value.getAsString()) {
- if (*str == "off") {
- result = TraceLevel::Off;
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, TraceLevel &Result,
+ llvm::json::Path Path) {
+ if (std::optional<StringRef> Str = Value.getAsString()) {
+ if (*Str == "off") {
+ Result = TraceLevel::Off;
return true;
}
- if (*str == "messages") {
- result = TraceLevel::Messages;
+ if (*Str == "messages") {
+ Result = TraceLevel::Messages;
return true;
}
- if (*str == "verbose") {
- result = TraceLevel::Verbose;
+ if (*Str == "verbose") {
+ Result = TraceLevel::Verbose;
return true;
}
}
return false;
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- InitializeParams &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- if (!o)
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ InitializeParams &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ if (!O)
return false;
// We deliberately don't fail if we can't parse individual fields.
- o.map("capabilities", result.capabilities);
- o.map("trace", result.trace);
- mapOptOrNull(value, "clientInfo", result.clientInfo, path);
+ O.map("capabilities", Result.capabilities);
+ O.map("trace", Result.trace);
+ mapOptOrNull(Value, "clientInfo", Result.clientInfo, Path);
return true;
}
@@ -348,27 +348,27 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// TextDocumentItem
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- TextDocumentItem &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("uri", result.uri) &&
- o.map("languageId", result.languageId) && o.map("text", result.text) &&
- o.map("version", result.version);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ TextDocumentItem &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("uri", Result.uri) &&
+ O.map("languageId", Result.languageId) && O.map("text", Result.text) &&
+ O.map("version", Result.version);
}
//===----------------------------------------------------------------------===//
// TextDocumentIdentifier
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const TextDocumentIdentifier &value) {
- return llvm::json::Object{{"uri", value.uri}};
+llvm::json::Value llvm::lsp::toJSON(const TextDocumentIdentifier &Value) {
+ return llvm::json::Object{{"uri", Value.uri}};
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- TextDocumentIdentifier &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("uri", result.uri);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ TextDocumentIdentifier &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("uri", Result.uri);
}
//===----------------------------------------------------------------------===//
@@ -376,134 +376,134 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
//===----------------------------------------------------------------------===//
llvm::json::Value
-llvm::lsp::toJSON(const VersionedTextDocumentIdentifier &value) {
+llvm::lsp::toJSON(const VersionedTextDocumentIdentifier &Value) {
return llvm::json::Object{
- {"uri", value.uri},
- {"version", value.version},
+ {"uri", Value.uri},
+ {"version", Value.version},
};
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- VersionedTextDocumentIdentifier &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("uri", result.uri) && o.map("version", result.version);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ VersionedTextDocumentIdentifier &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("uri", Result.uri) && O.map("version", Result.version);
}
//===----------------------------------------------------------------------===//
// Position
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, Position &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("line", result.line) &&
- o.map("character", result.character);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, Position &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("line", Result.line) &&
+ O.map("character", Result.character);
}
-llvm::json::Value llvm::lsp::toJSON(const Position &value) {
+llvm::json::Value llvm::lsp::toJSON(const Position &Value) {
return llvm::json::Object{
- {"line", value.line},
- {"character", value.character},
+ {"line", Value.line},
+ {"character", Value.character},
};
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Position &value) {
- return os << value.line << ':' << value.character;
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, const Position &Value) {
+ return Os << Value.line << ':' << Value.character;
}
//===----------------------------------------------------------------------===//
// Range
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, Range &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("start", result.start) && o.map("end", result.end);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, Range &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("start", Result.start) && O.map("end", Result.end);
}
-llvm::json::Value llvm::lsp::toJSON(const Range &value) {
+llvm::json::Value llvm::lsp::toJSON(const Range &Value) {
return llvm::json::Object{
- {"start", value.start},
- {"end", value.end},
+ {"start", Value.start},
+ {"end", Value.end},
};
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Range &value) {
- return os << value.start << '-' << value.end;
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, const Range &Value) {
+ return Os << Value.start << '-' << Value.end;
}
//===----------------------------------------------------------------------===//
// Location
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, Location &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("uri", result.uri) && o.map("range", result.range);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, Location &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("uri", Result.uri) && O.map("range", Result.range);
}
-llvm::json::Value llvm::lsp::toJSON(const Location &value) {
+llvm::json::Value llvm::lsp::toJSON(const Location &Value) {
return llvm::json::Object{
- {"uri", value.uri},
- {"range", value.range},
+ {"uri", Value.uri},
+ {"range", Value.range},
};
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const Location &value) {
- return os << value.range << '@' << value.uri;
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, const Location &Value) {
+ return Os << Value.range << '@' << Value.uri;
}
//===----------------------------------------------------------------------===//
// TextDocumentPositionParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- TextDocumentPositionParams &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument) &&
- o.map("position", result.position);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ TextDocumentPositionParams &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument) &&
+ O.map("position", Result.position);
}
//===----------------------------------------------------------------------===//
// ReferenceParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- ReferenceContext &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.mapOptional("includeDeclaration", result.includeDeclaration);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ ReferenceContext &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.mapOptional("includeDeclaration", Result.includeDeclaration);
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- ReferenceParams &result, llvm::json::Path path) {
- TextDocumentPositionParams &base = result;
- llvm::json::ObjectMapper o(value, path);
- return fromJSON(value, base, path) && o &&
- o.mapOptional("context", result.context);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ ReferenceParams &Result, llvm::json::Path Path) {
+ TextDocumentPositionParams &Base = Result;
+ llvm::json::ObjectMapper O(Value, Path);
+ return fromJSON(Value, Base, Path) && O &&
+ O.mapOptional("context", Result.context);
}
//===----------------------------------------------------------------------===//
// DidOpenTextDocumentParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DidOpenTextDocumentParams &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DidOpenTextDocumentParams &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument);
}
//===----------------------------------------------------------------------===//
// DidCloseTextDocumentParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DidCloseTextDocumentParams &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DidCloseTextDocumentParams &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument);
}
//===----------------------------------------------------------------------===//
@@ -511,57 +511,57 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
//===----------------------------------------------------------------------===//
LogicalResult
-TextDocumentContentChangeEvent::applyTo(std::string &contents) const {
+TextDocumentContentChangeEvent::applyTo(std::string &Contents) const {
// If there is no range, the full document changed.
if (!range) {
- contents = text;
+ Contents = text;
return success();
}
// Try to map the replacement range to the content.
- llvm::SourceMgr tmpScrMgr;
- tmpScrMgr.AddNewSourceBuffer(llvm::MemoryBuffer::getMemBuffer(contents),
+ llvm::SourceMgr TmpScrMgr;
+ TmpScrMgr.AddNewSourceBuffer(llvm::MemoryBuffer::getMemBuffer(Contents),
SMLoc());
- SMRange rangeLoc = range->getAsSMRange(tmpScrMgr);
- if (!rangeLoc.isValid())
+ SMRange RangeLoc = range->getAsSMRange(TmpScrMgr);
+ if (!RangeLoc.isValid())
return failure();
- contents.replace(rangeLoc.Start.getPointer() - contents.data(),
- rangeLoc.End.getPointer() - rangeLoc.Start.getPointer(),
+ Contents.replace(RangeLoc.Start.getPointer() - Contents.data(),
+ RangeLoc.End.getPointer() - RangeLoc.Start.getPointer(),
text);
return success();
}
LogicalResult TextDocumentContentChangeEvent::applyTo(
- ArrayRef<TextDocumentContentChangeEvent> changes, std::string &contents) {
- for (const auto &change : changes)
- if (failed(change.applyTo(contents)))
+ ArrayRef<TextDocumentContentChangeEvent> Changes, std::string &Contents) {
+ for (const auto &Change : Changes)
+ if (failed(Change.applyTo(Contents)))
return failure();
return success();
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- TextDocumentContentChangeEvent &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("range", result.range) &&
- o.map("rangeLength", result.rangeLength) && o.map("text", result.text);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ TextDocumentContentChangeEvent &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("range", Result.range) &&
+ O.map("rangeLength", Result.rangeLength) && O.map("text", Result.text);
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DidChangeTextDocumentParams &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument) &&
- o.map("contentChanges", result.contentChanges);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DidChangeTextDocumentParams &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument) &&
+ O.map("contentChanges", Result.contentChanges);
}
//===----------------------------------------------------------------------===//
// MarkupContent
//===----------------------------------------------------------------------===//
-static llvm::StringRef toTextKind(MarkupKind kind) {
- switch (kind) {
+static llvm::StringRef toTextKind(MarkupKind Kind) {
+ switch (Kind) {
case MarkupKind::PlainText:
return "plaintext";
case MarkupKind::Markdown:
@@ -570,17 +570,17 @@ static llvm::StringRef toTextKind(MarkupKind kind) {
llvm_unreachable("Invalid MarkupKind");
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, MarkupKind kind) {
- return os << toTextKind(kind);
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, MarkupKind Kind) {
+ return Os << toTextKind(Kind);
}
-llvm::json::Value llvm::lsp::toJSON(const MarkupContent &mc) {
- if (mc.value.empty())
+llvm::json::Value llvm::lsp::toJSON(const MarkupContent &Mc) {
+ if (Mc.value.empty())
return nullptr;
return llvm::json::Object{
- {"kind", toTextKind(mc.kind)},
- {"value", mc.value},
+ {"kind", toTextKind(Mc.kind)},
+ {"value", Mc.value},
};
}
@@ -588,56 +588,56 @@ llvm::json::Value llvm::lsp::toJSON(const MarkupContent &mc) {
// Hover
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const Hover &hover) {
- llvm::json::Object result{{"contents", toJSON(hover.contents)}};
- if (hover.range)
- result["range"] = toJSON(*hover.range);
- return std::move(result);
+llvm::json::Value llvm::lsp::toJSON(const Hover &Hover) {
+ llvm::json::Object Result{{"contents", toJSON(Hover.contents)}};
+ if (Hover.range)
+ Result["range"] = toJSON(*Hover.range);
+ return std::move(Result);
}
//===----------------------------------------------------------------------===//
// DocumentSymbol
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const DocumentSymbol &symbol) {
- llvm::json::Object result{{"name", symbol.name},
- {"kind", static_cast<int>(symbol.kind)},
- {"range", symbol.range},
- {"selectionRange", symbol.selectionRange}};
+llvm::json::Value llvm::lsp::toJSON(const DocumentSymbol &Symbol) {
+ llvm::json::Object Result{{"name", Symbol.name},
+ {"kind", static_cast<int>(Symbol.kind)},
+ {"range", Symbol.range},
+ {"selectionRange", Symbol.selectionRange}};
- if (!symbol.detail.empty())
- result["detail"] = symbol.detail;
- if (!symbol.children.empty())
- result["children"] = symbol.children;
- return std::move(result);
+ if (!Symbol.detail.empty())
+ Result["detail"] = Symbol.detail;
+ if (!Symbol.children.empty())
+ Result["children"] = Symbol.children;
+ return std::move(Result);
}
//===----------------------------------------------------------------------===//
// DocumentSymbolParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DocumentSymbolParams &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DocumentSymbolParams &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument);
}
//===----------------------------------------------------------------------===//
// DiagnosticRelatedInformation
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DiagnosticRelatedInformation &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("location", result.location) &&
- o.map("message", result.message);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DiagnosticRelatedInformation &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("location", Result.location) &&
+ O.map("message", Result.message);
}
-llvm::json::Value llvm::lsp::toJSON(const DiagnosticRelatedInformation &info) {
+llvm::json::Value llvm::lsp::toJSON(const DiagnosticRelatedInformation &Info) {
return llvm::json::Object{
- {"location", info.location},
- {"message", info.message},
+ {"location", Info.location},
+ {"message", Info.message},
};
}
@@ -645,64 +645,64 @@ llvm::json::Value llvm::lsp::toJSON(const DiagnosticRelatedInformation &info) {
// Diagnostic
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(DiagnosticTag tag) {
- return static_cast<int>(tag);
+llvm::json::Value llvm::lsp::toJSON(DiagnosticTag Tag) {
+ return static_cast<int>(Tag);
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, DiagnosticTag &result,
- llvm::json::Path path) {
- if (std::optional<int64_t> i = value.getAsInteger()) {
- result = (DiagnosticTag)*i;
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, DiagnosticTag &Result,
+ llvm::json::Path Path) {
+ if (std::optional<int64_t> I = Value.getAsInteger()) {
+ Result = (DiagnosticTag)*I;
return true;
}
return false;
}
-llvm::json::Value llvm::lsp::toJSON(const Diagnostic &diag) {
- llvm::json::Object result{
- {"range", diag.range},
- {"severity", (int)diag.severity},
- {"message", diag.message},
+llvm::json::Value llvm::lsp::toJSON(const Diagnostic &Diag) {
+ llvm::json::Object Result{
+ {"range", Diag.range},
+ {"severity", (int)Diag.severity},
+ {"message", Diag.message},
};
- if (diag.category)
- result["category"] = *diag.category;
- if (!diag.source.empty())
- result["source"] = diag.source;
- if (diag.relatedInformation)
- result["relatedInformation"] = *diag.relatedInformation;
- if (!diag.tags.empty())
- result["tags"] = diag.tags;
- return std::move(result);
-}
-
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, Diagnostic &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- if (!o)
+ if (Diag.category)
+ Result["category"] = *Diag.category;
+ if (!Diag.source.empty())
+ Result["source"] = Diag.source;
+ if (Diag.relatedInformation)
+ Result["relatedInformation"] = *Diag.relatedInformation;
+ if (!Diag.tags.empty())
+ Result["tags"] = Diag.tags;
+ return std::move(Result);
+}
+
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, Diagnostic &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ if (!O)
return false;
- int severity = 0;
- if (!mapOptOrNull(value, "severity", severity, path))
+ int Severity = 0;
+ if (!mapOptOrNull(Value, "severity", Severity, Path))
return false;
- result.severity = (DiagnosticSeverity)severity;
+ Result.severity = (DiagnosticSeverity)Severity;
- return o.map("range", result.range) && o.map("message", result.message) &&
- mapOptOrNull(value, "category", result.category, path) &&
- mapOptOrNull(value, "source", result.source, path) &&
- mapOptOrNull(value, "relatedInformation", result.relatedInformation,
- path) &&
- mapOptOrNull(value, "tags", result.tags, path);
+ return O.map("range", Result.range) && O.map("message", Result.message) &&
+ mapOptOrNull(Value, "category", Result.category, Path) &&
+ mapOptOrNull(Value, "source", Result.source, Path) &&
+ mapOptOrNull(Value, "relatedInformation", Result.relatedInformation,
+ Path) &&
+ mapOptOrNull(Value, "tags", Result.tags, Path);
}
//===----------------------------------------------------------------------===//
// PublishDiagnosticsParams
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const PublishDiagnosticsParams ¶ms) {
+llvm::json::Value llvm::lsp::toJSON(const PublishDiagnosticsParams &Params) {
return llvm::json::Object{
- {"uri", params.uri},
- {"diagnostics", params.diagnostics},
- {"version", params.version},
+ {"uri", Params.uri},
+ {"diagnostics", Params.diagnostics},
+ {"version", Params.version},
};
}
@@ -710,52 +710,52 @@ llvm::json::Value llvm::lsp::toJSON(const PublishDiagnosticsParams ¶ms) {
// TextEdit
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, TextEdit &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("range", result.range) && o.map("newText", result.newText);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, TextEdit &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("range", Result.range) && O.map("newText", Result.newText);
}
-llvm::json::Value llvm::lsp::toJSON(const TextEdit &value) {
+llvm::json::Value llvm::lsp::toJSON(const TextEdit &Value) {
return llvm::json::Object{
- {"range", value.range},
- {"newText", value.newText},
+ {"range", Value.range},
+ {"newText", Value.newText},
};
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os, const TextEdit &value) {
- os << value.range << " => \"";
- llvm::printEscapedString(value.newText, os);
- return os << '"';
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os, const TextEdit &Value) {
+ Os << Value.range << " => \"";
+ llvm::printEscapedString(Value.newText, Os);
+ return Os << '"';
}
//===----------------------------------------------------------------------===//
// CompletionItemKind
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CompletionItemKind &result, llvm::json::Path path) {
- if (std::optional<int64_t> intValue = value.getAsInteger()) {
- if (*intValue < static_cast<int>(CompletionItemKind::Text) ||
- *intValue > static_cast<int>(CompletionItemKind::TypeParameter))
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CompletionItemKind &Result, llvm::json::Path Path) {
+ if (std::optional<int64_t> IntValue = Value.getAsInteger()) {
+ if (*IntValue < static_cast<int>(CompletionItemKind::Text) ||
+ *IntValue > static_cast<int>(CompletionItemKind::TypeParameter))
return false;
- result = static_cast<CompletionItemKind>(*intValue);
+ Result = static_cast<CompletionItemKind>(*IntValue);
return true;
}
return false;
}
CompletionItemKind llvm::lsp::adjustKindToCapability(
- CompletionItemKind kind,
- CompletionItemKindBitset &supportedCompletionItemKinds) {
- size_t kindVal = static_cast<size_t>(kind);
- if (kindVal >= kCompletionItemKindMin &&
- kindVal <= supportedCompletionItemKinds.size() &&
- supportedCompletionItemKinds[kindVal])
- return kind;
+ CompletionItemKind Kind,
+ CompletionItemKindBitset &SupportedCompletionItemKinds) {
+ size_t KindVal = static_cast<size_t>(Kind);
+ if (KindVal >= kCompletionItemKindMin &&
+ KindVal <= SupportedCompletionItemKinds.size() &&
+ SupportedCompletionItemKinds[KindVal])
+ return Kind;
// Provide some fall backs for common kinds that are close enough.
- switch (kind) {
+ switch (Kind) {
case CompletionItemKind::Folder:
return CompletionItemKind::File;
case CompletionItemKind::EnumMember:
@@ -767,14 +767,14 @@ CompletionItemKind llvm::lsp::adjustKindToCapability(
}
}
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CompletionItemKindBitset &result,
- llvm::json::Path path) {
- if (const llvm::json::Array *arrayValue = value.getAsArray()) {
- for (size_t i = 0, e = arrayValue->size(); i < e; ++i) {
- CompletionItemKind kindOut;
- if (fromJSON((*arrayValue)[i], kindOut, path.index(i)))
- result.set(size_t(kindOut));
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CompletionItemKindBitset &Result,
+ llvm::json::Path Path) {
+ if (const llvm::json::Array *ArrayValue = Value.getAsArray()) {
+ for (size_t I = 0, E = ArrayValue->size(); I < E; ++I) {
+ CompletionItemKind KindOut;
+ if (fromJSON((*ArrayValue)[I], KindOut, Path.index(I)))
+ Result.set(size_t(KindOut));
}
return true;
}
@@ -785,53 +785,53 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// CompletionItem
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const CompletionItem &value) {
- assert(!value.label.empty() && "completion item label is required");
- llvm::json::Object result{{"label", value.label}};
- if (value.kind != CompletionItemKind::Missing)
- result["kind"] = static_cast<int>(value.kind);
- if (!value.detail.empty())
- result["detail"] = value.detail;
- if (value.documentation)
- result["documentation"] = value.documentation;
- if (!value.sortText.empty())
- result["sortText"] = value.sortText;
- if (!value.filterText.empty())
- result["filterText"] = value.filterText;
- if (!value.insertText.empty())
- result["insertText"] = value.insertText;
- if (value.insertTextFormat != InsertTextFormat::Missing)
- result["insertTextFormat"] = static_cast<int>(value.insertTextFormat);
- if (value.textEdit)
- result["textEdit"] = *value.textEdit;
- if (!value.additionalTextEdits.empty()) {
- result["additionalTextEdits"] =
- llvm::json::Array(value.additionalTextEdits);
+llvm::json::Value llvm::lsp::toJSON(const CompletionItem &Value) {
+ assert(!Value.label.empty() && "completion item label is required");
+ llvm::json::Object Result{{"label", Value.label}};
+ if (Value.kind != CompletionItemKind::Missing)
+ Result["kind"] = static_cast<int>(Value.kind);
+ if (!Value.detail.empty())
+ Result["detail"] = Value.detail;
+ if (Value.documentation)
+ Result["documentation"] = Value.documentation;
+ if (!Value.sortText.empty())
+ Result["sortText"] = Value.sortText;
+ if (!Value.filterText.empty())
+ Result["filterText"] = Value.filterText;
+ if (!Value.insertText.empty())
+ Result["insertText"] = Value.insertText;
+ if (Value.insertTextFormat != InsertTextFormat::Missing)
+ Result["insertTextFormat"] = static_cast<int>(Value.insertTextFormat);
+ if (Value.textEdit)
+ Result["textEdit"] = *Value.textEdit;
+ if (!Value.additionalTextEdits.empty()) {
+ Result["additionalTextEdits"] =
+ llvm::json::Array(Value.additionalTextEdits);
}
- if (value.deprecated)
- result["deprecated"] = value.deprecated;
- return std::move(result);
+ if (Value.deprecated)
+ Result["deprecated"] = Value.deprecated;
+ return std::move(Result);
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os,
- const CompletionItem &value) {
- return os << value.label << " - " << toJSON(value);
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os,
+ const CompletionItem &Value) {
+ return Os << Value.label << " - " << toJSON(Value);
}
-bool llvm::lsp::operator<(const CompletionItem &lhs,
- const CompletionItem &rhs) {
- return (lhs.sortText.empty() ? lhs.label : lhs.sortText) <
- (rhs.sortText.empty() ? rhs.label : rhs.sortText);
+bool llvm::lsp::operator<(const CompletionItem &Lhs,
+ const CompletionItem &Rhs) {
+ return (Lhs.sortText.empty() ? Lhs.label : Lhs.sortText) <
+ (Rhs.sortText.empty() ? Rhs.label : Rhs.sortText);
}
//===----------------------------------------------------------------------===//
// CompletionList
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const CompletionList &value) {
+llvm::json::Value llvm::lsp::toJSON(const CompletionList &Value) {
return llvm::json::Object{
- {"isIncomplete", value.isIncomplete},
- {"items", llvm::json::Array(value.items)},
+ {"isIncomplete", Value.isIncomplete},
+ {"items", llvm::json::Array(Value.items)},
};
}
@@ -839,14 +839,14 @@ llvm::json::Value llvm::lsp::toJSON(const CompletionList &value) {
// CompletionContext
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CompletionContext &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- int triggerKind;
- if (!o || !o.map("triggerKind", triggerKind) ||
- !mapOptOrNull(value, "triggerCharacter", result.triggerCharacter, path))
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CompletionContext &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ int TriggerKind;
+ if (!O || !O.map("triggerKind", TriggerKind) ||
+ !mapOptOrNull(Value, "triggerCharacter", Result.triggerCharacter, Path))
return false;
- result.triggerKind = static_cast<CompletionTriggerKind>(triggerKind);
+ Result.triggerKind = static_cast<CompletionTriggerKind>(TriggerKind);
return true;
}
@@ -854,12 +854,12 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// CompletionParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CompletionParams &result, llvm::json::Path path) {
- if (!fromJSON(value, static_cast<TextDocumentPositionParams &>(result), path))
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CompletionParams &Result, llvm::json::Path Path) {
+ if (!fromJSON(Value, static_cast<TextDocumentPositionParams &>(Result), Path))
return false;
- if (const llvm::json::Value *context = value.getAsObject()->get("context"))
- return fromJSON(*context, result.context, path.field("context"));
+ if (const llvm::json::Value *Context = Value.getAsObject()->get("context"))
+ return fromJSON(*Context, Result.context, Path.field("context"));
return true;
}
@@ -867,53 +867,53 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// ParameterInformation
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const ParameterInformation &value) {
- assert((value.labelOffsets || !value.labelString.empty()) &&
+llvm::json::Value llvm::lsp::toJSON(const ParameterInformation &Value) {
+ assert((Value.labelOffsets || !Value.labelString.empty()) &&
"parameter information label is required");
- llvm::json::Object result;
- if (value.labelOffsets)
- result["label"] = llvm::json::Array(
- {value.labelOffsets->first, value.labelOffsets->second});
+ llvm::json::Object Result;
+ if (Value.labelOffsets)
+ Result["label"] = llvm::json::Array(
+ {Value.labelOffsets->first, Value.labelOffsets->second});
else
- result["label"] = value.labelString;
- if (!value.documentation.empty())
- result["documentation"] = value.documentation;
- return std::move(result);
+ Result["label"] = Value.labelString;
+ if (!Value.documentation.empty())
+ Result["documentation"] = Value.documentation;
+ return std::move(Result);
}
//===----------------------------------------------------------------------===//
// SignatureInformation
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const SignatureInformation &value) {
- assert(!value.label.empty() && "signature information label is required");
- llvm::json::Object result{
- {"label", value.label},
- {"parameters", llvm::json::Array(value.parameters)},
+llvm::json::Value llvm::lsp::toJSON(const SignatureInformation &Value) {
+ assert(!Value.label.empty() && "signature information label is required");
+ llvm::json::Object Result{
+ {"label", Value.label},
+ {"parameters", llvm::json::Array(Value.parameters)},
};
- if (!value.documentation.empty())
- result["documentation"] = value.documentation;
- return std::move(result);
+ if (!Value.documentation.empty())
+ Result["documentation"] = Value.documentation;
+ return std::move(Result);
}
-raw_ostream &llvm::lsp::operator<<(raw_ostream &os,
- const SignatureInformation &value) {
- return os << value.label << " - " << toJSON(value);
+raw_ostream &llvm::lsp::operator<<(raw_ostream &Os,
+ const SignatureInformation &Value) {
+ return Os << Value.label << " - " << toJSON(Value);
}
//===----------------------------------------------------------------------===//
// SignatureHelp
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const SignatureHelp &value) {
- assert(value.activeSignature >= 0 &&
+llvm::json::Value llvm::lsp::toJSON(const SignatureHelp &Value) {
+ assert(Value.activeSignature >= 0 &&
"Unexpected negative value for number of active signatures.");
- assert(value.activeParameter >= 0 &&
+ assert(Value.activeParameter >= 0 &&
"Unexpected negative value for active parameter index");
return llvm::json::Object{
- {"activeSignature", value.activeSignature},
- {"activeParameter", value.activeParameter},
- {"signatures", llvm::json::Array(value.signatures)},
+ {"activeSignature", Value.activeSignature},
+ {"activeParameter", Value.activeParameter},
+ {"signatures", llvm::json::Array(Value.signatures)},
};
}
@@ -921,20 +921,20 @@ llvm::json::Value llvm::lsp::toJSON(const SignatureHelp &value) {
// DocumentLinkParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- DocumentLinkParams &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ DocumentLinkParams &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument);
}
//===----------------------------------------------------------------------===//
// DocumentLink
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const DocumentLink &value) {
+llvm::json::Value llvm::lsp::toJSON(const DocumentLink &Value) {
return llvm::json::Object{
- {"range", value.range},
- {"target", value.target},
+ {"range", Value.range},
+ {"target", Value.target},
};
}
@@ -942,40 +942,40 @@ llvm::json::Value llvm::lsp::toJSON(const DocumentLink &value) {
// InlayHintsParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- InlayHintsParams &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument) &&
- o.map("range", result.range);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ InlayHintsParams &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument) &&
+ O.map("range", Result.range);
}
//===----------------------------------------------------------------------===//
// InlayHint
//===----------------------------------------------------------------------===//
-llvm::json::Value llvm::lsp::toJSON(const InlayHint &value) {
- return llvm::json::Object{{"position", value.position},
- {"kind", (int)value.kind},
- {"label", value.label},
- {"paddingLeft", value.paddingLeft},
- {"paddingRight", value.paddingRight}};
+llvm::json::Value llvm::lsp::toJSON(const InlayHint &Value) {
+ return llvm::json::Object{{"position", Value.position},
+ {"kind", (int)Value.kind},
+ {"label", Value.label},
+ {"paddingLeft", Value.paddingLeft},
+ {"paddingRight", Value.paddingRight}};
}
-bool llvm::lsp::operator==(const InlayHint &lhs, const InlayHint &rhs) {
- return std::tie(lhs.position, lhs.kind, lhs.label) ==
- std::tie(rhs.position, rhs.kind, rhs.label);
+bool llvm::lsp::operator==(const InlayHint &Lhs, const InlayHint &Rhs) {
+ return std::tie(Lhs.position, Lhs.kind, Lhs.label) ==
+ std::tie(Rhs.position, Rhs.kind, Rhs.label);
}
-bool llvm::lsp::operator<(const InlayHint &lhs, const InlayHint &rhs) {
- return std::tie(lhs.position, lhs.kind, lhs.label) <
- std::tie(rhs.position, rhs.kind, rhs.label);
+bool llvm::lsp::operator<(const InlayHint &Lhs, const InlayHint &Rhs) {
+ return std::tie(Lhs.position, Lhs.kind, Lhs.label) <
+ std::tie(Rhs.position, Rhs.kind, Rhs.label);
}
-llvm::raw_ostream &llvm::lsp::operator<<(llvm::raw_ostream &os,
- InlayHintKind value) {
- switch (value) {
+llvm::raw_ostream &llvm::lsp::operator<<(llvm::raw_ostream &Os,
+ InlayHintKind Value) {
+ switch (Value) {
case InlayHintKind::Parameter:
- return os << "parameter";
+ return Os << "parameter";
case InlayHintKind::Type:
- return os << "type";
+ return Os << "type";
}
llvm_unreachable("Unknown InlayHintKind");
}
@@ -984,12 +984,12 @@ llvm::raw_ostream &llvm::lsp::operator<<(llvm::raw_ostream &os,
// CodeActionContext
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CodeActionContext &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- if (!o || !o.map("diagnostics", result.diagnostics))
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CodeActionContext &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ if (!O || !O.map("diagnostics", Result.diagnostics))
return false;
- o.map("only", result.only);
+ O.map("only", Result.only);
return true;
}
@@ -997,28 +997,28 @@ bool llvm::lsp::fromJSON(const llvm::json::Value &value,
// CodeActionParams
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value,
- CodeActionParams &result, llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("textDocument", result.textDocument) &&
- o.map("range", result.range) && o.map("context", result.context);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value,
+ CodeActionParams &Result, llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("textDocument", Result.textDocument) &&
+ O.map("range", Result.range) && O.map("context", Result.context);
}
//===----------------------------------------------------------------------===//
// WorkspaceEdit
//===----------------------------------------------------------------------===//
-bool llvm::lsp::fromJSON(const llvm::json::Value &value, WorkspaceEdit &result,
- llvm::json::Path path) {
- llvm::json::ObjectMapper o(value, path);
- return o && o.map("changes", result.changes);
+bool llvm::lsp::fromJSON(const llvm::json::Value &Value, WorkspaceEdit &Result,
+ llvm::json::Path Path) {
+ llvm::json::ObjectMapper O(Value, Path);
+ return O && O.map("changes", Result.changes);
}
-llvm::json::Value llvm::lsp::toJSON(const WorkspaceEdit &value) {
- llvm::json::Object fileChanges;
- for (auto &change : value.changes)
- fileChanges[change.first] = llvm::json::Array(change.second);
- return llvm::json::Object{{"changes", std::move(fileChanges)}};
+llvm::json::Value llvm::lsp::toJSON(const WorkspaceEdit &Value) {
+ llvm::json::Object FileChanges;
+ for (auto &Change : Value.changes)
+ FileChanges[Change.first] = llvm::json::Array(Change.second);
+ return llvm::json::Object{{"changes", std::move(FileChanges)}};
}
//===----------------------------------------------------------------------===//
@@ -1029,15 +1029,15 @@ const llvm::StringLiteral CodeAction::kQuickFix = "quickfix";
const llvm::StringLiteral CodeAction::kRefactor = "refactor";
const llvm::StringLiteral CodeAction::kInfo = "info";
-llvm::json::Value llvm::lsp::toJSON(const CodeAction &value) {
- llvm::json::Object codeAction{{"title", value.title}};
- if (value.kind)
- codeAction["kind"] = *value.kind;
- if (value.diagnostics)
- codeAction["diagnostics"] = llvm::json::Array(*value.diagnostics);
- if (value.isPreferred)
- codeAction["isPreferred"] = true;
- if (value.edit)
- codeAction["edit"] = *value.edit;
- return std::move(codeAction);
+llvm::json::Value llvm::lsp::toJSON(const CodeAction &Value) {
+ llvm::json::Object CodeAction{{"title", Value.title}};
+ if (Value.kind)
+ CodeAction["kind"] = *Value.kind;
+ if (Value.diagnostics)
+ CodeAction["diagnostics"] = llvm::json::Array(*Value.diagnostics);
+ if (Value.isPreferred)
+ CodeAction["isPreferred"] = true;
+ if (Value.edit)
+ CodeAction["edit"] = *Value.edit;
+ return std::move(CodeAction);
}
diff --git a/llvm/lib/Support/LSP/Transport.cpp b/llvm/lib/Support/LSP/Transport.cpp
index 3f13a9ee0bf8c..e71f17701636b 100644
--- a/llvm/lib/Support/LSP/Transport.cpp
+++ b/llvm/lib/Support/LSP/Transport.cpp
@@ -7,14 +7,14 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/LSP/Transport.h"
-#include "llvm/Support/LSP/Logging.h"
-#include "llvm/Support/LSP/Protocol.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/LSP/Logging.h"
+#include "llvm/Support/LSP/Protocol.h"
+#include <atomic>
#include <optional>
#include <system_error>
#include <utility>
-#include <atomic>
using namespace llvm;
using namespace llvm::lsp;
@@ -30,52 +30,52 @@ namespace {
/// - if there were multiple replies, only the first is sent
class Reply {
public:
- Reply(const llvm::json::Value &id, StringRef method, JSONTransport &transport,
- std::mutex &transportOutputMutex);
- Reply(Reply &&other);
+ Reply(const llvm::json::Value &Id, StringRef Method, JSONTransport &Transport,
+ std::mutex &TransportOutputMutex);
+ Reply(Reply &&Other);
Reply &operator=(Reply &&) = delete;
Reply(const Reply &) = delete;
Reply &operator=(const Reply &) = delete;
- void operator()(llvm::Expected<llvm::json::Value> reply);
+ void operator()(llvm::Expected<llvm::json::Value> Reply);
private:
- std::string method;
- std::atomic<bool> replied = {false};
- llvm::json::Value id;
- JSONTransport *transport;
- std::mutex &transportOutputMutex;
+ std::string Method;
+ std::atomic<bool> Replied = {false};
+ llvm::json::Value Id;
+ JSONTransport *Transport;
+ std::mutex &TransportOutputMutex;
};
} // namespace
-Reply::Reply(const llvm::json::Value &id, llvm::StringRef method,
- JSONTransport &transport, std::mutex &transportOutputMutex)
- : method(method), id(id), transport(&transport),
- transportOutputMutex(transportOutputMutex) {}
+Reply::Reply(const llvm::json::Value &Id, llvm::StringRef Method,
+ JSONTransport &Transport, std::mutex &TransportOutputMutex)
+ : Method(Method), Id(Id), Transport(&Transport),
+ TransportOutputMutex(TransportOutputMutex) {}
-Reply::Reply(Reply &&other)
- : method(other.method), replied(other.replied.load()),
- id(std::move(other.id)), transport(other.transport),
- transportOutputMutex(other.transportOutputMutex) {
- other.transport = nullptr;
+Reply::Reply(Reply &&Other)
+ : Method(Other.Method), Replied(Other.Replied.load()),
+ Id(std::move(Other.Id)), Transport(Other.Transport),
+ TransportOutputMutex(Other.TransportOutputMutex) {
+ Other.Transport = nullptr;
}
-void Reply::operator()(llvm::Expected<llvm::json::Value> reply) {
- if (replied.exchange(true)) {
- Logger::error("Replied twice to message {0}({1})", method, id);
+void Reply::operator()(llvm::Expected<llvm::json::Value> Reply) {
+ if (Replied.exchange(true)) {
+ Logger::error("Replied twice to message {0}({1})", Method, Id);
assert(false && "must reply to each call only once!");
return;
}
- assert(transport && "expected valid transport to reply to");
+ assert(Transport && "expected valid transport to reply to");
- std::lock_guard<std::mutex> transportLock(transportOutputMutex);
- if (reply) {
- Logger::info("--> reply:{0}({1})", method, id);
- transport->reply(std::move(id), std::move(reply));
+ std::lock_guard<std::mutex> TransportLock(TransportOutputMutex);
+ if (Reply) {
+ Logger::info("--> reply:{0}({1})", Method, Id);
+ Transport->reply(std::move(Id), std::move(Reply));
} else {
- llvm::Error error = reply.takeError();
- Logger::info("--> reply:{0}({1}): {2}", method, id, error);
- transport->reply(std::move(id), std::move(error));
+ llvm::Error Error = Reply.takeError();
+ Logger::info("--> reply:{0}({1}): {2}", Method, Id, Error);
+ Transport->reply(std::move(Id), std::move(Error));
}
}
@@ -83,61 +83,61 @@ void Reply::operator()(llvm::Expected<llvm::json::Value> reply) {
// MessageHandler
//===----------------------------------------------------------------------===//
-bool MessageHandler::onNotify(llvm::StringRef method, llvm::json::Value value) {
- Logger::info("--> {0}", method);
+bool MessageHandler::onNotify(llvm::StringRef Method, llvm::json::Value Value) {
+ Logger::info("--> {0}", Method);
- if (method == "exit")
+ if (Method == "exit")
return false;
- if (method == "$cancel") {
+ if (Method == "$cancel") {
// TODO: Add support for cancelling requests.
} else {
- auto it = notificationHandlers.find(method);
- if (it != notificationHandlers.end())
- it->second(std::move(value));
+ auto It = NotificationHandlers.find(Method);
+ if (It != NotificationHandlers.end())
+ It->second(std::move(Value));
}
return true;
}
-bool MessageHandler::onCall(llvm::StringRef method, llvm::json::Value params,
- llvm::json::Value id) {
- Logger::info("--> {0}({1})", method, id);
+bool MessageHandler::onCall(llvm::StringRef Method, llvm::json::Value Params,
+ llvm::json::Value Id) {
+ Logger::info("--> {0}({1})", Method, Id);
- Reply reply(id, method, transport, transportOutputMutex);
+ Reply Reply(Id, Method, Transport, TransportOutputMutex);
- auto it = methodHandlers.find(method);
- if (it != methodHandlers.end()) {
- it->second(std::move(params), std::move(reply));
+ auto It = MethodHandlers.find(Method);
+ if (It != MethodHandlers.end()) {
+ It->second(std::move(Params), std::move(Reply));
} else {
- reply(llvm::make_error<LSPError>("method not found: " + method.str(),
+ Reply(llvm::make_error<LSPError>("method not found: " + Method.str(),
ErrorCode::MethodNotFound));
}
return true;
}
-bool MessageHandler::onReply(llvm::json::Value id,
- llvm::Expected<llvm::json::Value> result) {
+bool MessageHandler::onReply(llvm::json::Value Id,
+ llvm::Expected<llvm::json::Value> Result) {
// Find the response handler in the mapping. If it exists, move it out of the
// mapping and erase it.
- ResponseHandlerTy responseHandler;
+ ResponseHandlerTy ResponseHandler;
{
- std::lock_guard<std::mutex> responseHandlersLock(responseHandlersMutex);
- auto it = responseHandlers.find(debugString(id));
- if (it != responseHandlers.end()) {
- responseHandler = std::move(it->second);
- responseHandlers.erase(it);
+ std::lock_guard<std::mutex> responseHandlersLock(ResponseHandlerTy);
+ auto It = ResponseHandlers.find(debugString(Id));
+ if (It != ResponseHandlers.end()) {
+ ResponseHandler = std::move(It->second);
+ ResponseHandlers.erase(It);
}
}
// If we found a response handler, invoke it. Otherwise, log an error.
- if (responseHandler.second) {
- Logger::info("--> reply:{0}({1})", responseHandler.first, id);
- responseHandler.second(std::move(id), std::move(result));
+ if (ResponseHandler.second) {
+ Logger::info("--> reply:{0}({1})", ResponseHandler.first, Id);
+ ResponseHandler.second(std::move(Id), std::move(Result));
} else {
Logger::error(
"received a reply with ID {0}, but there was no such outgoing request",
- id);
- if (!result)
- llvm::consumeError(result.takeError());
+ Id);
+ if (!Result)
+ llvm::consumeError(Result.takeError());
}
return true;
}
@@ -147,155 +147,155 @@ bool MessageHandler::onReply(llvm::json::Value id,
//===----------------------------------------------------------------------===//
/// Encode the given error as a JSON object.
-static llvm::json::Object encodeError(llvm::Error error) {
- std::string message;
- ErrorCode code = ErrorCode::UnknownErrorCode;
- auto handlerFn = [&](const LSPError &lspError) -> llvm::Error {
- message = lspError.message;
- code = lspError.code;
+static llvm::json::Object encodeError(llvm::Error Error) {
+ std::string Message;
+ ErrorCode Code = ErrorCode::UnknownErrorCode;
+ auto HandlerFn = [&](const LSPError &LspError) -> llvm::Error {
+ Message = LspError.message;
+ Code = LspError.code;
return llvm::Error::success();
};
- if (llvm::Error unhandled = llvm::handleErrors(std::move(error), handlerFn))
- message = llvm::toString(std::move(unhandled));
+ if (llvm::Error Unhandled = llvm::handleErrors(std::move(Error), HandlerFn))
+ Message = llvm::toString(std::move(Unhandled));
return llvm::json::Object{
- {"message", std::move(message)},
- {"code", int64_t(code)},
+ {"message", std::move(Message)},
+ {"code", int64_t(Code)},
};
}
/// Decode the given JSON object into an error.
-llvm::Error decodeError(const llvm::json::Object &o) {
- StringRef msg = o.getString("message").value_or("Unspecified error");
- if (std::optional<int64_t> code = o.getInteger("code"))
- return llvm::make_error<LSPError>(msg.str(), ErrorCode(*code));
+llvm::Error decodeError(const llvm::json::Object &O) {
+ StringRef Msg = O.getString("message").value_or("Unspecified error");
+ if (std::optional<int64_t> Code = O.getInteger("code"))
+ return llvm::make_error<LSPError>(Msg.str(), ErrorCode(*Code));
return llvm::make_error<llvm::StringError>(llvm::inconvertibleErrorCode(),
- msg.str());
+ Msg.str());
}
-void JSONTransport::notify(StringRef method, llvm::json::Value params) {
+void JSONTransport::notify(StringRef Method, llvm::json::Value Params) {
sendMessage(llvm::json::Object{
{"jsonrpc", "2.0"},
- {"method", method},
- {"params", std::move(params)},
+ {"method", Method},
+ {"params", std::move(Params)},
});
}
-void JSONTransport::call(StringRef method, llvm::json::Value params,
- llvm::json::Value id) {
+void JSONTransport::call(StringRef Method, llvm::json::Value Params,
+ llvm::json::Value Id) {
sendMessage(llvm::json::Object{
{"jsonrpc", "2.0"},
- {"id", std::move(id)},
- {"method", method},
- {"params", std::move(params)},
+ {"id", std::move(Id)},
+ {"method", Method},
+ {"params", std::move(Params)},
});
}
-void JSONTransport::reply(llvm::json::Value id,
- llvm::Expected<llvm::json::Value> result) {
- if (result) {
+void JSONTransport::reply(llvm::json::Value Id,
+ llvm::Expected<llvm::json::Value> Result) {
+ if (Result) {
return sendMessage(llvm::json::Object{
{"jsonrpc", "2.0"},
- {"id", std::move(id)},
- {"result", std::move(*result)},
+ {"id", std::move(Id)},
+ {"result", std::move(*Result)},
});
}
sendMessage(llvm::json::Object{
{"jsonrpc", "2.0"},
- {"id", std::move(id)},
- {"error", encodeError(result.takeError())},
+ {"id", std::move(Id)},
+ {"error", encodeError(Result.takeError())},
});
}
-llvm::Error JSONTransport::run(MessageHandler &handler) {
- std::string json;
- while (!in->isEndOfInput()) {
- if (in->hasError()) {
+llvm::Error JSONTransport::run(MessageHandler &Handler) {
+ std::string Json;
+ while (!In->isEndOfInput()) {
+ if (In->hasError()) {
return llvm::errorCodeToError(
std::error_code(errno, std::system_category()));
}
- if (succeeded(in->readMessage(json))) {
- if (llvm::Expected<llvm::json::Value> doc = llvm::json::parse(json)) {
- if (!handleMessage(std::move(*doc), handler))
+ if (succeeded(In->readMessage(Json))) {
+ if (llvm::Expected<llvm::json::Value> Doc = llvm::json::parse(Json)) {
+ if (!handleMessage(std::move(*Doc), Handler))
return llvm::Error::success();
} else {
- Logger::error("JSON parse error: {0}", llvm::toString(doc.takeError()));
+ Logger::error("JSON parse error: {0}", llvm::toString(Doc.takeError()));
}
}
}
return llvm::errorCodeToError(std::make_error_code(std::errc::io_error));
}
-void JSONTransport::sendMessage(llvm::json::Value msg) {
- outputBuffer.clear();
- llvm::raw_svector_ostream os(outputBuffer);
- os << llvm::formatv(prettyOutput ? "{0:2}\n" : "{0}", msg);
- out << "Content-Length: " << outputBuffer.size() << "\r\n\r\n"
- << outputBuffer;
- out.flush();
- Logger::debug(">>> {0}\n", outputBuffer);
+void JSONTransport::sendMessage(llvm::json::Value Msg) {
+ OutputBuffer.clear();
+ llvm::raw_svector_ostream os(OutputBuffer);
+ os << llvm::formatv(PrettyOutput ? "{0:2}\n" : "{0}", Msg);
+ Out << "Content-Length: " << OutputBuffer.size() << "\r\n\r\n"
+ << OutputBuffer;
+ Out.flush();
+ Logger::debug(">>> {0}\n", OutputBuffer);
}
-bool JSONTransport::handleMessage(llvm::json::Value msg,
- MessageHandler &handler) {
+bool JSONTransport::handleMessage(llvm::json::Value Msg,
+ MessageHandler &Handler) {
// Message must be an object with "jsonrpc":"2.0".
- llvm::json::Object *object = msg.getAsObject();
- if (!object ||
- object->getString("jsonrpc") != std::optional<StringRef>("2.0"))
+ llvm::json::Object *Object = Msg.getAsObject();
+ if (!Object ||
+ Object->getString("jsonrpc") != std::optional<StringRef>("2.0"))
return false;
// `id` may be any JSON value. If absent, this is a notification.
- std::optional<llvm::json::Value> id;
- if (llvm::json::Value *i = object->get("id"))
- id = std::move(*i);
- std::optional<StringRef> method = object->getString("method");
+ std::optional<llvm::json::Value> Id;
+ if (llvm::json::Value *I = Object->get("id"))
+ Id = std::move(*I);
+ std::optional<StringRef> Method = Object->getString("method");
// This is a response.
- if (!method) {
- if (!id)
+ if (!Method) {
+ if (!Id)
return false;
- if (auto *err = object->getObject("error"))
- return handler.onReply(std::move(*id), decodeError(*err));
+ if (auto *Err = Object->getObject("error"))
+ return Handler.onReply(std::move(*Id), decodeError(*Err));
// result should be given, use null if not.
- llvm::json::Value result = nullptr;
- if (llvm::json::Value *r = object->get("result"))
- result = std::move(*r);
- return handler.onReply(std::move(*id), std::move(result));
+ llvm::json::Value Result = nullptr;
+ if (llvm::json::Value *R = Object->get("result"))
+ Result = std::move(*R);
+ return Handler.onReply(std::move(*Id), std::move(Result));
}
// Params should be given, use null if not.
- llvm::json::Value params = nullptr;
- if (llvm::json::Value *p = object->get("params"))
- params = std::move(*p);
+ llvm::json::Value Params = nullptr;
+ if (llvm::json::Value *P = Object->get("params"))
+ Params = std::move(*P);
- if (id)
- return handler.onCall(*method, std::move(params), std::move(*id));
- return handler.onNotify(*method, std::move(params));
+ if (Id)
+ return Handler.onCall(*Method, std::move(Params), std::move(*Id));
+ return Handler.onNotify(*Method, std::move(Params));
}
/// Tries to read a line up to and including \n.
/// If failing, feof(), ferror(), or shutdownRequested() will be set.
-LogicalResult readLine(std::FILE *in, SmallVectorImpl<char> &out) {
+LogicalResult readLine(std::FILE *In, SmallVectorImpl<char> &Out) {
// Big enough to hold any reasonable header line. May not fit content lines
// in delimited mode, but performance doesn't matter for that mode.
- static constexpr int bufSize = 128;
- size_t size = 0;
- out.clear();
+ static constexpr int BufSize = 128;
+ size_t Size = 0;
+ Out.clear();
for (;;) {
- out.resize_for_overwrite(size + bufSize);
- if (!std::fgets(&out[size], bufSize, in))
+ Out.resize_for_overwrite(Size + BufSize);
+ if (!std::fgets(&Out[Size], BufSize, In))
return failure();
- clearerr(in);
+ clearerr(In);
// If the line contained null bytes, anything after it (including \n) will
// be ignored. Fortunately this is not a legal header or JSON.
- size_t read = std::strlen(&out[size]);
- if (read > 0 && out[size + read - 1] == '\n') {
- out.resize(size + read);
+ size_t Read = std::strlen(&Out[Size]);
+ if (Read > 0 && Out[Size + Read - 1] == '\n') {
+ Out.resize(Size + Read);
return success();
}
- size += read;
+ Size += Read;
}
}
@@ -303,20 +303,20 @@ LogicalResult readLine(std::FILE *in, SmallVectorImpl<char> &out) {
// - ferror(), feof(), or shutdownRequested() are set.
// - Content-Length is missing or empty (protocol error)
LogicalResult
-JSONTransportInputOverFile::readStandardMessage(std::string &json) {
+JSONTransportInputOverFile::readStandardMessage(std::string &Json) {
// A Language Server Protocol message starts with a set of HTTP headers,
// delimited by \r\n, and terminated by an empty line (\r\n).
- unsigned long long contentLength = 0;
- llvm::SmallString<128> line;
+ unsigned long long ContentLength = 0;
+ llvm::SmallString<128> Line;
while (true) {
- if (feof(in) || hasError() || failed(readLine(in, line)))
+ if (feof(In) || hasError() || failed(readLine(In, Line)))
return failure();
// Content-Length is a mandatory header, and the only one we handle.
- StringRef lineRef = line;
- if (lineRef.consume_front("Content-Length: ")) {
- llvm::getAsUnsignedInteger(lineRef.trim(), 0, contentLength);
- } else if (!lineRef.trim().empty()) {
+ StringRef LineRef = Line;
+ if (LineRef.consume_front("Content-Length: ")) {
+ llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
+ } else if (!LineRef.trim().empty()) {
// It's another header, ignore it.
continue;
} else {
@@ -326,19 +326,19 @@ JSONTransportInputOverFile::readStandardMessage(std::string &json) {
}
// The fuzzer likes crashing us by sending "Content-Length: 9999999999999999"
- if (contentLength == 0 || contentLength > 1 << 30)
+ if (ContentLength == 0 || ContentLength > 1 << 30)
return failure();
- json.resize(contentLength);
- for (size_t pos = 0, read; pos < contentLength; pos += read) {
- read = std::fread(&json[pos], 1, contentLength - pos, in);
- if (read == 0)
+ Json.resize(ContentLength);
+ for (size_t Pos = 0, Read; Pos < ContentLength; Pos += Read) {
+ Read = std::fread(&Json[Pos], 1, ContentLength - Pos, In);
+ if (Read == 0)
return failure();
// If we're done, the error was transient. If we're not done, either it was
// transient or we'll see it again on retry.
- clearerr(in);
- pos += read;
+ clearerr(In);
+ Pos += Read;
}
return success();
}
@@ -350,20 +350,20 @@ JSONTransportInputOverFile::readStandardMessage(std::string &json) {
/// When returning failure: feof(), ferror(), or shutdownRequested() will be
/// set.
LogicalResult
-JSONTransportInputOverFile::readDelimitedMessage(std::string &json) {
- json.clear();
- llvm::SmallString<128> line;
- while (succeeded(readLine(in, line))) {
- StringRef lineRef = line.str().trim();
- if (lineRef.starts_with("//")) {
+JSONTransportInputOverFile::readDelimitedMessage(std::string &Json) {
+ Json.clear();
+ llvm::SmallString<128> Line;
+ while (succeeded(readLine(In, Line))) {
+ StringRef LineRef = Line.str().trim();
+ if (LineRef.starts_with("//")) {
// Found a delimiter for the message.
- if (lineRef == "// -----")
+ if (LineRef == "// -----")
break;
continue;
}
- json += line;
+ Json += Line;
}
- return failure(ferror(in));
+ return failure(ferror(In));
}
>From 93232d53519b51088d900153965d13be24de4066 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Wed, 27 Aug 2025 07:46:30 +0000
Subject: [PATCH 7/8] Clang format files
---
llvm/include/llvm/Support/LSP/Logging.h | 9 +++------
llvm/include/llvm/Support/LSP/Protocol.h | 3 +--
llvm/include/llvm/Support/LSP/Transport.h | 2 +-
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/Support/LSP/Logging.h b/llvm/include/llvm/Support/LSP/Logging.h
index 6930a7cf246df..d1ecf113a5123 100644
--- a/llvm/include/llvm/Support/LSP/Logging.h
+++ b/llvm/include/llvm/Support/LSP/Logging.h
@@ -29,16 +29,13 @@ class Logger {
/// Initiate a log message at various severity levels. These should be called
/// after a call to `initialize`.
- template <typename... Ts>
- static void debug(const char *Fmt, Ts &&...Vals) {
+ template <typename... Ts> static void debug(const char *Fmt, Ts &&...Vals) {
log(Level::Debug, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
- template <typename... Ts>
- static void info(const char *Fmt, Ts &&...Vals) {
+ template <typename... Ts> static void info(const char *Fmt, Ts &&...Vals) {
log(Level::Info, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
- template <typename... Ts>
- static void error(const char *Fmt, Ts &&...Vals) {
+ template <typename... Ts> static void error(const char *Fmt, Ts &&...Vals) {
log(Level::Error, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
}
diff --git a/llvm/include/llvm/Support/LSP/Protocol.h b/llvm/include/llvm/Support/LSP/Protocol.h
index a01a1a0a00ef2..93b82f1e581f8 100644
--- a/llvm/include/llvm/Support/LSP/Protocol.h
+++ b/llvm/include/llvm/Support/LSP/Protocol.h
@@ -1248,8 +1248,7 @@ llvm::json::Value toJSON(const CodeAction &);
} // namespace llvm
namespace llvm {
-template <>
-struct format_provider<llvm::lsp::Position> {
+template <> struct format_provider<llvm::lsp::Position> {
static void format(const llvm::lsp::Position &pos, raw_ostream &os,
StringRef style) {
assert(style.empty() && "style modifiers for this type are not supported");
diff --git a/llvm/include/llvm/Support/LSP/Transport.h b/llvm/include/llvm/Support/LSP/Transport.h
index 45a0b6a78e304..ccd7f213aa277 100644
--- a/llvm/include/llvm/Support/LSP/Transport.h
+++ b/llvm/include/llvm/Support/LSP/Transport.h
@@ -15,12 +15,12 @@
#ifndef LLVM_SUPPORT_LSP_TRANSPORT_H
#define LLVM_SUPPORT_LSP_TRANSPORT_H
-#include "llvm/Support/LSP/Logging.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormatAdapters.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/LSP/Logging.h"
#include "llvm/Support/LSP/Protocol.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
>From feec5e1c12db4b3cae766d621ade59c461f2d4a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albert=20Havli=C4=8Dek?= <ahavlicek at azul.com>
Date: Wed, 27 Aug 2025 11:50:38 +0000
Subject: [PATCH 8/8] Fix object inclusion problems
---
llvm/lib/Support/CMakeLists.txt | 1 -
llvm/lib/Support/LSP/CMakeLists.txt | 14 ++++----------
mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt | 1 +
mlir/lib/Tools/mlir-pdll-lsp-server/CMakeLists.txt | 1 +
mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt | 1 +
5 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 82a32ba817b10..d739f5c0f28b4 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -289,7 +289,6 @@ add_llvm_component_library(LLVMSupport
${ALLOCATOR_FILES}
$<TARGET_OBJECTS:LLVMSupportBlake3>
- $<TARGET_OBJECTS:LLVMSupportLSP>
# System
Atomic.cpp
diff --git a/llvm/lib/Support/LSP/CMakeLists.txt b/llvm/lib/Support/LSP/CMakeLists.txt
index 353e649105c17..132dc78b23495 100644
--- a/llvm/lib/Support/LSP/CMakeLists.txt
+++ b/llvm/lib/Support/LSP/CMakeLists.txt
@@ -2,16 +2,10 @@ add_llvm_library(LLVMSupportLSP STATIC
Protocol.cpp
Transport.cpp
Logging.cpp
-)
-target_include_directories(LLVMSupportLSP
- PUBLIC
- $<BUILD_INTERFACE:${LLVM_MAIN_INCLUDE_DIR}>
- $<BUILD_INTERFACE:${LLVM_LIBRARY_DIR}/Support/LSP>
- $<INSTALL_INTERFACE:include> # for installation
-)
+ ADDITIONAL_HEADER_DIRS
+ ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/LSP
-target_link_libraries(LLVMSupportLSP
- PUBLIC
- LLVMSupport
+ LINK_LIBS
+ LLVMSupport
)
diff --git a/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt b/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt
index d04d5156fb3c5..db665dd31eaab 100644
--- a/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt
+++ b/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt
@@ -13,4 +13,5 @@ add_mlir_library(MLIRLspServerLib
MLIRIR
MLIRLspServerSupportLib
MLIRParser
+ LLVMSupportLSP
)
diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/CMakeLists.txt b/mlir/lib/Tools/mlir-pdll-lsp-server/CMakeLists.txt
index bf25b7e0a64f3..fc1f90b19dc4a 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/CMakeLists.txt
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/CMakeLists.txt
@@ -11,4 +11,5 @@ llvm_add_library(MLIRPdllLspServerLib
MLIRPDLLCodeGen
MLIRPDLLParser
MLIRLspServerSupportLib
+ LLVMSupportLSP
)
diff --git a/mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt b/mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt
index 80fc1ffe4029a..67819247d72cb 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt
+++ b/mlir/lib/Tools/tblgen-lsp-server/CMakeLists.txt
@@ -17,4 +17,5 @@ llvm_add_library(TableGenLspServerLib
LINK_LIBS PUBLIC
MLIRLspServerSupportLib
MLIRSupport
+ LLVMSupportLSP
)
More information about the llvm-commits
mailing list