switch to lsp-zero

writing
Nick Zana 2 years ago
parent fc59aa483e
commit 5c190777dc

@ -2,6 +2,4 @@ require('plugins') -- Setup packer.nvim and install plugins
require('nvim_opts') -- Basic vim options
require('autocmd') -- Convenient Autocommands
require('lsp')
require('keybindings')
require('nvim-cmp-cfg')
require('ts_config')

@ -52,33 +52,33 @@ map('n', '<leader>gl', '<cmd>diffget //3<CR>', options) -- merge from right pane
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
map('n', 'gD', function() vim.lsp.buf.declaration() end, options)
map('n', 'gd', function() vim.lsp.buf.definition() end, options)
map('n', '<leader>k', function() vim.lsp.buf.hover() end, options)
map('n', '<leader>s', function() vim.lsp.buf.signature_help() end, options)
map('n', '<leader>r', function() vim.lsp.buf.rename() end, options)
map('n', '<leader>a', function() vim.lsp.buf.code_action() end, options)
map('n', 'gr', function() vim.lsp.buf.references() end, options)
map('n', '<leader>d', function() vim.diagnostic.open_float() end, options)
map('n', '[d', function() vim.diagnostic.goto_prev() end, options)
map('n', ']d', function() vim.diagnostic.goto_next() end, options)
map('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, options)
map('n', '<leader>F', function() vim.lsp.buf.format() end, options)
local opts = { buffer = bufnr, remap = false }
vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts)
vim.keymap.set('n', '<leader>k', function() vim.lsp.buf.hover() end, opts)
vim.keymap.set('n', '<leader>r', function() vim.lsp.buf.rename() end, opts)
vim.keymap.set('n', '<leader>a', function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts)
vim.keymap.set('n', '<leader>d', function() vim.diagnostic.open_float() end, opts)
vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, opts)
vim.keymap.set('n', '<leader>F', function() vim.lsp.buf.format() end, opts)
end
-- Code actions
-- TODO: Generalize to LSP or only attach on Rust buffers
map('n', '<leader>t', '<cmd>RustTest<CR>', options) -- Run test under cursor
local cmp_mappings = function ()
local cmp = require('cmp')
return {
['<C-j>'] = cmp.mapping.scroll_docs(4),
['<C-k>'] = cmp.mapping.scroll_docs(-4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
}
end
return { on_attach = on_attach }
return { on_attach = on_attach, cmp_mappings = cmp_mappings }

@ -1,18 +1,40 @@
local on_attach = require'keybindings'.on_attach
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- SERVERS
-- rust_analyzer
vim.g.rustfmt_autosave = 1
lspconfig.rust_analyzer.setup{
on_attach = on_attach,
capabilities = capabilities,
local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = false,
manage_nvim_cmp = false,
suggest_lsp_servers = false,
})
local keybindings = require('keybindings')
local on_attach = keybindings.on_attach
local cmp_mapping = keybindings.cmp_mappings
lsp.on_attach(on_attach)
local cmp = require('cmp')
local cmp_config = lsp.defaults.cmp_config({
preselect = 'none',
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert(cmp_mappings),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
})
cmp.setup(cmp_config)
-- Configure lua language server for neovim
lsp.nvim_workspace()
lsp.configure('rust_analyzer', {
settings = {
["rust-analyzer"] = {
cargo = {
features = "all",
},
procMacro = {
enable = true,
},
@ -20,17 +42,18 @@ lspconfig.rust_analyzer.setup{
command = 'clippy',
extraArgs = { "--", "-W", "clippy::pedantic" }
},
}
},
}
}
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities=capabilities,
}
-- clangd
lspconfig.clangd.setup{
on_attach = on_attach,
capabilities = capabilities,
}
})
lsp.configure('tsserver', {
cmd = { "npx", "typescript-language-server", "--stdio" },
})
lsp.configure('html', {
cmd = { "npx", "vscode-html-language-server", "--stdio" },
})
lsp.setup_servers({'tsserver', 'rust_analyzer', 'html'})
lsp.setup()

@ -1,4 +1,4 @@
local o = vim.o -- global
local o = vim.o -- globalopts
local g = vim.g -- global 2?
local wo = vim.wo -- window local
local bo = vim.bo -- buffer local
@ -43,3 +43,5 @@ o.dir = '/tmp'
-- Buffers
o.hidden = true -- Allow hidden buffers without saving
vim.opt.completeopt = {'menu','menuone','noselect'}

@ -17,31 +17,28 @@ local plugins = require('packer').startup(function(use)
-- git
use 'tpope/vim-fugitive'
-- LSP
use 'neovim/nvim-lspconfig' -- Common lsp server configurations
use {
'hrsh7th/nvim-cmp',
} -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp
-- LSP Extensions
use 'nvim-lua/lsp_extensions.nvim'
-- Snippets (required for nvim-cmp)
use 'L3MON4D3/LuaSnip'
use {
'saadparwaiz1/cmp_luasnip',
commit = 'b10829736542e7cc9291e60bab134df1273165c9',
}
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
-- Language Specfic
use 'rust-lang/rust.vim'
use 'https://git.sr.ht/~sircmpwn/hare.vim'
-- lsp
use {
'VonHeikemen/lsp-zero.nvim',
branch = 'v1.x',
requires = {
-- LSP Support
{'neovim/nvim-lspconfig'},
-- Autocompletion
{'hrsh7th/nvim-cmp'},
{'hrsh7th/cmp-nvim-lsp'},
{'hrsh7th/cmp-buffer'}, -- Optional
-- Snippets
{'L3MON4D3/LuaSnip'},
},
}
if packer_bootstrap then
require('packer').sync()

Loading…
Cancel
Save