macOS Sierra 10.12.1
VSCode version 1.7.2
Ruby plugin version 0.10.4
User settings:
{
"workbench.editor.enablePreview": true,
"explorer.openEditors.visible": 0,
"editor.tabSize": 2,
"editor.detectIndentation": false
}
end should auto un-indent properly after a def, module, class, etc.
end doesn't auto un-indent properly after a def, module, class, etc.
open an rb file or create a new one and type:
def foo and push enter, then type end
Hi @pharmmd-rich, this is a known issue unfortunately. We're aware of it and there isn't an easy workaround unfortunately.
I don't know if it helps at all, but the systemverilog extension has automatic end insertion/unindentation. I'm not familiar with how they implemented it, and I know that it is a much simpler language, but I thought that I would drop that here.
.
The system verilog extension can be found here.
The recent 1.9 release mentioned improved support for indentation for language extensions: https://code.visualstudio.com/updates/v1_9#_indentation-rules-improvements
Indentation rules improvements
We polished our implementation of Indentation Rules, which Language extensions can leverage to determine the correct indentation level for a specific line. The indentation adjustments are usually triggered after users finish writing a line and press Enter.
In addition, we implemented an experimental command Reindent Lines and you can use it to adjust the indentation of the whole file if the indentation rules are properly set.
Could these changes help this extension such that manually un-indenting every end isn't needed?
It does help to an extent. Now, in Ruby, if you type 'end' and then push enter, end will properly de-indent itself. I haven't tried the extension mentioned above, but it'd be nice if the Ruby extension would implement that functionality.
The indentation rules enhancement was implemented by me as well :) Right now as Code only supports indentation adjustments when you press enter, you can see the indentation adjusts properly, with or without this extension.
I'll keep working on the indentation improvement in Code and personally I'd like to bring in auto indent, in which case you don't need to rely on pressing Enter. As this extension already has a good indentation rules setting, we don't need to change anything here.
@rebornix hey mate, thanks for the great work!
Any ideas when the extended functionality regarding auto-indent could see some light :)?
@rebornix thanks for your work on the extension so far, I use it every day and it's a great help :)
Will the changes to auto-indentation in the latest VS Code release help to resolve this issue? Looks promising...
Yes, that feature is particularly for this case. If you take a look at the gif in the release note of 1.14, you'll see that I use Ruby code as an example :)
Just set editor.autoIndent to true. Hope you guys like it
Oh, didn't realise it was off by default, haha. All working now. Great update, thanks @rebornix !
Awesome, @rebornix! I saw the indentationRules part of the release notes but I'm not entirely sure if I need to enable anything or if this extension needs these rules to work with pasting code? I tried but it doesn't seem to work right now.
My guess is we need to add the indentationRules for files like .rb and .html.erb etc?
@aried3r it works out of the box. You just have to enable the setting.
@pharmmd-rich, I did enable it, sorry if that wasn't clear. Does indenting on pasting work for you, though? That's what I'm actually asking.
Pasting has been working great for me, way better than previously. Are you having an issue?
Yeah, pasting ruby code still does not auto-indent, usually retaining all the whitespace of the first line in addition to the existing whitespace of the line. The remaining pasted lines retain the indentation of the source.
So the current workflow looks like this:
Ideally I'd love to skip the last two, which I though was coming with VSCode 1.14
Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.
Most helpful comment
The indentation rules enhancement was implemented by me as well :) Right now as Code only supports indentation adjustments when you press enter, you can see the indentation adjusts properly, with or without this extension.
I'll keep working on the indentation improvement in Code and personally I'd like to bring in auto indent, in which case you don't need to rely on pressing Enter. As this extension already has a good indentation rules setting, we don't need to change anything here.