Vscode: Automatically indent "end" for ruby code

Created on 26 Jan 2016  路  30Comments  路  Source: microsoft/vscode

In VSCode 0.10.6 the "end" in ruby doesn't gets indented after writing it. It should be handled like the brackets in Javascript.

Left: VSCode, Right: Atom (Gif. Reload to see it again)
indentation

feature-request languages-basic on-testplan

Most helpful comment

You can now set editor.autoIndent to true in today's Insider to embrace this feature, thank you all for your patience and help on this! Feedback welcome.

All 30 comments

I'm guessing this will come in the next release?

Any update on this?

+1 for this feature

@rebornix does your ruby extension do this?

Firstly we have snippets in my ruby extension so each time you type def you will get correctly indented end. So it's likely a workaround.

Secondly, I think we have this auto indenting feature but unluckily I found it not working right now. I'll let you guys know when I have more info, then this issue can be treated as external.

I'm trying to support correct indentation as Atom does, and find following interesting difference between VS Code, Atom and TextMate.

TextMate documents increaseIndentPattern and decreaseIndentPattern at https://manual.macromates.com/en/appendix . increaseIndentPattern matches a starting line and any lines after it will have an additional indentation, this functionality is handled correclty in all editors.

But when we come to decreaseIndentPattern, we are running into some problems. The documenation in TextMate site is not that clear, when a line matches decreaseIndentPattern regex, should we unindent the current line or lines after? IMHO, it should be current line as any previous line has additional indentation and it's the right time to unindent. This is also how Atom does it.

However, in our implementation as below

/**
  * Describes indentation rules for a language.
  */
export interface IndentationRule {
    /**
     * If a line matches this pattern, then all the lines after it should be unindendented once (until another rule matches).
     */
    decreaseIndentPattern: RegExp;

Per comments we put in the definition, we are unindenting lines after but not the current line. I'm not sure if it's the root cause, but this makes end never gets correct unindentation.

There is also a long bebate to add decreaseNextIndentPattern to Atom in https://github.com/atom/atom/pull/6808 so I think we need to rethink what's the correct behavior of decreaseIndentPattern. I'll give TextMate a try once I'm back to my Mac to see what's the default behavior, before that I'd like to hear your voices. @alexandrudima , any thoughts?

@rebornix I followed https://manual.macromates.com/en/appendix while implementing it.

I think I got wrong the semantics of decreaseIndentPattern (it should probably decrease the current line too).

The implementation is at https://github.com/Microsoft/vscode/blob/master/src/vs/editor/common/modes/supports/onEnter.ts#L128

To support decreasing the current line indent, the EnterAction must be extended with an additional type of IndentAction, a new one maybe called OutdentInclusive or something and it must be adopted everywhere where EnterAction is interpreted.

Are there any updates on this? It's the one crutch for developing ruby apps using VS Code

Are there any updates on this? It's the one crutch for developing ruby apps using VS Code

Lua as well. :(

For the julia extension we are also waiting for this, would be great if this could be prioritized.

bump.

+1 this is really annoying.

+1 for visibility since this isn't getting any love.

+1 its time to give some love to this bug

My investigation up there https://github.com/Microsoft/vscode/issues/2272#issuecomment-225515268 is kind of misleading. The existing code and logic is correct and necessary. The only thing we didn't take into consideration is modifying indentation while users type.

Right now, our existing logic about decreaseIndentPattern is checking whether we should decease the following line if you press enter. This makes sense as after you press enter, the content after your content becomes a new line, which makes it as following line. But to enable this feature, we need to declare the correct decreaseIndentPattern for ruby code, I've filed a feature request here https://github.com/Microsoft/vscode/pull/16401. Before that's merged, you can play with my ruby extension but I don't think it will take long.

Another part is actually modifying indentation while users type. Since we are at the end of this iteration and adding this feature to master might affect TypeScript, Ruby and any other potential extension that leverages decreaseIndentPattern https://github.com/search?utf8=%E2%9C%93&q=decreaseIndentPattern+vscode&type=Code&ref=searchresults. We don't rush this time but we can have that in recent updates of Insider build.

Stay tuned.

Any updates on this? I'd like to use Visual Studio Code for Ruby projects but this behavior is frustrating coming from other editors.

Yeah, I just tried to start using VSCode for Ruby development, and I have to say, this is kind of a deal breaker. This makes just writing basic Ruby code pretty frustrating. I'm sure it will get fixed at some point. I'll revisit then.

+1

+1

This seems to work for me now after inserting a newline after the end, but it would be good if this happens right after end is typed:

Current behavior:
vscode_end

Ideal behavior: In the gif in the issue description: https://github.com/Microsoft/vscode/issues/2272#issue-128769995

This is still better than what it was before.

Yes, let me second that request that things should unindent not just on enter, but when then word end has been typed. We really, really would like to see that for the julia extension as well.

I also think it would be great if this could move to a milestone fairly soon. It is one of the few core areas where VS Code currently lacks behind something like Atom.

I started using VSCode 2 days ago, moving from Sublime, and I love it. This, however, is one of the few things that annoys me at the moment...

Agreed. I love VS Code thus far, but I'm switching back to Atom for Ruby development just because of this.

VSCode is by far my favorite editor, except for this. Would absolutely love to see this implemented.

VSCode is awesome, I've gotten around this by Shift+TABing following end but VSCode NEEDS to update this.

Not just indentation, but also highlighting do/end brackets for languages like Ruby or Elixir

It works fine with braces { } but I'd like to see it for do end as well.

To add my voice, as a newcomer I'm extremely happy with VS Code but this just seems odd. If this works for curly-brace languages, I can't see the logic in not implementing this same behavior for languages which terminate blocks with end.

You can now set editor.autoIndent to true in today's Insider to embrace this feature, thank you all for your patience and help on this! Feedback welcome.

This issue was reintroduced in the latest update

Search for editor.autoIndent in settings and change it to true

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrkiley picture mrkiley  路  3Comments

trstringer picture trstringer  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

shanalikhan picture shanalikhan  路  3Comments

villiv picture villiv  路  3Comments