From 6ce064dd0480108c9acb6617dd763982f8c3bacc Mon Sep 17 00:00:00 2001 From: Aryan Soni Date: Tue, 9 Jan 2024 15:35:43 -0500 Subject: [PATCH] Store the client name --- lib/ruby_lsp/executor.rb | 3 +++ lib/ruby_lsp/store.rb | 3 +++ test/executor_test.rb | 13 +++++++++++++ test/store_test.rb | 5 +++++ 4 files changed, 24 insertions(+) diff --git a/lib/ruby_lsp/executor.rb b/lib/ruby_lsp/executor.rb index 3136272906..05f2d8bfab 100644 --- a/lib/ruby_lsp/executor.rb +++ b/lib/ruby_lsp/executor.rb @@ -623,6 +623,9 @@ def initialize_request(options) workspace_uri = options.dig(:workspaceFolders, 0, :uri) @store.workspace_uri = URI(workspace_uri) if workspace_uri + client_name = options.dig(:clientInfo, :name) + @store.client_name = client_name if client_name + encodings = options.dig(:capabilities, :general, :positionEncodings) @store.encoding = if encodings.nil? || encodings.empty? Constant::PositionEncodingKind::UTF16 diff --git a/lib/ruby_lsp/store.rb b/lib/ruby_lsp/store.rb index 540bb11c60..7c14fe9be7 100644 --- a/lib/ruby_lsp/store.rb +++ b/lib/ruby_lsp/store.rb @@ -23,6 +23,9 @@ class Store sig { returns(T::Hash[Symbol, RequestConfig]) } attr_accessor :features_configuration + sig { returns(T.nilable(String)) } + attr_accessor :client_name + sig { void } def initialize @state = T.let({}, T::Hash[String, Document]) diff --git a/test/executor_test.rb b/test/executor_test.rb index 7e132390f2..effd3a440a 100644 --- a/test/executor_test.rb +++ b/test/executor_test.rb @@ -353,6 +353,19 @@ def test_returns_void_for_unhandled_request assert_same(RubyLsp::VOID, result.response) end + def test_initialize_sets_client_name + @executor.execute({ + method: "initialize", + params: { + initializationOptions: {}, + capabilities: {}, + clientInfo: { name: "FooClient" }, + }, + }) + + assert_equal("FooClient", @store.client_name) + end + private def with_uninstalled_rubocop(&block) diff --git a/test/store_test.rb b/test/store_test.rb index 8c5f88aaec..de44f00a7b 100644 --- a/test/store_test.rb +++ b/test/store_test.rb @@ -192,4 +192,9 @@ def test_push_edits @store.get(uri), ) end + + def test_client_name + @store.client_name = "FooClient" + assert_equal("FooClient", @store.client_name) + end end