Skip to content

Commit

Permalink
Use _response for listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Sep 12, 2023
1 parent e187810 commit 9954711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class CodeLens < ::RubyLsp::Listener
BASE_COMMAND = "bin/rails test"

sig { override.returns(ResponseType) }
attr_reader :response
attr_reader :_response

sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue).void }
def initialize(uri, emitter, message_queue)
@response = T.let([], ResponseType)
@_response = T.let([], ResponseType)
@path = T.let(uri.to_standardized_path, T.nilable(String))
emitter.register(self, :on_command, :on_class, :on_def)

Expand Down Expand Up @@ -121,23 +121,23 @@ def add_test_code_lens(node, name:, command:, kind:)
},
]

@response << create_code_lens(
@_response << create_code_lens(
node,
title: "Run",
command_name: "rubyLsp.runTest",
arguments: arguments,
data: { type: "test", kind: kind },
)

@response << create_code_lens(
@_response << create_code_lens(
node,
title: "Run In Terminal",
command_name: "rubyLsp.runTestInTerminal",
arguments: arguments,
data: { type: "test_in_terminal", kind: kind },
)

@response << create_code_lens(
@_response << create_code_lens(
node,
title: "Debug",
command_name: "rubyLsp.debugTest",
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby_lsp/ruby_lsp_rails/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Hover < ::RubyLsp::Listener
ResponseType = type_member { { fixed: T.nilable(::RubyLsp::Interface::Hover) } }

sig { override.returns(ResponseType) }
attr_reader :response
attr_reader :_response

sig { params(client: RailsClient, emitter: RubyLsp::EventEmitter, message_queue: Thread::Queue).void }
def initialize(client, emitter, message_queue)
super(emitter, message_queue)

@response = T.let(nil, ResponseType)
@_response = T.let(nil, ResponseType)
@client = client
emitter.register(self, :on_const, :on_command, :on_const_path_ref, :on_call)
end
Expand All @@ -46,26 +46,26 @@ def on_const(node)
end
content << model[:columns].map { |name, type| "**#{name}**: #{type}\n" }.join("\n")
contents = RubyLsp::Interface::MarkupContent.new(kind: "markdown", value: content)
@response = RubyLsp::Interface::Hover.new(range: range_from_syntax_tree_node(node), contents: contents)
@_response = RubyLsp::Interface::Hover.new(range: range_from_syntax_tree_node(node), contents: contents)
end

sig { params(node: SyntaxTree::Command).void }
def on_command(node)
message = node.message
@response = generate_rails_document_link_hover(message.value, message)
@_response = generate_rails_document_link_hover(message.value, message)
end

sig { params(node: SyntaxTree::ConstPathRef).void }
def on_const_path_ref(node)
@response = generate_rails_document_link_hover(full_constant_name(node), node)
@_response = generate_rails_document_link_hover(full_constant_name(node), node)
end

sig { params(node: SyntaxTree::CallNode).void }
def on_call(node)
message = node.message
return if message.is_a?(Symbol)

@response = generate_rails_document_link_hover(message.value, message)
@_response = generate_rails_document_link_hover(message.value, message)
end

private
Expand Down

0 comments on commit 9954711

Please sign in to comment.