Skip to content

Commit

Permalink
Update to work with latest ruby-lsp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Mar 24, 2024
1 parent 66c069b commit 9c5d892
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GIT

GIT
remote: https://github.com/Shopify/ruby-lsp.git
revision: 8b4303f9688b5fafebe260031c34e1a310c97d3c
revision: 662ba62a629e84b893e02952e7561112ce6cb752
branch: main
specs:
ruby-lsp (0.14.7)
Expand All @@ -23,7 +23,7 @@ PATH
actionpack (>= 6.0)
activerecord (>= 6.0)
railties (>= 6.0)
ruby-lsp (>= 0.14.2, < 0.15.0)
ruby-lsp
sorbet-runtime (>= 0.5.9897)

GEM
Expand Down
2 changes: 1 addition & 1 deletion ruby-lsp-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
spec.add_dependency("actionpack", ">= 6.0")
spec.add_dependency("activerecord", ">= 6.0")
spec.add_dependency("railties", ">= 6.0")
spec.add_dependency("ruby-lsp", ">= 0.14.2", "< 0.15.0")
spec.add_dependency("ruby-lsp") # TODO: bump, ">= 0.14.2", "< 0.15.0")
spec.add_dependency("sorbet-runtime", ">= 0.5.9897")
end
27 changes: 10 additions & 17 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,18 @@ class NestedTest < ActiveSupport::TestCase
private

def generate_code_lens_for_source(source)
uri = URI("file:///fake.rb")
store = RubyLsp::Store.new
store.set(uri: uri, source: source, version: 1)

capture_subprocess_io do
RubyLsp::Executor.new(store, @message_queue).execute({
method: "initialized",
params: {},
})
end

response = RubyLsp::Executor.new(store, @message_queue).execute({
method: "textDocument/codeLens",
params: { textDocument: { uri: uri }, position: { line: 0, character: 0 } },
})
with_server(source) do |server, uri|
server.process_message(
id: 1,
method: "textDocument/codeLens",
params: { textDocument: { uri: uri }, position: { line: 0, character: 0 } },
)

assert_nil(response.error)
result = server.pop_response

response.response
assert_instance_of(RubyLsp::Result, result)
result.response
end
end
end
end
Expand Down
30 changes: 8 additions & 22 deletions test/ruby_lsp_rails/definition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,15 @@ def baz; end
private

def generate_definitions_for_source(source, position)
uri = URI("file:///fake.rb")
store = RubyLsp::Store.new
store.set(uri: uri, source: source, version: 1)

executor = RubyLsp::Executor.new(store, @message_queue)
executor.instance_variable_get(:@index).index_single(
RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)), source
)

capture_subprocess_io do
RubyLsp::Executor.new(store, @message_queue).execute({
method: "initialized",
params: {},
})
with_server(source) do |server, uri|
server.process_message(
id: 1,
method: "textDocument/definition",
params: { textDocument: { uri: uri }, position: position },
)

server.pop_response.response
end

response = executor.execute({
method: "textDocument/definition",
params: { textDocument: { uri: uri }, position: position },
})

assert_nil(response.error)
response.response
end
end
end
Expand Down
26 changes: 8 additions & 18 deletions test/ruby_lsp_rails/document_symbol_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,15 @@ class FooModel < ApplicationRecord
private

def generate_document_symbols_for_source(source)
uri = URI("file:///fake.rb")
store = RubyLsp::Store.new
store.set(uri: uri, source: source, version: 1)

capture_subprocess_io do
RubyLsp::Executor.new(store, @message_queue).execute({
method: "initialized",
params: {},
})
with_server(source) do |server, uri|
server.process_message(
id: 1,
method: "textDocument/documentSymbol",
params: { textDocument: { uri: uri }, position: { line: 0, character: 0 } },
)

server.pop_response.response
end

response = RubyLsp::Executor.new(store, @message_queue).execute({
method: "textDocument/documentSymbol",
params: { textDocument: { uri: uri }, position: { line: 0, character: 0 } },
})

assert_nil(response.error)

response.response
end
end
end
Expand Down
33 changes: 7 additions & 26 deletions test/ruby_lsp_rails/hover_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,15 @@ class ActiveRecord::Base
private

def hover_on_source(source, position)
uri = URI("file:///fake.rb")
store = RubyLsp::Store.new
store.set(uri: uri, source: source, version: 1)

executor = RubyLsp::Executor.new(store, @message_queue)
executor.instance_variable_get(:@index).index_single(
RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)), source
)

capture_subprocess_io do
RubyLsp::Executor.new(store, @message_queue).execute({
method: "initialized",
params: {},
})
end

response = executor.execute(
{
with_server(source) do |server, uri|
server.process_message(
id: 1,
method: "textDocument/hover",
params: {
textDocument: { uri: uri },
position: position,
},
},
)
params: { textDocument: { uri: uri }, position: position },
)

assert_nil(response.error)
response.response
server.pop_response.response
end
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,44 @@

module ActiveSupport
class TestCase
extend T::Sig

def dummy_root
File.expand_path("#{__dir__}/dummy")
end

# TODO: share with ruby-lsp?
sig do
type_parameters(:T)
.params(
source: T.nilable(String),
uri: URI::Generic,
block: T.proc.params(server: RubyLsp::Server, uri: URI::Generic).returns(T.type_parameter(:T)),
).returns(T.type_parameter(:T))
end
def with_server(source = nil, uri = URI("file:///fake.rb"), &block)
server = ::RubyLsp::Server.new(test_mode: true)
server.process_message({ method: "initialized" })

if source
server.process_message({
id: 1,
method: "textDocument/didOpen",
params: {
textDocument: {
uri: uri,
text: source,
version: 1,
},
},
})
end

index = server.index
index.index_single(RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)), source)
block.call(server, uri)
ensure
T.must(server).run_shutdown
end
end
end

0 comments on commit 9c5d892

Please sign in to comment.