castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 158 forks source link

The version 0.47 breaks neovim lsp client #600

Closed datanoise closed 2 years ago

datanoise commented 2 years ago

The version 0.47 breaks neovim lsp client when you type colon between brackets:

[|]

type :

[:]

results:

Error executing luv callback:
/usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:262: /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:76: invalid heade
r line "content or terminator or tSTRING_DBEG or tSTRING_DVAR\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/parser/rubyvm/class_methods.rb
:15:in `rescue in parse_with_comments'\
/Users/kent/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/parser/rubyvm/class_methods.rb
:10:in `parse_with_comments'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/source.rb:45:in `initialize'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/source.rb:129:in `new'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/source.rb:129:in `finish_synch
ronize'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/language_server/host/sources.r
b:39:in `block in tick'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/language_server/host/sources.r
b:38:in `synchronize'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/language_server/host/sources.r
b:38:in `tick'\
~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/solargraph-0.47.0/lib/solargraph/language_server/host/sources.r
b:29:in `block in start'\
Content-Length: 928826"
stack traceback:
        [C]: in function 'parse_chunk'
        /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:262: in function </usr/local/share/nvim/runtime/lua/vim/lsp/rpc.
lua:248>
datanoise commented 2 years ago

After a bit of digging it seems that it is caused by leftover printouts in the code:

lib/solargraph/source.rb line 48:

    def initialize code, filename = nil, version = 0
      @code = normalize(code)
      @repaired = code
      @filename = filename
      @version = version
      @domains = []
      begin
        @node, @comments = Solargraph::Parser.parse_with_comments(@code, filename)
        @parsed = true
      rescue Parser::SyntaxError, EncodingError => e
->        puts "[#{e.class}] #{e.message}"
->        puts e.backtrace
        @node = nil
        @comments = {}
        @parsed = false
      ensure
        @code.freeze
      end
    end

Interestingly, I don't see these two puts are committed in the repository but they are in the published gem file.

castwide commented 2 years ago

Sorry about that. Those should output to a proper logger instead. I'll fix it in a patch ASAP.

castwide commented 2 years ago

I'm not sure how that code wound up in the release (it's not even in my local repo), but it's removed in v0.47.1.