Skip to content

Latest commit

 

History

History
179 lines (143 loc) · 6.34 KB

README.md

File metadata and controls

179 lines (143 loc) · 6.34 KB

ror.nvim

Make Ruby on Rails development experience FUN!

YouTube demo video.

Installation

Plug 'weizheheng/ror.nvim'

Dependencies

  1. telescope

Optional Dependencies

  1. 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.
  2. 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 } }), }
})

Usage

-- 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 })

LunarVim

-- Set a keybind
lvim.builtin.which_key.mappings["r"] = {
    name = "Ruby on Rails",
    c = { "<cmd>lua require('ror.commands').list_commands()<cr>", "RoR Menu" },
}

Features

1. Test Helpers

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

Prerequisite

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

2. Finders

I love Telescope, but sometimes there are just too much noise. ROR finders allow you to quickly look for files in:

  1. Models and model tests
  2. Controllers and controller tests
  3. Views
  4. Migrations and more
CleanShot.2023-02-01.at.17.03.57.mp4

3. Generators helpers

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

4. Destroyer helpers

Each Rails generators have a destroyer too!

CleanShot.2023-02-01.at.17.21.52.mp4

5. CLI helpers

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

6. Navigation helpers

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

7. Routes helpers

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

8. Schema helpers

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

Prerequisite

  • Snippets is tested to be working with Luasnip
  • This should work with other snippets plugin if they support loading Vscode-like snippets

Usage

-- With luasnip installed, you will need to add this line to your config
require("luasnip.loaders.from_vscode").lazy_load()