LSP Zero
The purpose of this plugin is to bundle all the “boilerplate code” necessary to have nvim-cmp (a popular autocompletion plugin) and nvim-lspconfig working together. And if you opt in, it can use mason.nvim to let you install language servers from inside neovim.
If you have any question about a feature or configuration feel free to open a new discussion in this repository. Or join the chat #lsp-zero-nvim:matrix.org.
Announcement
The branch v2.x has been created. You can now test v2 of lsp-zero. The main branch still points to v1.x, but this will probably change by the end of March. So if you are still using the main branch, please change it to v1.x to avoid breaking changes.
This new release of lsp-zero recommends a less opinionated configuration. The aim is to let lsp-zero “extend” lspconfig and nvim-cmp with some defaults, and then let the user interact with each plugin directly if they need further customizations. This will make it easier for everyone to integrate other plugins from the Neovim ecosystem with lsp-zero.
How to get started
If you are new to neovim go to the section Resources for new users.
If you know how to configure neovim go to Quickstart (for the impatient).
Also consider you might not need lsp-zero.
Documentation
Quickstart (for the impatient)
This section assumes you want enable every single feature lsp-zero offers. Optional and required plugins will be marked with a comment.
If you know your way around neovim and how to configure it, take a look at this examples:
Requirements for language servers
I suggest you read the requirements of mason.nvim.
Make sure you have at least the minimum requirements listed in unix systems or windows.
Installing
Use your favorite plugin manager to install this plugin and all its lua dependencies.
With packer.nvim:
use {
'VonHeikemen/lsp-zero.nvim',
branch = 'v1.x',
requires = {
-- LSP Support
{'neovim/nvim-lspconfig'}, -- Required
{'williamboman/mason.nvim'}, -- Optional
{'williamboman/mason-lspconfig.nvim'}, -- Optional
-- Autocompletion
{'hrsh7th/nvim-cmp'}, -- Required
{'hrsh7th/cmp-nvim-lsp'}, -- Required
{'hrsh7th/cmp-buffer'}, -- Optional
{'hrsh7th/cmp-path'}, -- Optional
{'saadparwaiz1/cmp_luasnip'}, -- Optional
{'hrsh7th/cmp-nvim-lua'}, -- Optional
-- Snippets
{'L3MON4D3/LuaSnip'}, -- Required
{'rafamadriz/friendly-snippets'}, -- Optional
}
}
With lazy.nvim:
{
'VonHeikemen/lsp-zero.nvim',
branch = 'v1.x',
dependencies = {
-- LSP Support
{'neovim/nvim-lspconfig'}, -- Required
{'williamboman/mason.nvim'}, -- Optional
{'williamboman/mason-lspconfig.nvim'}, -- Optional
-- Autocompletion
{'hrsh7th/nvim-cmp'}, -- Required
{'hrsh7th/cmp-nvim-lsp'}, -- Required
{'hrsh7th/cmp-buffer'}, -- Optional
{'hrsh7th/cmp-path'}, -- Optional
{'saadparwaiz1/cmp_luasnip'}, -- Optional
{'hrsh7th/cmp-nvim-lua'}, -- Optional
-- Snippets
{'L3MON4D3/LuaSnip'}, -- Required
{'rafamadriz/friendly-snippets'}, -- Optional
}
}
With paq:
{'VonHeikemen/lsp-zero.nvim', branch = 'v1.x'};
-- LSP Support
{'neovim/nvim-lspconfig'}; -- Required
{'williamboman/mason.nvim'}; -- Optional
{'williamboman/mason-lspconfig.nvim'}; -- Optional
-- Autocompletion Engine
{'hrsh7th/nvim-cmp'}; -- Required
{'hrsh7th/cmp-nvim-lsp'}; -- Required
{'hrsh7th/cmp-buffer'}; -- Optional
{'hrsh7th/cmp-path'}; -- Optional
{'saadparwaiz1/cmp_luasnip'}; -- Optional
{'hrsh7th/cmp-nvim-lua'}; -- Optional
-- Snippets
{'L3MON4D3/LuaSnip'}; -- Required
{'rafamadriz/friendly-snippets'}; -- Optional
With vim-plug:
" LSP Support
Plug 'neovim/nvim-lspconfig' " Required
Plug 'williamboman/mason.nvim' " Optional
Plug 'williamboman/mason-lspconfig.nvim' " Optional
" Autocompletion Engine
Plug 'hrsh7th/nvim-cmp' " Required
Plug 'hrsh7th/cmp-nvim-lsp' " Required
Plug 'hrsh7th/cmp-buffer' " Optional
Plug 'hrsh7th/cmp-path' " Optional
Plug 'saadparwaiz1/cmp_luasnip' " Optional
Plug 'hrsh7th/cmp-nvim-lua' " Optional
" Snippets
Plug 'L3MON4D3/LuaSnip' " Required
Plug 'rafamadriz/friendly-snippets' " Optional
Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v1.x'}
Usage
Inside your configuration file add this piece of lua code.
local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = true,
manage_nvim_cmp = true,
suggest_lsp_servers = false,
})
-- (Optional) Configure lua language server for neovim
lsp.nvim_workspace()
lsp.setup()
If you want to install a language server for a particular file type use the command :LspInstall. And when the installation is done restart neovim.
If you don’t want to manage your language servers with mason.nvim then you’ll need to list the LSP servers you want to configure with .setup_servers().
local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = true,
manage_nvim_cmp = true,
suggest_lsp_servers = false,
})
-- When you don't have mason.nvim installed
-- You'll need to list the servers installed in your system
lsp.setup_servers({'tsserver', 'eslint'})
-- (Optional) Configure lua language server for neovim
lsp.nvim_workspace()
lsp.setup()
When using vimscript you can wrap lua code in lua <<EOF ... EOF.
lua <
评论