-
Notifications
You must be signed in to change notification settings - Fork 0
III. LSP
LSP is quite a bit more complicated than TreeSitter. We've got quite a bit of plugins this time around, add all of these (!):
" LSP Support
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v1.x'}
Plug 'L3MON4D3/LuaSnip'
Plug 'rafamadriz/friendly-snippets'
" Autocompletion Engine
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'hrsh7th/cmp-nvim-lua'
Full configuration so far
call plug#begin() " Put all your `Plug <x>/<y>` statements here! " Let's add Mason for LSP Plug 'williamboman/mason.nvim' " and TreeSitter for highlighting Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}" LSP Support Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason-lspconfig.nvim' Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v1.x'} " Snippets/examples for LSP Plug 'L3MON4D3/LuaSnip'
Plug 'rafamadriz/friendly-snippets' " Autocompletion Engine Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-path' Plug 'saadparwaiz1/cmp_luasnip' Plug 'hrsh7th/cmp-nvim-lua' call plug#end() " Put all yourlua require('<xyz>')
statements here! Make sure to include the following too: lua require('init')
Then, run :PlugInstall
as per usual to install all of these.
Now, there's a lot to add. Most of this is ripped straight from ThePrimeagen's lsp.lua
file, but who cares, really?
Anyways, just append the following to init.lua
:
local lsp = require('lsp-zero')
lsp.preset('recommended')
lsp.configure('lua-language-server', {
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
}
})
lsp.nvim_workspace()
lsp.setup()
Optionally, if you want error messages displayed inline while you write code, add:
vim.diagnostic.config({
update_in_insert = true,
virtual_text = true
})
after the aforementioned block.
Full `init.lua` config (with inline errors)
require("mason").setup() local lsp = require('lsp-zero')* COPY AND PASTING THE ABOVE CODE PROBABLY WON'T WORK! REPLACE THE SPACES WITH TABS! (It has to do with how I formatted each tab with 4lsp.preset('recommended')
lsp.configure('lua-language-server', { settings = { Lua = { diagnostics = { globals = { 'vim' } } } } })
lsp.nvim_workspace()
lsp.setup()
vim.diagnostic.config({ update_in_insert = true, virtual_text = true })
emsp
s (which is disgustingly jank) but whatever)
Alright, LSP should be set up now.
All we gotta do is run :Mason
in Neovim and install whatever LSP servers you want (with the i
keybind, or X
to uninstall).