LSP / Code Completions
Adds code completions capabilities with nvim-cmp and nvim-lspconfig.
This module adds a number of code completion features to neovim. It sets up nvim-cmp with lsp, path, buffer, nvim and snippet sources and also adds lsp signatures to show function signatures as you type. This module does not setup any language LSPs, those are configured within the language modules. Instead this module setups and configures nvim-cmp and other plugins that are shared by language modules.
Adding extra nvim-cmp sourcesâ
To add extra completion sources to nvim-cmp you will first need to install
the nvim-cmp extension in your config.lua file. You will then need to
add the source to the settings table of this module. Here's an example
using cmp-calc.
-- config.lua
doom.use_package("hrsh7th/cmp-calc")
local lsp_settings = doom.features.lsp.settings
table.insert(lsp_settings.completion.sources, { name = 'calc' })
If you want to add a source that needs access to nvim-cmp. I.e cmp-nvim-lsp-document-symbol
you will need to use the on_post_config hook of the packages field of the lsp
module.
-- config.lua
doom.use_package({ "hrsh7th/cmp-nvim-lsp-document-symbol", after="nvim-cmp" })
doom.features.lsp.packages["nvim-cmp"].on_post_config(function()
local cmp = require'cmp'
cmp.setup.cmdline('/', {
sources = cmp.config.sources({
{ name = 'nvim_lsp_document_symbol' }
}, {
{ name = 'buffer' }
})
})
end)
đĄ You will have reload doom-nvim and run
:PackerCompileafter adding pre/post config hooks.
đĄ Some cmp completion sources do not work well with lazy loading. You may have to disable lazy loading so it works properly.
doom.features.lsp.packages['nvim-cmp'].event = nil -- Removes the load on InsertEnter autocommand
Settingsâ
Settings for the lsp module.
You can access and override these values in your config.lua. I.e.
local lsp_settings = doom.features.lsp.settings
lsp_settings.<field> = <new_value>
lsp.settings = {
-- Settings for cmp_luasnip
snippets = {
history = true,
updateevents = "TextChanged,TextChangedI",
},
-- Settings for "lsp_signature.nvim"
signature = {
-- This is mandatory, otherwise border config won't get registered.
-- If you want to hook lspsaga or other signature handler, pls set to false
bind = true,
-- Show hint in a floating window
floating_window = false,
-- Position floating window above or below cursor
floating_window_above_cur_line = true,
-- Number of comment/doc lines when inserting text (when `floating_window = true`)
doc_lines = 10,
-- When true, keep floating window open until all parameters completed
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = true, -- virtual hint enable
hint_prefix = "îĄ ",
hint_scheme = "String",
hi_parameter = "Search", -- how your parameter will be highlight
max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
transparency = 100,
extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom
debug = false, -- set to true to enable debug logging
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
shadow_blend = 36, -- if you using shadow as border use this set the opacity
shadow_guibg = "Black", -- if you using shadow as border use this set the color e.g. 'Green' or '#121315'
},
icons = {
error = "ī",
warn = "īą",
hint = "īĒ",
info = "ī",
},
severity_sort = true,
-- Settings for nvim-cmp
completion = {
-- Icons for each completion type
kinds = {
Text = "ī ",
Method = "īĻ ",
Function = "ī ",
Constructor = "īŖ ",
Field = "ī´˛ ",
Variable = "î ",
Class = "ī ",
Interface = "ī°Ž ",
Module = "ī¨ ",
Property = "ī° ",
Unit = "īĩ ",
Value = "īĸ ",
Enum = "īŠ",
Keyword = "ī ",
Snippet = "ī ",
Color = "īŖ ",
File = "ī ",
Reference = "ī ",
Folder = "ī ",
EnumMember = "ī
",
Constant = "ī˛ ",
Struct = "īŗ¤ ",
Event = "ī§ ",
Operator = "ī ",
TypeParameter = "ī ",
},
experimental = {
-- Show current completion as ghost text in line
-- @type boolean
ghost_text = true,
},
completeopt = "menu,menuone,preview,noinsert",
window = {
documentation = {
border = { "â", "â", "âŽ", "â", "â¯", "â", "â°", "â" },
},
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
sources = {
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer" },
},
},
sorting = {
"offset",
"exact",
"score",
"kind",
"sort_text",
"length",
"order",
},
}
Plugins/Packagesâ
Plugins for the doom.features.lsp module.
These plugins will be passed into packer.nvim on startup. You can tweak
the packer options by accessing these values in your config.lua file.
i.e.:
local lsp_packages = doom.features.lsp.packages
lsp_packages['nvim-lspconfig'].commit = '<my_new_commit_sha>'
| Key | Source | Commit | Is Lazy? |
|---|---|---|---|
nvim-lspconfig | neovim/nvim-lspconfig | 01ce5f04384ebe79527284fd177938412 | |
cmp-nvim-lsp | hrsh7th/cmp-nvim-lsp | a5c56b71630f17aa7c38e15c59fd648a8 | |
cmp_luasnip | saadparwaiz1/cmp_luasnip | bcbda508d0a45d28ae366bb3f08db2e36 | |
nvim-cmp | hrsh7th/nvim-cmp | 23abc6c3fe5f3600145d2a413703e7272 | |
cmp-path | hrsh7th/cmp-path | d9c29299a64f968ebb45846c485725f23 | |
lsp_signature.nvim | ray-x/lsp_signature.nvim | 58771db3f086c8d904ff5f80705fd962b | |
cmp-nvim-lua | hrsh7th/cmp-nvim-lua | e7198ab7d00f117e88e223b4bd8c02d21 | |
cmp-buffer | hrsh7th/cmp-buffer | 9166796b644a841a02de8dd1cc1d311fa |
`lsp.binds`()
Keybindsâ
Override these keybinds in your config.lua:
local lsp = doom.features.lsp
lsp.binds = {
{ "<leader>prefix", "<cmd>echo 'my new keybind'<CR>", name = "Description for my new keybind" }
}
| Keymap | Description |
|---|---|
K | Show hover doc |
[d | Jump to prev diagnostic |
]d | Jump to next diagnostic |
gD | Jump to declaration |
gd | Jump to definition |
gr | Jump to references |
gi | Jump to implementation |
ga | Do code action |
<C-p> | Jump to prev diagnostic |
<C-n> | Jump to next diagnostic |
<C-k> | Show signature help |
<leader>cr | Rename |
<leader>ca | Do action |
<leader>ct | Jump to type |
<leader>cD | Jump to declaration |
<leader>cd | Jump to definition |
<leader>cR | Jump to references |
<leader>ci | Jump to implementation |
<leader>cli | Inform |
<leader>clr | Restart |
<leader>cls | Start |
<leader>cld | Disconnect |
<leader>cd[ | Jump to prev |
<leader>cd] | Jump to next |
<leader>cdp | Jump to prev |
<leader>cdn | Jump to next |
<leader>cdL | Line |
<leader>cdl | Loclist |
<leader>tc | Toggle completion |