Skip to content

wassimk/cmp-rails-fixture-names

Repository files navigation

cmp-rails-fixture-names

This plugin is a source for nvim-cmp to complete Ruby on Rails fixture names. Names meaning the individual fixtures each fixture type represents.

For example, a User model would have a users fixture type and each fixture has a name. If you have a user fixture called bob. This cmp source will auto-complete the fixture name bob when you type users(:.

It will also parse the fixture file and show the fixture data/attributes in the documentation window.

There is a companion plugin, called cmp-rails-fixture-types that only completes fixture types.

Setup

Prerequisites

Fixtures must exist in the default location of test/fixtures or spec/fixtures and be .yml files.

This plugin regex parses the YAML files for completion data so anything fancy like a Ruby loop that generates fixtures will likely break.

Installation

Using with nvim-cmp

Install cmp-rails-fixture-names using your plugin manager of choice. For example, here it is using lazy.nvim:

{
  "hrsh7th/nvim-cmp",
  dependencies = {
    { "wassimk/cmp-rails-fixture-names", version = "*", ft = "ruby" },
  },
}

Then add rails-fixture-names source in your nvim-cmp configuration:

require("cmp").setup {
  -- ...
  sources = {
    { name = "rails-fixture-names" },
    -- other sources ...
  },
  -- ...
}

Using with blink.cmp

Since blink.cmp doesn't directly support nvim-cmp sources, you'll need to use the blink.compat compatibility layer. Install both plugins:

{
  'saghen/blink.compat',
  version = '2.*',
  lazy = true,
  opts = {},
  dependencies = {
    { 'wassimk/cmp-rails-fixture-names', version = '*', ft = 'ruby' },
  },
},
{
  'saghen/blink.cmp',
  version = '1.*',
  opts = {
    sources = {
      per_filetype = {
        ruby = {
          inherit_defaults = true,
          'rails_fixture_names'
        },
      },
      providers = {
        rails_fixture_names = {
          name = 'rails_fixture_names',
          module = 'blink.compat.source',
        },
      },
    },
  },
}

About

An nvim-cmp source for Ruby on Rails fixture names including documentation

Resources

License

Stars

Watchers

Forks

Languages