diff --git a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h b/mlir/include/mlir/Tools/lsp-server-support/Protocol.h --- a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h +++ b/mlir/include/mlir/Tools/lsp-server-support/Protocol.h @@ -167,6 +167,22 @@ bool fromJSON(const llvm::json::Value &value, ClientCapabilities &result, llvm::json::Path path); +//===----------------------------------------------------------------------===// +// ClientInfo +//===----------------------------------------------------------------------===// + +struct ClientInfo { + /// The name of the client as defined by the client. + std::string name; + + /// The client's version as defined by the client. + std::optional version; +}; + +/// Add support for JSON serialization. +bool fromJSON(const llvm::json::Value &value, ClientInfo &result, + llvm::json::Path path); + //===----------------------------------------------------------------------===// // InitializeParams //===----------------------------------------------------------------------===// @@ -185,6 +201,9 @@ /// The capabilities provided by the client (editor or tool). ClientCapabilities capabilities; + /// Information about the client. + std::optional clientInfo; + /// The initial trace setting. If omitted trace is disabled ('off'). std::optional trace; }; diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp --- a/mlir/lib/Tools/lsp-server-support/Protocol.cpp +++ b/mlir/lib/Tools/lsp-server-support/Protocol.cpp @@ -294,6 +294,21 @@ return true; } +//===----------------------------------------------------------------------===// +// ClientInfo +//===----------------------------------------------------------------------===// + +bool mlir::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); + return true; +} + //===----------------------------------------------------------------------===// // InitializeParams //===----------------------------------------------------------------------===// @@ -325,6 +340,8 @@ // 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); + return true; } diff --git a/mlir/test/mlir-lsp-server/initialize-params-invalid.test b/mlir/test/mlir-lsp-server/initialize-params-invalid.test --- a/mlir/test/mlir-lsp-server/initialize-params-invalid.test +++ b/mlir/test/mlir-lsp-server/initialize-params-invalid.test @@ -1,6 +1,6 @@ // RUN: mlir-lsp-server -lit-test < %s | FileCheck -strict-whitespace %s // Test with invalid initialize request parameters -{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":"","rootUri":"test:///workspace","capabilities":{},"trace":"verbose"}} +{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":"","rootUri":"test:///workspace","capabilities":{},"clientInfo":{"name": 10},"trace":"verbose"}} // CHECK: "id": 0, // CHECK-NEXT: "jsonrpc": "2.0", // CHECK-NEXT: "result": { diff --git a/mlir/test/mlir-lsp-server/initialize-params.test b/mlir/test/mlir-lsp-server/initialize-params.test --- a/mlir/test/mlir-lsp-server/initialize-params.test +++ b/mlir/test/mlir-lsp-server/initialize-params.test @@ -1,6 +1,6 @@ // RUN: mlir-lsp-server -lit-test < %s | FileCheck -strict-whitespace %s // Test initialize request parameters with rootUri -{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootUri":"test:///workspace","capabilities":{},"trace":"off"}} +{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootUri":"test:///workspace","capabilities":{},"clientInfo":{"name": "test", "version": "1.2.3"},"trace":"off"}} // CHECK: "id": 0, // CHECK-NEXT: "jsonrpc": "2.0", // CHECK-NEXT: "result": {