Skip to content

Commit

Permalink
closer! everything makes sense except for this range end value
Browse files Browse the repository at this point in the history
  • Loading branch information
searls committed May 17, 2024
1 parent 72cd1c3 commit fe2fa67
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
3 changes: 1 addition & 2 deletions lib/ruby_lsp/standard/wraps_built_in_lsp_standardizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def init!
end

def run_formatting(uri, document)
# TODO: this isn't being triggered by my test
@standardizer.format(uri_to_path(uri), document.source)
end

Expand Down Expand Up @@ -72,7 +71,7 @@ def run_diagnostic(uri, document)

# duplicated from: lib/standard/lsp/routes.rb
def uri_to_path(uri)
uri.sub(%r{^file://}, "")
uri.to_s.sub(%r{^file://}, "")
end

# lifted from:
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions test/fixture/ruby_lsp/simple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s = 'hi'
puts s
60 changes: 37 additions & 23 deletions test/ruby_lsp_addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_format
s = 'hello'
puts s
RUBY
with_server(source) do |server, uri|
with_server(source, "test/fixture/ruby_lsp/simple.rb") do |server, uri|
server.process_message(
id: 1,
method: "textDocument/formatting",
Expand All @@ -27,39 +27,53 @@ def test_format
result = server.pop_response

assert_instance_of(RubyLsp::Result, result)
refute_nil result.response
assert 1, result.response.size
assert_equal({
range: RubyLsp::Interface::Range.new(
start: RubyLsp::Interface::Position.new(line: 0, character: 0),
# Fails! Actual is line: 19, character: 19??????
end: RubyLsp::Interface::Position.new(line: 2, character: 5)
),
newText: <<~RUBY
s = "hello"
puts s
RUBY
}, result.response.first.to_hash)
end
end

private

# Lifted from here, because we need to override the formatter to "standard" in the test helper:
# https://github.com/Shopify/ruby-lsp/blob/4c1906172add4d5c39c35d3396aa29c768bfb898/lib/ruby_lsp/test_helper.rb#L20
def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typechecker: false, load_addons: true,
def with_server(source = nil, path = "fake.rb", pwd: "test/fixture/ruby_lsp", stub_no_typechecker: false, load_addons: true,
&block)
server = RubyLsp::Server.new(test_mode: true)
server.global_state.formatter = "standard" # <-- TODO this should work, right?
server.global_state.stubs(:typechecker).returns(false) if stub_no_typechecker
Dir.chdir pwd do
server = RubyLsp::Server.new(test_mode: true)
uri = Kernel.URI(File.join(server.global_state.workspace_path, path))
server.global_state.formatter = "standard" # <-- TODO this should work, right?
server.global_state.stubs(:typechecker).returns(false) if stub_no_typechecker

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

server.global_state.index.index_single(
RubyIndexer::IndexablePath.new(nil, uri.to_standardized_path),
source
)
server.load_addons if load_addons
block.call(server, uri)
server.global_state.index.index_single(
RubyIndexer::IndexablePath.new(nil, uri.to_standardized_path),
source
)
server.load_addons if load_addons
block.call(server, uri)
end
ensure
if load_addons
RubyLsp::Addon.addons.each(&:deactivate)
Expand Down

0 comments on commit fe2fa67

Please sign in to comment.