Git Product home page Git Product logo

fastaction.nvim's Introduction

FastAction.nvim

FastAction.nvim is a sleek, efficiency plugin designed to optimize code actions in Neovim. By leveraging Neovim's built-in LSP capabilities, it offers a simple and intuitive interface that enhances your coding experience.

Features

  • Popup Interface: Display code actions in a customizable popup window.
  • Keybindings: Configure keys to quickly dismiss or select code actions, making your workflow more efficient.
  • Priority Handling: Customize the display order of actions based on priority, ensuring the most used actions are always visible on top.
  • Flexible Selection: Extendable selection prompt that can replace Neovim's built-in vim.ui.select, providing more versatility in how you interact with lists

Installation

Using lazy.nvim

  {
      'Chaitanyabsprip/fastaction.nvim',
      ---@type FastActionConfig
      opts = {},
  }

Configuration

fastaction.nvim comes with sensible defaults to get you started quickly:

{
  dismiss_keys = { "j", "k", "<c-c>", "q" },
  override_function = function(_) end,
  keys = "qwertyuiopasdfghlzxcvbnm",
  popup = {
    border = "rounded",
    hide_cursor = true,
    highlight = {
      divider = "FloatBorder",
      key = "MoreMsg",
      title = "Title",
      window = "NormalFloat",
    },
    title = "Select one of:",
  },
  priority = {
    -- dart = {
    --   { pattern = "organize import", key ="o", order = 1 },
    --   { pattern = "extract method", key ="x", order = 2 },
    --   { pattern = "extract widget", key ="e", order = 3 },
    -- },
  },
 register_ui_select = false,
}

The order key in the priority table determines the position of that match in the code actions selection prompt. Lower number means higher up in the prompt.

Example Configuration
{
  dismiss_keys = { "j", "k", "<c-c>", "q" },
  override_function = function(params) -- to retain built-in style keymaps
      params.invalid_keys[#params.invalid_keys + 1] = tostring(#params.invalid_keys + 1)
      return { key = tostring(#params.invalid_keys), order = 0 }
  end,
  keys = "asdfghlzxcvbnm",
  popup = {
    border = "rounded",
    hide_cursor = true,
    highlight = {
      divider = "FloatBorder",
      key = "MoreMsg",
      title = "Title",
      window = "NormalFloat",
    },
    title = "Select one of:",
  },
  priority = {
    dart = {
      { pattern = "organize import", key ="o", order = 1 },
      { pattern = "extract method", key ="x", order = 2 },
      { pattern = "extract widget", key ="e", order = 3 },
    },
    typescript = {
      { pattern = 'to existing import declaration', key = 'a', order = 2 },
      { pattern = 'from module', key = 'i', order = 1 },
    }
  }
}

Usage

fastaction.nvim exposes three function apart from setup.

  • code_action(): Displays code actions in a popup window.
  • range_code_action(): Displays code actions in a popup window for a visual range.
  • select(items: any, opts: SelectOpts, on_choice: fun(item: any)): Displays a selection prompt window for items.

To integrate these functions with your LSP mappings, add the following to your configuration:

    vim.keymap.set(
        'n',
        '<leader>a',
        '<cmd>lua require("fastaction").code_action()<CR>',
        { buffer = bufnr }
    )
    vim.keymap.set(
        'v',
        '<leader>a',
        "<esc><cmd>lua require('fastaction').range_code_action()<CR>",
        { buffer = bufnr }
    )

You can also use require('fastaction').select as a replacement for vim.ui.select.

code-action

How it works

fastaction.nvim enhances the selection process by assigning key mappings to each option in the selection prompt. Here's how it achieves this:

Intelligent key mapping

For each option, the plugin selects a key mapping based on the priority configuration. If no priority is set, it falls back to using the letters in the option's title. For example, if the option is "organize imports," the plugin first checks if the 'o' key is available. If 'o' is taken, it moves to the next letter, 'r,' and so on, until it finds an available key The code_action and range_code_action functions are essentially using the stylised prompt to choose from the code actions.

Streamlined Code Actions

The code_action and range_code_action functions utilize this intelligent prompt to display and select from the available code actions efficiently. By leveraging this stylized prompt, FastAction.nvim ensures a smoother and more intuitive selection process, making your coding experience more fluid and enjoyable.

Credit

This repository is a fork of nvim-pack/lsp-fastaction.nvim building on its foundations to provide an even more streamlined and efficient experience.

fastaction.nvim's People

Contributors

chaitanyabsprip avatar windwp avatar akinsho avatar eslam-allam avatar diniamo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.