Skip to content

Avoid indenting after endless method definition#4041

Open
vinistock wants to merge 1 commit intomainfrom
03-31-avoid_indenting_after_endless_method_definition
Open

Avoid indenting after endless method definition#4041
vinistock wants to merge 1 commit intomainfrom
03-31-avoid_indenting_after_endless_method_definition

Conversation

@vinistock
Copy link
Copy Markdown
Member

Motivation

Closes #3997

The automatic indentation rules that are bundled in VS Code don't account for endless method definitions and end up advancing the indentation when you break the line (which isn't what you'd expect).

This PR adds our own indentation rules to validate the fix first. Once we know this works correctly, we can contribute the improvement to VS Code and get rid of this.

Implementation

The rules become more complicated because we now need a negative lookahead that can catch and endless method definition without confusing it with a setter name. Using a setter name with an endless method definition is actually a syntax error, but we don't want to indent anyway.

Example:

# No indent
def foo = 42
def self.foo = 42
def Foo.foo = 42
def foo=(foo) = 42 # invalid, but we don't want to indent
def self.foo=(foo) = 42 # invalid, but we don't want to indent
def Foo.foo=(foo) = 42 # invalid, but we don't want to indent

# Indent
def foo
def self.foo
def Foo.foo
def foo=(foo)
def self.foo=(foo)
def Foo.foo=(foo)

@vinistock vinistock self-assigned this Mar 31, 2026
@vinistock vinistock requested a review from a team as a code owner March 31, 2026 14:44
@vinistock vinistock added bugfix This PR will fix an existing bug vscode This pull request should be included in the VS Code extension's release notes labels Mar 31, 2026
@vinistock vinistock requested review from alexcrocha and st0012 March 31, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug vscode This pull request should be included in the VS Code extension's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indent after <ENTER> is incorrect after endless method definition

2 participants