Skip to content

Commit

Permalink
Fix breaking changes from Ruby LSP v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Aug 8, 2023
1 parent aae3135 commit 8d2eb60
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ 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

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

super(emitter, message_queue)
Expand Down Expand Up @@ -109,6 +107,8 @@ def on_class(node)

sig { params(node: SyntaxTree::Node, name: String, command: String, kind: Symbol).void }
def add_test_code_lens(node, name:, command:, kind:)
return unless @path

arguments = [
@path,
name,
Expand Down
32 changes: 31 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,39 @@ module Rails
class Extension < ::RubyLsp::Extension
extend T::Sig

sig { returns(RailsClient) }
def client
@client ||= T.let(RailsClient.new, T.nilable(RailsClient))
end

sig { override.void }
def activate
RubyLsp::Rails::RailsClient.instance.check_if_server_is_running!
client.check_if_server_is_running!
end

sig { override.void }
def deactivate; end

# Creates a new CodeLens listener. This method is invoked on every CodeLens request
sig do
override.params(
uri: URI::Generic,
emitter: EventEmitter,
message_queue: Thread::Queue,
).returns(T.nilable(Listener[T::Array[Interface::CodeLens]]))
end
def create_code_lens_listener(uri, emitter, message_queue)
CodeLens.new(uri, emitter, message_queue)
end

sig do
override.params(
emitter: EventEmitter,
message_queue: Thread::Queue,
).returns(T.nilable(Listener[T.nilable(Interface::Hover)]))
end
def create_hover_listener(emitter, message_queue)
Hover.new(client, emitter, message_queue)
end

sig { override.returns(String) }
Expand Down
11 changes: 5 additions & 6 deletions lib/ruby_lsp/ruby_lsp_rails/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ 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

sig { params(emitter: RubyLsp::EventEmitter, message_queue: Thread::Queue).void }
def initialize(emitter, message_queue)
super
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)
@client = client
emitter.register(self, :on_const)
end

sig { params(node: SyntaxTree::Const).void }
def on_const(node)
model = RailsClient.instance.model(node.value)
model = @client.model(node.value)
return if model.nil?

schema_file = model[:schema_file]
Expand Down
2 changes: 0 additions & 2 deletions lib/ruby_lsp/ruby_lsp_rails/rails_client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# typed: strict
# frozen_string_literal: true

require "singleton"
require "net/http"

module RubyLsp
Expand All @@ -10,7 +9,6 @@ class RailsClient
class ServerAddressUnknown < StandardError; end

extend T::Sig
include Singleton

SERVER_NOT_RUNNING_MESSAGE = "Rails server is not running. " \
"To get Rails features in the editor, boot the Rails server"
Expand Down

0 comments on commit 8d2eb60

Please sign in to comment.