Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Language server doesn't like a particular line of code #693

Closed
anamba opened this issue Jan 7, 2021 · 25 comments
Closed

Language server doesn't like a particular line of code #693

anamba opened this issue Jan 7, 2021 · 25 comments
Assignees
Labels
bug Bug reports

Comments

@anamba
Copy link

anamba commented Jan 7, 2021

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) }

🤷‍♂️

@anamba
Copy link
Author

anamba commented Jan 7, 2021

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

@wingrunr21 wingrunr21 self-assigned this Jan 7, 2021
@wingrunr21 wingrunr21 added the bug Bug reports label Jan 7, 2021
@wingrunr21
Copy link
Collaborator

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!

@anamba
Copy link
Author

anamba commented Jan 7, 2021

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

@durrellchamorro
Copy link

@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.

@qortex
Copy link

qortex commented Jan 7, 2021

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 

@zarembas
Copy link

zarembas commented Jan 7, 2021

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'

@mdesantis
Copy link

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

@AankTia
Copy link

AankTia commented Jan 7, 2021

I had the same issue

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

@wingrunr21
Copy link
Collaborator

@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.

@wingrunr21
Copy link
Collaborator

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).

@zarembas
Copy link

zarembas commented Jan 7, 2021

@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.

@qortex
Copy link

qortex commented Jan 7, 2021

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.

@arushs
Copy link

arushs commented Jan 7, 2021

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

@wingrunr21
Copy link
Collaborator

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.

@IbukiMoriya
Copy link

IbukiMoriya commented Jan 8, 2021

I updated to 0.28.1. Problem stopped for a while.

@zarembas
Copy link

zarembas commented Jan 8, 2021

@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.

@mmirus
Copy link

mmirus commented Jan 8, 2021

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

@wingrunr21
Copy link
Collaborator

@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.

@zarembas
Copy link

zarembas commented Jan 8, 2021

@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.

@wingrunr21
Copy link
Collaborator

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

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

@wingrunr21
Copy link
Collaborator

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

@anamba
Copy link
Author

anamba commented Jan 9, 2021

@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!

@wingrunr21
Copy link
Collaborator

Great! Have a great weekend!

@addbrick
Copy link

Just a note, I started to run into this issue with the same error messages in v0.28.1. It appeared to repro on an empty ruby file, so not sure if I just got into a really bad state. Downgrading to v0.27 fixed the issue.

@palexvs
Copy link

palexvs commented Feb 14, 2023

Same here - v0.28.1 fails on ruby File.read(".ruby-version").strip line

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug reports
Projects
None yet
Development

No branches or pull requests