Skip to content

Commit

Permalink
Ensure we respond to requests with IDs or client will hang
Browse files Browse the repository at this point in the history
  • Loading branch information
searls committed Feb 10, 2023
1 parent 961ba18 commit 3a0e7db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/standard/lsp/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def handle_unsupported_method(request, method = request[:method])
@logger.puts "Unsupported Method: #{method}"
end

def handle_method_missing(request)
if request.key?(:id)
@writer.write({id: request[:id], result: nil})
end
end

private

def format_file(file_uri)
Expand Down
7 changes: 3 additions & 4 deletions lib/standard/lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def initialize(standardizer)

def start
@reader.read do |request|
next unless request.key?(:method) # ignore responses without methods

method = request[:method]
if (route = @routes.for(method))
if !request.key?(:method)
@routes.handle_method_missing(request)
elsif (route = @routes.for(request[:method]))
route.call(request)
else
@routes.handle_unsupported_method(request)
Expand Down
18 changes: 17 additions & 1 deletion test/standard/runners/lsp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_unknown_commands
}, msgs.last)
end

def test_methodless_requests_are_ignored
def test_methodless_requests_are_acked
msgs, err = run_server_on_requests(
{
id: 1,
Expand All @@ -279,6 +279,22 @@ def test_methodless_requests_are_ignored
}
)

assert_equal "", err.string
assert_equal({
id: 1,
jsonrpc: "2.0",
result: nil
}, msgs.last)
end

def test_methodless_and_idless_requests_are_dropped
msgs, err = run_server_on_requests(
{
jsonrpc: "2.0",
result: {}
}
)

assert_equal "", err.string
assert_empty msgs
end
Expand Down

0 comments on commit 3a0e7db

Please sign in to comment.