Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.55k stars 146 forks source link

Ruby Syntax Highlighting "class" where not actually a class i.e. "classification" #2269

Closed jeronimoamazon closed 3 months ago

jeronimoamazon commented 3 months ago

Description

When using the latest version of VSCode and the RubyLSP, words that contain class are highlighted like an actual class.

Reproduction steps

Ruby LSP extension: v0.7.8 VSCode version:

  1. Open VSCode
  2. Install the Ruby extension pack containing sorbet and the LSP
  3. Open/create a new Ruby file
  4. Paste the following code
  5. See that words that contain class are highlighted weird
  6. If I disable the LSP extension, the issue disappears (because nothing is highlighting the syntax).

Code snippet or error message

# frozen_string_literal: true

# A test class
class MyClass
  class_attribute :banana

  def my_function
    classification = 1

    classification + 1
  end
end

Screenshot 2024-07-08 at 1 27 09 PM

st0012 commented 3 months ago

Can you screenshot the extension control panel by clicking the { } mark at the bottom, next to Ruby? It should look like:

Screenshot 2024-07-08 at 21 39 22

And it looks like there are 2 causes for the issue:

  1. The server didn't start correctly for your project, which should be confirmed by your extension control panel. If you go to the OUTPUT tab and then select Ruby LSP, it may show the reasons behind it.
  2. Since the server isn't available, the extension would then fallback to the grammar file it has. And I think a recent change in #2242 may be linked to this.

@vinistock can you take a look at 2)? I think we may need to replace the first \\s* with \\s+?

vinistock commented 3 months ago

Yeah, https://github.com/Shopify/ruby-lsp/pull/2270 should fix it.

In addition to the grammar bug, it looks like semantic highlighting is not running. It is turned off by default in VS Code, so you might want to turn it on and review our recommended settings to get the most out of the LSP.

jeronimoamazon commented 3 months ago

Here are my ruby settings:

    "[ruby]": {
        "editor.defaultFormatter": "Shopify.ruby-lsp",
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "editor.tabSize": 2,
        "editor.insertSpaces": true,
        "files.trimTrailingWhitespace": true,
        "files.insertFinalNewline": true,
        "files.trimFinalNewlines": true,
        "editor.rulers": [
            120
        ],
        "editor.semanticHighlighting.enabled": true
    },

And here is the Ruby LSP output tab when reloading the VSCode window:

2024-07-08 11:46:31.160 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 11:46:38.654 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 11:46:40.575 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 11:46:42.346 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 11:46:44.654 [info] (***) Discovered version manager none
2024-07-08 11:46:44.654 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 11:57:12.458 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 11:57:13.606 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 11:57:14.766 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 11:57:15.952 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 11:57:17.074 [info] (***) Discovered version manager none
2024-07-08 11:57:17.074 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 11:57:18.374 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 11:57:19.500 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 11:57:20.570 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 11:57:21.644 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 11:57:22.727 [info] (***) Discovered version manager none
2024-07-08 11:57:22.727 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 11:57:24.953 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 11:57:26.139 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 11:57:27.245 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 11:57:28.311 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 11:57:29.363 [info] (***) Discovered version manager none
2024-07-08 11:57:29.363 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 11:57:37.638 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 11:57:38.871 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 11:57:39.954 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 11:57:40.976 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 11:57:42.007 [info] (***) Discovered version manager none
2024-07-08 11:57:42.007 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:17:03.330 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:17:04.429 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:17:05.440 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:17:06.468 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:17:07.490 [info] (***) Discovered version manager none
2024-07-08 13:17:07.490 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:23:12.551 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:23:13.705 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:23:14.743 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:23:15.754 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:23:16.778 [info] (***) Discovered version manager none
2024-07-08 13:23:16.778 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:24:46.406 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:24:47.482 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:24:48.560 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:24:49.590 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:24:50.585 [info] (***) Discovered version manager none
2024-07-08 13:24:50.585 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:24:56.047 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:24:57.172 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:24:58.242 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:24:59.441 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:25:00.530 [info] (***) Discovered version manager none
2024-07-08 13:25:00.530 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:25:28.802 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:25:30.031 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:25:31.091 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:25:32.807 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:25:33.924 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:25:35.054 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:25:36.159 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:25:37.197 [info] (***) Discovered version manager none
2024-07-08 13:25:37.197 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:36:21.061 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:36:22.163 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:36:23.293 [info] (***) Checking if rvm is available on the path with command: /bin/zsh -i -c 'rvm --version'
2024-07-08 13:36:24.323 [info] (***) Checking if asdf is available on the path with command: /bin/zsh -i -c 'asdf --version'
2024-07-08 13:36:25.391 [info] (***) Discovered version manager none
2024-07-08 13:36:25.391 [info] (***) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:48:06.491 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:48:07.658 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:48:08.660 [info] (***) Discovered version manager rbenv
2024-07-08 13:48:08.660 [info] (***) Running command: `rbenv exec ruby -W0 -rjson -e 'STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
2024-07-08 13:48:54.690 [info] (***) Checking if chruby is available on the path with command: /bin/zsh -i -c 'chruby --version'
2024-07-08 13:48:55.929 [info] (***) Checking if rbenv is available on the path with command: /bin/zsh -i -c 'rbenv --version'
2024-07-08 13:48:56.885 [info] (***) Discovered version manager rbenv
2024-07-08 13:48:56.885 [info] (***) Running command: `rbenv exec ruby -W0 -rjson -e 'STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)'` in /Users/xxx/*** using shell: /bin/zsh
jeronimoamazon commented 3 months ago

Thanks all for the quick response.