Skip to content

Commit

Permalink
Store the client name
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan Soni committed Jan 9, 2024
1 parent fd904d3 commit 6ce064d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_lsp/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
13 changes: 13 additions & 0 deletions test/executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6ce064d

Please sign in to comment.