Shopify / ruby-lsp

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

Modules::include wrong indentation #1734

Closed akirataguchi115 closed 6 months ago

akirataguchi115 commented 8 months ago

Ruby version

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

Code snippet

class Brewery < ApplicationRecord
  include RatingAverage
  has_many :beers, dependent: :destroy
end

Description

Paste the code snippet. Remove line 2. Start writing the same line starting with "include" with indentation already input there like in the snippet.

Expected output

The indentation holds and the include gets typed correctly there.

Actual output

Ruby LSP indents the "include" backwards as if the include shouldn't be indented.

According to the Official Ruby API include should be indented: https://docs.ruby-lang.org/en/master/Module.html

vinistock commented 8 months ago

Thank you for the bug report! This is indeed annoying, but it's not coming from the server. We don't handle this in onTypeFormatting, this is coming from the grammar file in the VS Code extension.

I'll transfer the issue to that repo.

davidcelis commented 7 months ago

Not sure if its the same issue or only related, but I've found some other auto indentation issues when using Shopify's Ruby LSP extension. In addition to the original problem around include being auto-indented as soon as you type in (probably because it tries to detect it as the pattern matching keyword), I've also noticed inconsistent behavior with do...end blocks. For example, in RSpec tests, different things happen with different kinds of blocks:

describe "an rspec test group" do
# does not properly increase indentation after entering the newline

let(:variable) do
  # properly increases indentation after entering the newline
vinistock commented 7 months ago

I can't really reproduce the describe block indentation issue. If I do it, I get the right indentation. Do you have any other Ruby related extensions? Also, are you using our recommended configurations?

davidcelis commented 7 months ago

Weird… I can't reproduce it anymore either 🤔 Totally willing to chalk it up to some fluke or strange interaction, sorry for the misdirection 😅

akirataguchi115 commented 7 months ago

I'll try to reproduce this in the next 48 hours.

akirataguchi115 commented 7 months ago

I am able to reproduce the bug. Editing the Code snippet to be more readable as the issue template messed it up.

I can confirm that the wrong auto indent already happens, as stated above, when typing "in".

I can also reproduce the following bug mentioned above:

describe "an rspec test group" do
# does not properly increase indentation after entering the newline

let(:variable) do
  # properly increases indentation after entering the newline

The bug still happens after setting the recommended configurations and disabling ruby-rubocop extension.

andyw8 commented 7 months ago

Are you using Copilot?

I can reproduce if that's enabled:

akirataguchi115 commented 7 months ago

Great to know that you can reproduce it. I'm not using Copilot though.

vinistock commented 7 months ago

We created a fix for the in and the when problem. For the indentation after the automatic on type formatting end completions, I believe that the language configuration decrease rules are getting triggered when we insert it, which messes up the indentation.

The way to fix it is to add the correct indentation from the on type formatting request in the server.

zacheryph commented 4 months ago

For anyone else that finds this Issue and wonders "whats going on?" since there wasn't a link. 🤣 LSP will correct indentation on format, but... its still rather annoying. @vinistock opened a PR for the underlying issue in VS Code itself. (many thanks btw. I swear this worked at some point in the past ... many months, but the rules in vs code say its been this way since 2021 🤷)

https://github.com/microsoft/vscode/pull/198349

davidcelis commented 4 months ago

Will that fix the issue in VSCode? It seems like that's against the now-deprecated default Ruby extension, and everybody now is being told to install Shopify's Ruby LSP extension

andyw8 commented 4 months ago

The change above corresponds to the built-in Ruby Language Basics extension:

Screenshot 2024-01-17 at 2 20 40 PM

The extension that was deprecated was https://github.com/rubyide/vscode-ruby