Reputation: 558
I'm using MacOS and I have installed VSCode, Ruby, rubocop, Ruby Solargraph, and their gem dependencies.
Having done this, how do I now execute a Ruby script without using the Terminal panel within VSCode?
Upvotes: 25
Views: 48234
Reputation: 7276
There are multiple ways:
Add the following task to your project's .vscode/tasks.json
file and then run it:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run ruby file",
"type": "shell",
"command": "ruby ${file}",
"presentation": {
"reveal": "always",
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
}
]
}
You might want to remap the F5
key in keybindings.json
to execute that task instead of the default behavior which fires a debugger. This is what I personally prefer to do.
{
"key": "f5",
"command": "-workbench.action.debug.start",
},
{
"key": "f5",
"command": "workbench.action.tasks.runTask",
"args": "Run ruby file", /* Label of the task defined above */
"when": "editorTextFocus && editorLangId == 'ruby'"
}
Shopify.ruby-lsp
).create a launch.json file
link.Debug: Start Without Debugging
action.The downside of this method is that it prints the additional information from a debugger.
Ruby REPL: You can run any Ruby expression here. Note that output to the STDOUT/ERR printed on the TERMINAL. [experimental]
,COMMAND
runsCOMMAND
debug command (ex:,info
).,help
to list all debug commands. DEBUGGER: Disconnected.
Upvotes: 4
Reputation: 49
You can try "Ruby Runner" extension for VS Code. It's works well in 2021.
https://marketplace.visualstudio.com/items?itemName=MateuszDrewniak.ruby-runner
Upvotes: 4
Reputation: 657
You have 2 choices for this case;
Install Code runner extension
Then , CTRL
+ ALT
+ N
Install Code runner extension
Cmd
+ Shift
+ p
choose Run By language
type ruby
wallla 🔥
Upvotes: 18
Reputation: 26071
You can use Coder Runner Extension.
Once adding the extension you press Command + Shift + P
and select run by language
then choose ruby
Upvotes: 32