Skip to content

Commit

Permalink
Move listener registration to the extension activation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jul 12, 2023
1 parent 6f83418 commit 08c95f9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 0 additions & 2 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class CodeLens < ::RubyLsp::Listener
ResponseType = type_member { { fixed: T::Array[::RubyLsp::Interface::CodeLens] } }
BASE_COMMAND = "bin/rails test"

::RubyLsp::Requests::CodeLens.add_listener(self)

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

Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Extension < ::RubyLsp::Extension

sig { override.void }
def activate
::RubyLsp::Requests::Hover.add_listener(RubyLsp::Rails::Hover)
::RubyLsp::Requests::CodeLens.add_listener(RubyLsp::Rails::CodeLens)

RubyLsp::Rails::RailsClient.instance.check_if_server_is_running!
end

Expand Down
2 changes: 0 additions & 2 deletions lib/ruby_lsp/ruby_lsp_rails/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class Hover < ::RubyLsp::Listener

ResponseType = type_member { { fixed: T.nilable(::RubyLsp::Interface::Hover) } }

::RubyLsp::Requests::Hover.add_listener(self)

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

Expand Down
2 changes: 2 additions & 0 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module RubyLsp
module Rails
class CodeLensTest < ActiveSupport::TestCase
setup do
::RubyLsp::Requests::CodeLens.add_listener(RubyLsp::Rails::CodeLens)
@message_queue = Thread::Queue.new
@store = RubyLsp::Store.new
end

def teardown
::RubyLsp::Requests::CodeLens.listeners.clear
T.must(@message_queue).close
end

Expand Down
3 changes: 3 additions & 0 deletions test/ruby_lsp_rails/extension_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ExtensionTest < ActiveSupport::TestCase
RubyLsp::Rails::RailsClient.stubs(instance: rails_client)
extension = Extension.new
assert_predicate(extension, :activate)
ensure
::RubyLsp::Requests::Hover.listeners.clear
::RubyLsp::Requests::CodeLens.listeners.clear
end
end
end
Expand Down

0 comments on commit 08c95f9

Please sign in to comment.