Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jeronimoamazon opened this issue Jul 8, 2024 · 4 comments · Fixed by #2270
Closed
Assignees
Labels
bug Something isn't working

Comments

@jeronimoamazon
Copy link

jeronimoamazon commented Jul 8, 2024

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.91.0 (Universal)
    Commit: ea1445cc7016315d0f5728f8e8b12a45dc0a7286
    Date: 2024-07-01T18:54:18.541Z (1 wk ago)
    Electron: 29.4.0
    ElectronBuildId: 9728852
    Chromium: 122.0.6261.156
    Node.js: 20.9.0
    V8: 12.2.281.27-electron.0
    OS: Darwin arm64 23.5.0
  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

@jeronimoamazon jeronimoamazon added the bug Something isn't working label Jul 8, 2024
@st0012
Copy link
Member

st0012 commented Jul 8, 2024

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 Simplify class and module grammar for more consistency #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
Copy link
Member

Yeah, #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
Copy link
Author

jeronimoamazon commented Jul 8, 2024

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
Copy link
Author

Thanks all for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants