Shopify / Shopify/ruby-lsp

Switch block style refactoring needs improvement

Open
#2,968 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help-wanted pinned
Dominant language
Ruby
Stars
2k
Forks
281
Avg merge
2h 14m
Merged PRs (30d)
6

Description

Description
Ruby LSP Information
VS Code Version

1.95.3

Ruby LSP Extension Version

0.8.16

Ruby LSP Server Version

0.22.1

Ruby LSP Addons
  • Ruby LSP RSpec
  • Ruby LSP Rails
Ruby Version

3.3.6

Ruby Version Manager

none

Installed Extensions
Click to expand
  • bash-ide-vscode (1.43.0)
  • copilot (1.249.0)
  • copilot-chat (0.22.4)
  • gitlab-workflow (5.21.0)
  • gitlens (16.0.5)
  • gitmoji-vscode (1.2.5)
  • gremlins (0.26.0)
  • hexeditor (1.11.1)
  • markdown-all-in-one (3.6.2)
  • markdown-mermaid (1.27.0)
  • ruby-lsp (0.8.16)
  • sass-indented (1.8.31)
  • shellcheck (0.37.1)
  • sorbet-vscode-extension (0.3.37)
  • sort-json (19.1.2)
  • sql-formatter-vsc (4.1.3)
  • svg (1.5.4)
  • text-power-tools (1.50.0)
  • todo-tree (0.0.226)
  • vscode-env (0.1.0)
  • vscode-eslint (3.0.10)
  • vscode-gitweblinks (2.12.0)
  • vscode-gutter-preview (0.32.2)
  • vscode-rdbg (0.2.2)
  • vscode-rubocop (0.7.0)
Ruby LSP Settings
Click to expand
Workspace
{
  "rubyVersionManager": {
    "identifier": "none"
  },
  "formatter": "none"
}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "none"
  },
  "customRubyCommand": "",
  "formatter": "none",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {}
}
Reproduction steps
  1. Start the Ruby LSP using a VSCode
  2. Open a Ruby file
  3. Find a code with a block returning a Hash like this one:
arr.map do |a|
  {
    id: a.id,
    name: a.name
  }
end
  1. We'd expect (or at least I do) the Hash to be preserved as it is and only the do ... end pairs to be turned into { ... } ones. Instead, we get this:
arr.map { |a| {;    id: a.id,;    name: a.name;  } }

LSP reports no errors; thus, I assume the support for this operation needs improvements.

I was let know of the code for this operation to be here: https://github.com/Shopify/ruby-lsp/blob/bbc1ccb4a047040c9c09a32ce5ae19b66aa10157/lib/ruby_lsp/requests/code_action_resolve.rb#L305-L332

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/ruby_lsp/requests/code_action_resolve.rb around lines 305-332, then reproduce the switch-block refactoring with the Hash-returning map example from the issue. Done means converting only the do...end pairs while preserving the Hash formatting and producing the expected Ruby code without the shown semicolon formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.