Vscode-ruby: Language server doesn't like a particular line of code

Created on 7 Jan 2021  ·  23Comments  ·  Source: rubyide/vscode-ruby

Your environment

  • vscode-ruby version: 0.28.0
  • Ruby version: 2.7.2
  • Ruby version manager (if any): asdf
  • VS Code version: 1.52.1
  • Operating System: macOS 11.1
  • Using language server? (eg useLanguageServer is true in your configuration?) yes

Expected behavior

  • Letting me view my Terminal while I work

Actual behavior

  • The actual extension functionality seems to work fine, but after I view a certain file, every time I click anywhere in Ruby file, my Terminal is switched to Output, which is incredibly disruptive (is there a way to switch that off perhaps?). Under Output, I see something like the following, which, according to my Google searches, is just generic extension errors:
Initializing Ruby language server...
TypeError: Cannot read property 'apply' of undefined
    at t.<computed> (/Users/anamba/.vscode/extensions/rebornix.ruby-0.28.0/dist/server/index.js:16:235186)
    at <anonymous>:wasm-function[20]:0x908
    at <anonymous>:wasm-function[19]:0x4a8
    at <anonymous>:wasm-function[80]:0x15c68
    at <anonymous>:wasm-function[129]:0x25fcc
    at ts_parser_parse_wasm (<anonymous>:wasm-function[248]:0x2d59c)
    at he.parse (/Users/anamba/.vscode/extensions/rebornix.ruby-0.28.0/dist/server/index.js:16:261383)
    at Object.createTree (/Users/anamba/.vscode/extensions/rebornix.ruby-0.28.0/dist/server/index.js:16:176062)
    at e.project (/Users/anamba/.vscode/extensions/rebornix.ruby-0.28.0/dist/server/index.js:16:176538)
    at e._next (/Users/anamba/.vscode/extensions/rebornix.ruby-0.28.0/dist/server/index.js:16:117207)
[Error - 11:11:12 AM] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 11:11:12 AM] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 11:11:15 AM] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603

I ultimately narrowed it down to these two lines (part of a merge method):

    photos.each { |obj| target.photos << obj }
    notes.each { |obj| target.notes << obj }

If I reload the window, all is well until I switch to that particular tab again, and then after that, any time I click anywhere in any ruby file, I get more errors under Output.

Rewriting those lines to this helped:

    photos.each { |obj| obj.update(entity: target) }
    notes.each { |obj| obj.update(entity: target) }

🤷‍♂️

bug

Most helpful comment

I also get a lot of errors like that since the last update. Pasting some of them here if it helps in the debugging:

[Error - 09:37:57] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:58] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:58] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:59] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:00] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:00] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:07] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:07] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:13] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:13] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:17] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:17] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:19] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:41] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:50:20] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:50:20] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 

All 23 comments

I did a search for '<<' in my codebase and those files also trigger this issue. I could rewrite them all, but...

Hmm that stack trace looks like a bug in the tree sitter Ruby grammar.

The Output pane is VSCode behavior. I’ll investigate if there’s a way to squash that somehow.

I’ll look at this tomorrow. Sorry for the disruption!

No worries, I figured out how to revert to the previous version (Extensions: Install Specific Version of Extension...).

@anamba thanks for reporting this. I had the same issue. I had to use the previous version of vscode-ruby as well. I'm on Ubuntu.

I also get a lot of errors like that since the last update. Pasting some of them here if it helps in the debugging:

[Error - 09:37:57] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:58] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:58] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:37:59] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:00] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:00] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:04] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:07] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:07] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:13] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:13] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:17] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:17] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:18] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:19] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:38:26] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:41] Request textDocument/documentHighlight failed.
  Message: Request textDocument/documentHighlight failed with message: Cannot read property 'rootNode' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 
[Error - 09:38:43] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:50:20] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'documentSymbols' of undefined
  Code: -32603 
[Error - 09:50:20] Request textDocument/foldingRange failed.
  Message: Request textDocument/foldingRange failed with message: Cannot read property 'foldingRanges' of undefined
  Code: -32603 

Same thing happens on mine, but on a different line

Bundler::Dsl::DSLError: 
[!] There was an error parsing `Gemfile`: No such file or directory @ rb_sysopen - .ruby-version. Bundler cannot continue.

 #  from /Users/.../Gemfile:4
 #  -------------------------------------------
 #  
 >  ruby File.read('.ruby-version').chomp

Works fine if I use ruby '2.6.5'

Same problem here. I worked around it downgrading to 0.27.0, as other people mentioned in the previous comments.

I had the same issue

Initializing Ruby language server...
TypeError: Cannot read property 'apply' of undefined

@qortex thanks for the output. All of those errors point to an inability to parse the source file. Are you also having issues with << syntax?

The downgrade works because I upgraded the Ruby grammar in this version. If necessary I'll downgrade it again and cut a new release for folks. Either way I'll get something out today so people can still use some of the other stuff in the new version.

Thanks everyone for the report. It does appear to be something to do with << and the tree-sitter-ruby grammar. Still digging to see what that may be. This also occurs with heredocs and anything else that uses that syntax.

@vassyz it is not related to Ruby version. The language server does not ever load Ruby to perform its analysis. All analysis is static or performed via shelling out to the appropriate command (eg RuboCop).

@wingrunr21 Might be just a coincidence, but I haven't changed the Gemfile in ages and after updating to the latest version the Terminal kept switching to the Output panel showing this error.

Thanks everyone for the report. It does appear to be something to do with << and the tree-sitter-ruby grammar. Still digging to see what that may be. This also occurs with heredocs and anything else that uses that syntax.

Makes sense, I have quite a bunch of heredocs snippets in my files.

I temporarily fixed this by downgrading to 0.27. Seems like an issue with the newest release

0.28.1 was just released with tree-sitter downgraded to the same version as in 0.27.0. I wasn't able to trace the issue but it is present in 0.16.x as well. I'll be digging into that as I need some of the features in newer tree sitter versions.

I updated to 0.28.1. Problem stopped for a while.

@vassyz it is not related to Ruby version. The language server does not ever load Ruby to perform its analysis. All analysis is static or performed via shelling out to the appropriate command (eg RuboCop).

@wingrunr21 I can confirm that this issue only happens on 0.28.0 and also 0.28.1. It does come from the language server, but it's not being triggered by Ruby 0.27.0.

Updating to 0.28.1 seems to have fixed the problem for me. Thanks!

@vassyz are you referring to your issue with your Gemfile or this issue? I created a local test file for this issue and in my testing the issue with << syntax seemed to be resolved.

@wingrunr21 The Gemfile, should I create another issue for it? Sorry, I commented here because I was encountering the same behaviour as the editor kept switching to the Output panel.

@vassyz I believe your issue is different. It's definitely a Ruby error. Thinking about it some more, it may have been this commit: c1b87d39d0349458e63baec7c5040c1996969e7c

Bundler will recursively check parent directories for a Gemfile. Your reference to the .ruby-version file is not relative to the Gemfile itself but to the working directory. I did a quick recreation here:

image

This issue isn't specific to the extension as it would also not work in your shell

@anamba if you get a chance, can you see if 0.28.1 resolves your issue? thanks!

@anamba if you get a chance, can you see if 0.28.1 resolves your issue? thanks!

0.28.1 is working for me. Thank you!

Great! Have a great weekend!

Was this page helpful?
0 / 5 - 0 ratings