Coder Social home page Coder Social logo

nvim-lightbulb's Introduction

nvim-lightbulb

VSCode ๐Ÿ’ก for neovim's built-in LSP.

Code Action selection window shown in the gif is telescope.nvim

Introduction/Rationale

The plugin shows a lightbulb in the sign column whenever a textDocument/codeAction is available at the current cursor position.

This makes code actions both discoverable and efficient, as code actions can be available even when there are no visible diagnostics (warning, information, hints etc.).

Getting Started

Prerequisites

  • neovim with LSP capabilities.

Installation

Just like any other plugin.

Example using vim-plug:

Plug 'kosayoda/nvim-lightbulb'

Usage

Call require('nvim-lightbulb').update_lightbulb() whenever you want to show a lightbulb if a code action is available at the current cursor position. Example with an autocmd for all filetypes:

VimScript:

autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()

Lua:

vim.cmd [[autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()]]

Configuration

Available options:
-- Showing defaults
require'nvim-lightbulb'.update_lightbulb {
    sign = {
        enabled = true,
        -- Priority of the gutter sign
        priority = 10,
    },
    float = {
        enabled = false,
        -- Text to show in the popup float
        text = "๐Ÿ’ก",
        -- Available keys for window options:
        -- - height     of floating window
        -- - width      of floating window
        -- - wrap_at    character to wrap at for computing height
        -- - max_width  maximal width of floating window
        -- - max_height maximal height of floating window
        -- - pad_left   number of columns to pad contents at left
        -- - pad_right  number of columns to pad contents at right
        -- - pad_top    number of lines to pad contents at top
        -- - pad_bottom number of lines to pad contents at bottom
        -- - offset_x   x-axis offset of the floating window
        -- - offset_y   y-axis offset of the floating window
        -- - anchor     corner of float to place at the cursor (NW, NE, SW, SE)
        -- - winblend   transparency of the window (0-100)
        win_opts = {},
    },
    virtual_text = {
        enabled = false,
        -- Text to show at virtual text
        text = "๐Ÿ’ก",
    },
    status_text = {
        enabled = false,
        -- Text to provide when code actions are available
        text = "๐Ÿ’ก",
        -- Text to provide when no actions are available
        text_unavailable = ""
    }
}
Modify the lightbulb sign:

Fill text, texthl, linehl, and numhl according to your preferences

VimScript:

call sign_define('LightBulbSign', { text = "", texthl = "", linehl="", numhl="" })

Lua:

vim.fn.sign_define('LightBulbSign', { text = "", texthl = "", linehl="", numhl="" })
Modify the lightbulb float window and virtual text colors

Fill ctermfg, ctermbg, guifg, guibg according to your preferences

VimScript:

augroup HighlightOverride
  autocmd!
  au ColorScheme * highlight LightBulbFloatWin ctermfg= ctermbg= guifg= guibg=
  au ColorScheme * highlight LightBulbVirtualText ctermfg= ctermbg= guifg= guibg=
augroup END

Lua:

vim.api.nvim_command('highlight LightBulbFloatWin ctermfg= ctermbg= guifg= guibg=')
vim.api.nvim_command('highlight LightBulbVirtualText ctermfg= ctermbg= guifg= guibg=')
Status-line text usage

With the status_text option enabled you can access the current lightbulb state through the lua function require'nvim-lightbulb'.get_status_text(). This allows easy integration with multiple different status line plugins.

nvim-lightbulb's People

Contributors

alaric avatar ikws4 avatar kosayoda avatar tamago324 avatar vvkot avatar weilbith avatar

Watchers

 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.