Skip to content

watkit/lspsaga.nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

                                 __
                                / /________  _________ _____ _____ _
                               / / ___/ __ \/ ___/ __ `/ __ `/ __ `/
                              / (__  ) /_/ (__  ) /_/ / /_/ / /_/ /
                             /_/____/ .___/____/\__,_/\__, /\__,_/
                                   /_/               /____/

                          ⚡ designed for convenience and efficiency ⚡

A light-weight lsp plugin based on neovim's built-in lsp with a highly performant UI.

  1. Install
  2. Example Configuration
  3. Usage Turtorial
  4. Customize Appearance
  5. Donate
  6. License

Install

you can use some plugins management like lazy.nvim, packaer.nvim to install lspsaga and lazyload by the plugin management keyword.

  • cmd lazylod by lspsaga command
  • ft lazy.nvim and packer both provide lazyload by filetype. then you can load the lspsaga according the filetypes which you write and use lsp.
  • event lazyload by event like BufRead,BufReadPost make sure your lsp plugin also loaded.
  • dependices for lazy.nvim you can set the lspsaga into nvim-lspconfig or other lsp plugin dependices keyword.
  • after for packer you can use after keyword.

Lazy

require('lazy').setup({
    'glepnir/lspsaga.nvim',
    event = 'BufRead',
    config = function()
        require('lspsaga').setup({})
    end
},opt)

Packer

use({
    "glepnir/lspsaga.nvim",
    branch = "main",
    config = function()
        require('lspsaga').setup({})
    end,
})

Example Configuration

require('lazy').setup({
    'glepnir/lspsaga.nvim',
    event = 'BufRead',
    config = function()
      require('lspsaga').setup({})
    end
})

local keymap = vim.keymap.set
-- Lsp finder find the symbol definition implement reference
-- if there is no implement it will hide
-- when you use action in finder like open vsplit then you can
-- use <C-t> to jump back
keymap("n", "gh", "<cmd>Lspsaga lsp_finder<CR>")

-- Code action
keymap({"n","v"}, "<leader>ca", "<cmd>Lspsaga code_action<CR>")

-- Rename
keymap("n", "gr", "<cmd>Lspsaga rename<CR>")

-- Peek Definition
-- you can edit the definition file in this flaotwindow
-- also support open/vsplit/etc operation check definition_action_keys
-- support tagstack C-t jump back
keymap("n", "gd", "<cmd>Lspsaga peek_definition<CR>")

-- Go to Definition
keymap("n","gd", "<cmd>Lspsaga goto_definition<CR>")

-- Show line diagnostics you can pass arugment ++unfocus to make
-- show_line_diagnsotic float window unfocus
keymap("n", "<leader>sl", "<cmd>Lspsaga show_line_diagnostics<CR>")

-- Show cursor diagnostic
-- also like show_line_diagnostics  support pass ++unfocus
keymap("n", "<leader>sc", "<cmd>Lspsaga show_cursor_diagnostics<CR>")

-- Show buffer diagnostic
keymap("n", "<leader>sb", "<cmd>Lspsaga show_buf_diagnostics<CR>")

-- Diagnsotic jump can use `<c-o>` to jump back
keymap("n", "[e", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
keymap("n", "]e", "<cmd>Lspsaga diagnostic_jump_next<CR>")

-- Diagnostic jump with filter like Only jump to error
keymap("n", "[E", function()
  require("lspsaga.diagnostic").goto_prev({ severity = vim.diagnostic.severity.ERROR })
end)
keymap("n", "]E", function()
  require("lspsaga.diagnostic").goto_next({ severity = vim.diagnostic.severity.ERROR })
end)

-- Toglle Outline
keymap("n","<leader>o", "<cmd>Lspsaga outline<CR>")

-- Hover Doc
keymap("n", "K", "<cmd>Lspsaga hover_doc<CR>")

-- Callhierarchy
keymap("n", "<Leader>ci", "<cmd>Lspsaga incoming_calls<CR>")
keymap("n", "<Leader>co", "<cmd>Lspsaga outgoing_calls<CR>")

-- Float terminal
keymap({"n", "t"} "<A-d>", "<cmd>Lspsaga term_toggle<CR>")

Usage Tutorial

Notice that title in float window must need neovim version >= 0.9

default options

  preview = {
    lines_above = 0,
    lines_below = 10,
  },
  scroll_preview = {
    scroll_down = '<C-f>',
    scroll_up = '<C-b>',
  },
  request_timeout = 2000,

:Lspsaga lsp_finder

Finder to show the defintion,reference,implement(only show when current word is interface or some type)

default finder options

  finder = {
    edit = { 'o', '<CR>' },
    vsplit = 's',
    split = 'i',
    tabe = 't',
    quit = { 'q', '<ESC>' },
  },
lsp finder show case

:Lspsaga peek_definition

there has two commands Lspsaga peek_defintion and Lspsaga goto_defintion, the peek_defitnion work like vscode that show the target file in a floatwindow you can edit as normalize.

options with default value

  definition = {
    edit = '<C-c>o',
    vsplit = '<C-c>v',
    split = '<C-c>i',
    tabe = '<C-c>t',
    quit = 'q',
    close = '<Esc>',
  }
peek_definition show case

the step in this gif show case

  • gd run lspsaga peek_definition.
  • do some comment edit then :w to save.
  • <C-c> o jump to this file.
  • lspsaga will show becacon highlight after jump .

:Lspsaga goto_definition

jump to definition and show beacon

:Lspsaga code_action

options with default value

  code_action = {
    num_shortcut = true,
    keys = {
      quit = 'q',
      exec = '<CR>',
    },
  },
  • num_shortcut it's true by default then you can use number to fast run action
code_action show case
  • ga run Lspsaga code_action
  • j to move and show the code action preview
  • <Cr> to run a action

:Lspsaga Lightbulb

when there has code action it will show a lightbulb, default options.

  lightbulb = {
    enable = true,
    enable_in_insert = true,
    sign = true,
    sign_priority = 40,
    virtual_text = true,
  },
lightbulb show case

:Lspasga hover_doc

lspsaga use treesitter markdown parser to render hover. so you must install markdown parser. you can press shotcut of Lspsaga hover_doc twice jump into the hover window. in my case is K.

hover_doc show case
  • K to run Lspsaga hover_doc.
  • press K again jump into the hover window.
  • q to quit.

:Lspsaga diagnostic_jump_next

jump to next diagnsotic position then show beacon and show the codeaction. default options

  diagnostic = {
    twice_into = false,
    show_code_action = true,
    show_source = true,
    keys = {
      exec_action = 'o',
      quit = 'q',
    },
  },

if twice_into set to true, press twice the diagnostic jump shortcut it will jump into the floatwindow. other way is use wincmd to jump into use <C-w>w.

also you can use a filter in diagnostic jump by using lspsaga function. function params is a table same as :h vim.diagnsotic.get_next

-- this is mean only jump to error position
-- or goto_next
require("lspsaga.diagnostic").goto_prev({ severity = vim.diagnostic.severity.ERROR })
diagnostic jump show case
  • [e to jump next diangostic position.
  • <C-w>w jump into the float window.
  • j to move.
  • o to execuate an action.

:Lspsaga show_diagnsotic

show_line_diagnsotic , show_buf_diagnostics ,show_cursor_diagnostics

show diangostics show case

:Lspsaga rename

lsp rename with select. default options

  rename = {
    quit = '<C-c>',
    exec = '<CR>',
    in_select = true,
  },
rename show case
  • gr to run Lspsaga rename
  • stesdd<CR>

:Lspsaga outline

default options

  outline = {
    win_position = 'right',
    win_with = '',
    win_width = 30,
    show_detail = true,
    auto_preview = true,
    auto_refresh = true,
    auto_close = true,
    custom_sort = nil,
    keys = {
      jump = 'o',
      expand_collaspe = 'u',
      quit = 'q',
    },
  },
outline show case
  • <Leader>o run Lspsaga outline
  • j move down
  • o to jump

:Lspsaga incoming_calls

run lsp callhierarchy incoming_calls. default options

  callhierarchy = {
    show_detail = false,
    keys = {
      edit = 'e',
      vsplit = 's',
      split = 'i',
      tabe = 't',
      jump = 'o',
      quit = 'q',
      expand_collaspe = 'u',
    },
  },
incoming_calls show case

:Lspsaga outgoing_calls

run lsp callhierarchy outgoing_calls

outgoing show_case

:Lspsaga symbols in winbar

require your neovim version >= 0.8. options with default value

  symbol_in_winbar = {
    enable = true,
    separator = '',
    hide_keyword = true,
    show_file = true,
    folder_level = 2,
  },
  • hide_keyword default is true it will hide some keyword or tmp variable make symbols more clean
  • folder_level work with show_file
symbols in winbar

:Lspaga symbols in custom winbar/statusline

lspsaga provide an api that you can use in your custom winbar or statusline.

vim.wo.winbar/ vim.wo.stl = require('lspsaga.symbolwinbar'):get_winbar()

:Lspsaga term_toggle

simple floaterm

float terminal toggle

Customize Appearance

:Lspsaga UI

default ui options

  ui = {
    -- currently only round theme
    theme = 'round',
    -- border type can be single,double,rounded,solid,shadow.
    border = 'solid',
    winblend = 0,
    expand = '',
    collaspe = '',
    preview = '',
    code_action = '💡',
    diagnostic = '🐞',
    incoming = '',
    outgoing = '',
    colors = {
      --float window normal bakcground color
      normal_bg = '#1d1536',
      --title background color
      title_bg = '#afd700',
      red = '#e95678',
      magenta = '#b33076',
      orange = '#FF8700',
      yellow = '#f7bb3b',
      green = '#afd700',
      cyan = '#36d0e0',
      blue = '#61afef',
      purple = '#CBA6F7',
      white = '#d1d4cf',
      black = '#1c1c19',
    },
    kind = {},
  },

Custom Highlight

you can change the default colors or only change some highlight groups which you want change. find all highlight groups in highlight.lua

Custom Kind

kind field is a table that key is kind name, value is icon, all kind defined in lspkind.lua

Donate

If you'd like to support my work financially, buy me a drink through paypal.

License

Licensed under the MIT license.

About

neovim lsp plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%