diff --git a/lib/standard/lsp/routes.rb b/lib/standard/lsp/routes.rb index 54a05abc..854086bc 100644 --- a/lib/standard/lsp/routes.rb +++ b/lib/standard/lsp/routes.rb @@ -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) diff --git a/lib/standard/lsp/server.rb b/lib/standard/lsp/server.rb index 8f37ef0a..620d23f3 100644 --- a/lib/standard/lsp/server.rb +++ b/lib/standard/lsp/server.rb @@ -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) diff --git a/test/standard/runners/lsp_test.rb b/test/standard/runners/lsp_test.rb index 8061e090..9a58c9bd 100644 --- a/test/standard/runners/lsp_test.rb +++ b/test/standard/runners/lsp_test.rb @@ -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, @@ -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