Git Product home page Git Product logo

lspsaga.nvim's Introduction

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

                          ⚡ 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 Tutorial
  4. Customize Appearance
  5. Backers
  6. Donate
  7. License

Install

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

  • cmd lazyload 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,
    dependencies = { {'nvim-tree/nvim-web-devicons'} }
},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>")

-- Rename word in whole project
keymap("n", "gr", "<cmd>Lspsaga rename ++project<CR>")

-- Peek Definition
-- you can edit the definition file in this float window
-- 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
-- press twice it will jump into hover window
keymap("n", "K", "<cmd>Lspsaga hover_doc<CR>")
-- if you want keep hover window in right top you can use ++keep arg
-- notice if you use hover with ++keep you press this keymap it will
-- close the hover window .if you want jump to hover window must use
-- wincmd command <C-w>w
keymap("n", "K", "<cmd>Lspsaga hover_doc ++keep<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>' },
  },
lsp finder show case

: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 run lspsaga peek_definition.
  • do some comment edit then :w to save.
  • <C-c> o jump to this file.
  • lspsaga will show beacon 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'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 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 floatwindow
  • jump_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 preview
  • o execute the action

:Lspsaga show_diagnostic

show_line_diagnostics , show_buf_diagnostics ,show_cursor_diagnostics

show diagnostics show case

:Lspsaga rename

lsp rename with select. default options

  rename = {
    quit = '<C-c>',
    exec = '<CR>',
    mark = 'x',
    confirm = '<CR>',
    in_select = true,
  },
  • mark used for ++project used to markd the file which you want als rename.
  • confirm after you marked the lines then press this keymap to execute.
rename show case
  • gr to run Lspsaga rename
  • stesdd<CR>
  • gR to run Lspsaga rename ++project
  • x to mark the file
  • CR to execute rename

: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',
    },
  },
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_collapse = '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,
    respect_root = false,
    color_mode = true,
  },
  • hide_keyword default is true it will hide some keyword or tmp variable make symbols more clean
  • folder_level work with show_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_level
  • color_mode default is true, false mean only icon have color.
symbols in winbar

: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

float terminal toggle

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.

@Möller Lukas @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.

lspsaga.nvim's People

Contributors

adelarsq avatar akinsho avatar alex-popov-tech avatar alienover avatar charlie39 avatar ckipp01 avatar cooperuser avatar elianiva avatar github-actions[bot] avatar glepnir avatar jint-lzxy avatar joeveiga avatar kuznetsss avatar leaxoy avatar leoatchina avatar nullchilly avatar phsix avatar rakerzh avatar someoneinjd avatar speed2exe avatar tamago324 avatar tapayne88 avatar tkmpypy avatar uga-rosa avatar unoqwy avatar vrshard avatar weilbith avatar xmgplays avatar xxiaoa avatar yuki-yano 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.