Skip to content

Format on save not working in VS Code #3279

@graygilmore

Description

@graygilmore

Description

Ruby LSP Information

VS Code Version

1.96.2

Ruby LSP Extension Version

0.9.7

Ruby LSP Server Version

0.23.11

Ruby LSP Add-ons

  • Ruby LSP Rails
  • Tapioca
  • RuboCop

Ruby Version

3.4.1

Ruby Version Manager

shadowenv

Installed Extensions

Click to expand
  • EditorConfig (0.17.1)
  • explorer (1.16.0)
  • gitlens (16.3.2)
  • polaris-for-vscode (0.9.8)
  • prettier-vscode (11.0.0)
  • remote-ssh (0.113.1)
  • remote-ssh-edit (0.87.0)
  • ruby-extensions-pack (0.1.13)
  • ruby-lsp (0.9.7)
  • sorbet-vscode-extension (0.3.40)
  • theme-check-vscode (3.6.0)
  • vscode-bazel (0.11.0)
  • vscode-eslint (3.0.10)
  • vscode-graphql (0.13.0)
  • vscode-graphql-syntax (1.3.8)
  • vscode-rdbg (0.2.2)
  • vscode-stylelint (1.4.0)
  • vscode-theme-onelight (2.3.0)

Ruby LSP Settings

Click to expand
Workspace
{
  "testTimeout": 300,
  "featureFlags": {
    "tapiocaAddon": true
  }
}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": false,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 300,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {
    "tapiocaAddon": true
  },
  "sigOpacityLevel": "1"
}

Reproduction steps

  1. Open any Ruby file
  2. Write code that should trigger a RuboCop Layout error
  3. Hit Save

Expected behavior

The file should be formatted based on the RuboCop rules

Actual behavior

No auto formatting happens.

Example

def foo; end

  def bar; end

should become:

def foo; end

def bar; end

Ruby LSP Output

I see a stack trace when Ruby LSP is booting up:

2025-03-07 11:12:34.352 [info] (shopify) [RuboCop] Initialized RuboCop LSP addon 1.71.2.

2025-03-07 11:12:34.392 [info] (shopify) Error loading addons:

<REPO>/vendor/bundle/ruby/3.4.0/gems/rubocop-1.71.2/lib/rubocop/cop/registry.rb:68:in 'RuboCop::Cop::Registry#dismiss': Cop RuboCop::Cop::Cop could not be dismissed (RuntimeError)
	from <REPO>/vendor/bundle/ruby/3.4.0/gems/rubocop-1.71.2/lib/rubocop/cop/base.rb:82:in 'RuboCop::Cop::Base.exclude_from_registry'
	from <REPO>/vendor/bundle/ruby/3.4.0/gems/rubocop-1.71.2/lib/rubocop/cop/cop.rb:14:in '<class:Cop>'

From the command line

If I run bundle exec rubocop -a <my-file> then it does successfully update the file to the correct format so I believe this to be a problem with the extension itself rather than RuboCop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions