Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make VSCode automatically insert 'end' on enter press after 'do' [closed]

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!

like image 690
xenover Avatar asked Sep 19 '17 12:09

xenover


2 Answers

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.

like image 138
xenover Avatar answered Oct 05 '22 23:10

xenover


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.

like image 28
StandardNerd Avatar answered Oct 05 '22 22:10

StandardNerd