Neovim for Minimalists — LSP and Completion
In this article, we will continue to set up LSP and completion for our minimal configuration.
This article is part of the Neovim for Minimalists series.
The Neovim configuration files can be found in this repository.
For the most recent version that uses mason.nvim
, check out the main branch.
LSP Setup
Installation
We will still use the nvim-lspconfig
and nvim-lsp-installer
plugins to configure the LSP servers.
Note: For mason.nvim, check out the main branch.
In the init.lua
file, we add the code to install the plugins.
use({
"neovim/nvim-lspconfig",
event = "BufReadPre",
requires = { "williamboman/nvim-lsp-installer" },
config = function()
require("config.lsp")
end,
})
Configuration
In the lua/lsp.lua
file, we configure the LSP.
- We automate the installation of the language servers (line 176 — line 186).
- We use a Lua table to specify the language servers and their configurations (line 5 — line 28). We only configure Python (
pyright
) and Lua language servers (sumneko_lua
). - In the
on_attach
function (line 145 — line 160), we configure omni completion (:h omnifunc
), completion function (:h completefunc
), format expression (:h formatexpr
), and tag function (:h tagfunc
).
For beginners, check out the Beginners series for more details.
- The
keymappings
function (line 32 — line 49) configures several basic LSP key bindings. - The
highlighting
function (line 51 — line 69) configures the document highlighting feature if it is supported by the language server. - The
formatting
function (line 121 — line 143) set up auto code formatting if it is supported by the…