__
/ /________ _________ _____ _____ _
/ / ___/ __ \/ ___/ __ `/ __ `/ __ `/
/ (__ ) /_/ (__ ) /_/ / /_/ / /_/ /
/_/____/ .___/____/\__,_/\__, /\__,_/
/_/ /____/
⚡ designed for convenience and efficiency ⚡
A light-weight lsp plugin based on neovim's built-in lsp with a highly performant UI.
Install
you can use some plugins management like lazy.nvim
, packer.nvim
to install lspsaga
and lazyload by the plugin management keyword.
cmd
lazyload bylspsaga
commandft
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 likeBufRead,BufReadPost
make sure your lsp plugin also loaded.dependices
for lazy.nvim you can set thelspsaga
intonvim-lspconfig
or other lsp plugindependices
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 argument ++unfocus to make
-- show_line_diagnostics 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>")
-- Diagnostic 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)
-- Toggle Outline
keymap("n","<leader>o", "<cmd>Lspsaga outline<CR>")
-- Hover Doc
-- if there has no hover will have a notify no information available
-- to disable it just Lspsaga hover_doc ++quiet
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 So if you are using the nvim 0.8 version you can't see title **If you are using nvim 0.9 and want disable title see [#customize-appearance]
For some new you don't need copy all options into setup function. just set the options that you changed into setup function it will extend to default options!
you can find these doc in neovim by :h lspsaga
.
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>' },
},
:Lspsaga peek_definition
there has two commands Lspsaga peek_definition
and Lspsaga goto_definition
, the peek_definition
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
runlspsaga 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 = {
-- string |table type
quit = 'q',
exec = '<CR>',
},
},
num_shortcut
it'strue
by default then you can use number to fast run action
code_action show case
ga
runLspsaga 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,
},
: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 runLspsaga hover_doc
.- press
K
again jump into the hover window. q
to quit.
:Lspsaga diagnostic_jump_next
jump to next diagnostic position then show beacon and show the codeaction. default options
diagnostic = {
show_code_action = true,
show_source = true,
jump_num_shortcut = true,
keys = {
exec_action = 'o',
quit = 'q',
go_action = 'g'
},
},
go_action
can quickly jump to action line in diagnostic floatwindowjump_num_shortcut
default is true after jump. Lspasga will auto bind the numbers to action index then just press number will execute the code action. after window close these number map will delete
also you can use a filter in diagnostic jump by using lspsaga function. function params is a table
same as :h vim.diagnostic.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 diagnostic position and show beacon and code actions in diagnostic window- press number
2
to execute code action no need jump into that window
- if you want to see the code action. you can using
<C-w>w
jump into the floatwindow g
go to the action line see the code action previewo
execute the action
:Lspsaga show_diagnostic
show_line_diagnostics
, show_buf_diagnostics
,show_cursor_diagnostics
:Lspsaga rename
lsp rename with select. default options
rename = {
quit = '<C-c>',
exec = '<CR>',
mark = 'x',
confirm = '<CR>',
in_select = true,
whole_project = true,
},
whole_project
support rename whole project after using lsp rename byrg
.mark
after lsp rename if there still have this word in project then will popup a window that include the files which include the word.then you can use this key mark the line that you want changed.confirm
when you marked the lines then press this keymap to execute.
: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_collapse = 'u',
quit = 'q',
},
},
: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_collapse = 'u',
},
},
:Lspsaga outgoing_calls
run lsp callhierarchy outgoing_calls
: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,
respect_root = false,
color_mode = true,
},
hide_keyword
default is true it will hide some keyword or tmp variable make symbols more cleanfolder_level
work withshow_file
respect_root
will respect lsp root if this is true will ignore the folder_level. if there is no lsp client usage then fallback to folder_levelcolor_mode
default is true, false mean only icon have color.
:Lspsaga 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
Customize Appearance
:Lspsaga UI
default ui options
ui = {
-- currently only round theme
theme = 'round',
-- this option only work in neovim 0.9
title = true,
-- border type can be single,double,rounded,solid,shadow.
border = 'solid',
winblend = 0,
expand = '',
collapse = '',
preview = ' ',
code_action = '💡',
diagnostic = '🐞',
incoming = ' ',
outgoing = ' ',
colors = {
--float window normal background 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
If you don't like config the colors or you use switch colorschem according time then you can use the old way. change the highlight group in your colorscheme or config. find all highlight groups in highlight.lua
Custom Kind
through ui.kind
to modified the all kinds defined in lspkind.lua
the key in ui.kind
is kind name, value can be string or table if string type is icon if table type
is {icon, color}
.
Backers
Thanks for all.
@HendrikPetertje @Bojan Wilytsch @Burgess Darrion
Donate
Currently I need some donate. If you'd like to support my work financially, donate through paypal. Thanks!
License
Licensed under the MIT license.