Make Ruby on Rails development experience FUN!
YouTube demo video.
Plug 'weizheheng/ror.nvim'
- nvim-notify (RECOMMENDED)
- With nvim-notify installed you can get beautiful notification on when the test is running and also display the result of the run when it's done.
- Otherwise, the notification will be shown in the command line through vim.notify.
- dressing.nvim
- I am using this plugin which make vim.ui.select to use telescope and also vim.ui.input to be a floating window asking for input as shown in my demo.
- The config I am using for dressing.nvim
require("dressing").setup({
input = {
min_width = { 60, 0.9 },
},
select = {
-- telescope = require('telescope.themes').get_ivy({...})
telescope = require('telescope.themes').get_dropdown({ layout_config = { height = 15, width = 90 } }), }
})
-- The default settings
require("ror").setup({
test = {
message = {
-- These are the default title for nvim-notify
file = "Running test file...",
line = "Running single test..."
},
coverage = {
-- To customize replace with the hex color you want for the highlight
-- guibg=#354a39
up = "DiffAdd",
-- guibg=#4a3536
down = "DiffDelete",
},
notification = {
-- Using timeout false will replace the progress notification window
-- Otherwise, the progress and the result will be a different notification window
timeout = false
},
pass_icon = "✅",
fail_icon = "❌"
}
})
-- Set a keybind
-- This "list_commands()" will show a list of all the available commands to run
vim.keymap.set("n", "<Leader>rc", ":lua require('ror.commands').list_commands()<CR>", { silent = true })
-- Set a keybind
lvim.builtin.which_key.mappings["r"] = {
name = "Ruby on Rails",
c = { "<cmd>lua require('ror.commands').list_commands()<cr>", "RoR Menu" },
}
Writing test in Rails is fun, but ror.nvim is bringing it to the next level with features like:
- Easily run all the tests in the file
- Easily run only a single test in the file
- Test results are shown in the file itself
- Show coverage percentage and also which lines are covered or not covered (with simplecov)
- Popup window for debugging purpose when you put a debugger in your test.
CleanShot.2023-02-01.at.16.51.56-converted-converted.mp4
If you are using minitest, you will need to install the minitest-json-reporter to your Ruby on Rails project:
group :test do
gem "minitest-json-reporter"
end
I love Telescope, but sometimes there are just too much noise. ROR finders allow you to quickly look for files in:
- Models and model tests
- Controllers and controller tests
- Views
- Migrations and more
CleanShot.2023-02-01.at.17.03.57.mp4
Rails provide a lot of generator methods, but one just couldn't remember them all!
Supported generators:
- Model
- Mailer
- Migration (add_column, remove_column, add_index)
- Controller
- System test
CleanShot.2023-02-01.at.17.16.25.mp4
Each Rails generators have a destroyer too!
CleanShot.2023-02-01.at.17.21.52.mp4
There are a few commands that Rails developers will run daily while developing, instead of switching to your console, just run it in Neovim!
Supported commands:
- bundle update
- bundle install
- rails db:migrate
- rails db:migrate:status
- rails db:rollback STEP=1
CleanShot.2023-02-01.at.17.24.46.mp4
Rails follows the Model, View, Controller (MVC) pattern, navigations helper provide a way to easily jump to the associated models, views, and controllers easily. Of course, you can quickly jump to the test files too!
CleanShot.2023-02-01.at.17.47.46.mp4
When working in a big project, it's very hard to remember all the routes. Rails does provide a CLI
method like rails routes
to list all the routes but that command is SLOwwwww. ROR routes helpers
provide a better experience to look through all the routes in your project.
CleanShot.2023-02-01.at.18.01.33.mp4
I bet there are times you don't remember what columns does an ActiveRecord model has? And you have to go to schema.rb and look through them? ror.nvim is here to help!
CleanShot.2023-02-01.at.18.06.37.mp4
9. Snippets + ror-lsp (EXPERIMENTAL)
I have been a Rails developer for 3 years now, and sometimes I still don't remember a lot of the built-in methods. There are active developments on adding types to Ruby code with tools like Sorbet and Ruby's built-in rbs which when pair with steep might give a very good developmet experience with all language server features.
I came across Aaron Patterson's YouTube video on creating a language server and also Shopify's ror-lsp GitHub repo and decided to create my own ror-lsp.
CleanShot.2023-02-01.at.18.35.01-converted.mp4
- Snippets is tested to be working with Luasnip
- This should work with other snippets plugin if they support loading Vscode-like snippets
-- With luasnip installed, you will need to add this line to your config
require("luasnip.loaders.from_vscode").lazy_load()