Skip to content

Ruby LSP running but formatting not working #1753

@hawm

Description

@hawm

Operating System

Debian GNU/Linux 11 (bullseye), Docker Image (debian:bullseye-slim)

Ruby version

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

Project has a bundle

  • Has bundle

Ruby version manager being used

no manager

Description

I am running VSCode and vscode-ruby-lsp in devcontainer, the Ruby LSP starts normally but formatting not working.

I already tweaked the "rubyLsp.formatter" in settiings.json, with values auto, rubocop or syntax_tree but was not lucky.

Project's Gemfile

# frozen_string_literal: true

source "https://rubygems.org"

group :development do
  gem "rubocop"
  gem "rubocop-discourse"
  gem "syntax_tree"
  gem "syntax_tree-disable_ternary"
end

.vscode/settings.json

{
  "rubyLsp.rubyVersionManager": "none",
  "rubyLsp.formatter": "rubocop",
  "rubyLsp.yjit": true,
  "rubyLsp.enableExperimentalFeatures": false,
  "rubyLsp.enabledFeatures": {
    "codeActions": false,
    "diagnostics": false,
    "documentHighlights": false,
    "documentLink": false,
    "documentSymbols": false,
    "foldingRanges": false,
    "formatting": true,
    "hover": false,
    "inlayHint": false,
    "onTypeFormatting": false,
    "selectionRanges": false,
    "semanticHighlighting": false,
    "completion": false,
    "codeLens": false,
    "definition": false
  },

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

  "ruby lsp.trace.server": "verbose"
}

Ruby file content ensure has formatting issue

# test.rb
def say_hello
  puts "Hello" # --> formatting: fixes the indentation on save
  end

Ruby LSP verbose output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp-wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions