castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
423 stars 25 forks source link

Saving an empty file throws [NoMethodError] undefined method `length' for nil:NilClass #165

Closed Fire- closed 4 years ago

Fire- commented 4 years ago

When saving a blank file, an error is thrown. This also causes the Output panel to take focus. It doesn't appear to do more than simply make the language server angry, however.

console.ts:137 [Extension Host] [INFO] Server received textDocument/didSave
                                [DEBUG] {"jsonrpc"=>"2.0", "method"=>"textDocument/didSave", "params"=>{"textDocument"=>{"uri"=>"file:///Users/fire/projects/unicodetest.rb", "version"=>1}}}
console.ts:137 [Extension Host] [INFO] Server received workspace/didChangeWatchedFiles
                                [DEBUG] {"jsonrpc"=>"2.0", "method"=>"workspace/didChangeWatchedFiles", "params"=>{"changes"=>[{"uri"=>"file:///Users/fire/projects/unicodetest.rb", "type"=>2}]}}
console.ts:137 [Extension Host] [INFO] Server received textDocument/formatting
                                [DEBUG] {"jsonrpc"=>"2.0", "id"=>6, "method"=>"textDocument/formatting", "params"=>{"textDocument"=>{"uri"=>"file:///Users/fire/projects/unicodetest.rb"}, "options"=>{"tabSize"=>2, "insertSpaces"=>true}}}
console.ts:137 [Extension Host] [WARN] Error processing request: [NoMethodError] undefined method `length' for nil:NilClass
console.ts:137 [Extension Host] [WARN] /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/message/text_document/formatting.rb:47:in `format'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/message/text_document/formatting.rb:26:in `process'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/host.rb:101:in `receive'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/adapter.rb:44:in `process'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/adapter.rb:17:in `block in opening'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/data_reader.rb:57:in `parse_message_from_buffer'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/data_reader.rb:35:in `block in receive'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/data_reader.rb:30:in `each_char'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/data_reader.rb:30:in `receive'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/lib/solargraph/language_server/transport/adapter.rb:27:in `receiving'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:63:in `tick'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/server/tcpip.rb:76:in `update'
                                       /Users/fire/.rbenv/versions/2.5.1/lib/ruby/2.5.0/observer.rb:197:in `block in notify_observers'
                                       /Users/fire/.rbenv/versions/2.5.1/lib/ruby/2.5.0/observer.rb:196:in `each'
                                       /Users/fire/.rbenv/versions/2.5.1/lib/ruby/2.5.0/observer.rb:196:in `notify_observers'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:121:in `read_input'
                                       /Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:102:in `block in run_input_thread'
                                [INFO] Sending response to textDocument/formatting
                                [DEBUG] {:jsonrpc=>"2.0", :id=>6, :error=>{:code=>-32603, :message=>"[NoMethodError] undefined method `length' for nil:NilClass"}}
                                [DEBUG] Content-Length: 119

                                {"jsonrpc":"2.0","id":6,"error":{"code":-32603,"message":"[NoMethodError] undefined method `length' for nil:NilClass"}}
castwide commented 4 years ago

Confirmed. There's a simple fix. I'll add it to a patch release.

castwide commented 4 years ago

The fix is in the gem's master branch. It'll be included in the next release.