Reputation: 415
I wanted to try out visual studio code for writing ruby/rails and came across this issue that when I write 'do' in the editor and then hit enter then 'end' is not automatically added to the next line.
Writing 'def' + enter works fine. 'begin' + enter works fine too, but not 'do' + enter.
I haven't found any extension that would make it work yet and google has not been much help either. Maybe there's a way to define the snipper myself?
Thanks in advance!
Upvotes: 13
Views: 4932
Reputation: 22728
This extension will do exactly what you wished for:
vscode-endwise
: This is an extension that wisely adds the "end" keyword to code structures in languages like Ruby or Crystal while keeping the correct indentation levels
Enjoy!
Upvotes: 7
Reputation: 415
I found a workaround that suffices for now. Using Code -> Preferences -> User Snippers -> Ruby I added the following snippets
"Do block": {
"prefix": "dob",
"body": [
"do",
"\t$0",
"end"
],
"description": "Do block"
},
"Do block with params": {
"prefix": "dobwp",
"body": [
"do |${1:param}|",
"\t$0",
"end"
],
"description": "Do block with params"
}
The first one inserts a
do
end
without any parameters. The second one inserts a
do |param|
end
and you can choose the param value.
The downside is that when writing do you have to move down and choose dob or dobwp and it's not the default behaviour of do like in sublime.
Upvotes: 12
Reputation: 4183
Did you try https://github.com/rubyide/vscode-ruby ? It states that
This extension provides rich Ruby language and debugging support for VS Code.
including Autocomplete. Maybe worth a try.
Upvotes: 5