Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically indent "end" for ruby code #2272

Closed
philipgiuliani opened this issue Jan 26, 2016 · 30 comments
Closed

Automatically indent "end" for ruby code #2272

philipgiuliani opened this issue Jan 26, 2016 · 30 comments
Assignees
Labels
feature-request Request for new features or functionality languages-basic Basic language support issues on-testplan
Milestone

Comments

@philipgiuliani
Copy link

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

@aeschli aeschli added the languages-basic Basic language support issues label Jan 26, 2016
@markediez
Copy link

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

@alexdima alexdima added the feature-request Request for new features or functionality label Feb 22, 2016
@markediez
Copy link

Any update on this?

@kyleect
Copy link

kyleect commented Jun 9, 2016

+1 for this feature

@Tyriar
Copy link
Member

Tyriar commented Jun 10, 2016

@rebornix does your ruby extension do this?

@rebornix
Copy link
Member

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.

@rebornix
Copy link
Member

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 atom/atom#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?

@alexdima
Copy link
Member

alexdima commented Jul 5, 2016

@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.

@coderberry
Copy link

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

@alexdima alexdima assigned alexdima and unassigned alexdima Oct 26, 2016
@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Oct 26, 2016
@itsMapleLeaf
Copy link

itsMapleLeaf commented Nov 20, 2016

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

Lua as well. :(

@davidanthoff
Copy link
Contributor

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

@surajreddy
Copy link

bump.

@jaredready
Copy link

+1 this is really annoying.

@nitsujri
Copy link

nitsujri commented Dec 1, 2016

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

@BrAmSe
Copy link

BrAmSe commented Dec 1, 2016

+1 its time to give some love to this bug

@rebornix
Copy link
Member

rebornix commented Dec 2, 2016

My investigation up there #2272 (comment) 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 #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.

@rebornix rebornix removed the bug Issue identified by VS Code Team member as probable bug label Jan 13, 2017
@kpollich
Copy link

kpollich commented Mar 7, 2017

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

@alexdima alexdima removed their assignment Mar 8, 2017
@elliotlarson
Copy link

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.

@andrewmartin
Copy link

+1

1 similar comment
@fnandes
Copy link

fnandes commented Mar 26, 2017

+1

@surajreddy
Copy link

surajreddy commented Mar 27, 2017

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: #2272 (comment)

This is still better than what it was before.

@davidanthoff
Copy link
Contributor

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.

@StanBright
Copy link

StanBright commented Apr 26, 2017

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...

@zebogen
Copy link

zebogen commented May 4, 2017

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

@coleby210
Copy link

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

@rebornix rebornix self-assigned this May 12, 2017
@emitchel
Copy link

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

@seivan
Copy link
Contributor

seivan commented Jun 14, 2017

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.

@andyferris
Copy link

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.

@rebornix rebornix modified the milestones: June 2017, Backlog Jun 19, 2017
@rebornix
Copy link
Member

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.

@mhornbacher
Copy link

This issue was reintroduced in the latest update

@blackhaj
Copy link

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

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality languages-basic Basic language support issues on-testplan
Projects
None yet
Development

No branches or pull requests