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('nvim_opts') -- Basic vim options
require('autocmd') -- Convenient Autocommands require('autocmd') -- Convenient Autocommands
require('lsp') require('lsp')
require('keybindings')
require('nvim-cmp-cfg')
require('ts_config') 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 -- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer -- after the language server attaches to the current buffer
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local opts = { buffer = bufnr, remap = false }
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, opts)
-- Enable completion triggered by <c-x><c-o> vim.keymap.set('n', '<leader>k', function() vim.lsp.buf.hover() end, opts)
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') 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)
-- Mappings. vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() end, opts)
local opts = { noremap=true, silent=true } 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)
map('n', 'gD', function() vim.lsp.buf.declaration() end, options) vim.keymap.set('n', '<leader>Q', function() vim.diagnostic.set_qflist() end, opts)
map('n', 'gd', function() vim.lsp.buf.definition() end, options) vim.keymap.set('n', '<leader>F', function() vim.lsp.buf.format() end, opts)
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)
end end
-- Code actions local cmp_mappings = function ()
-- TODO: Generalize to LSP or only attach on Rust buffers local cmp = require('cmp')
map('n', '<leader>t', '<cmd>RustTest<CR>', options) -- Run test under cursor 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 local lsp = require('lsp-zero').preset({
-- Add additional capabilities supported by nvim-cmp name = 'minimal',
local capabilities = vim.lsp.protocol.make_client_capabilities() set_lsp_keymaps = false,
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) manage_nvim_cmp = false,
suggest_lsp_servers = false,
local lspconfig = require('lspconfig') })
-- SERVERS local keybindings = require('keybindings')
-- rust_analyzer local on_attach = keybindings.on_attach
vim.g.rustfmt_autosave = 1 local cmp_mapping = keybindings.cmp_mappings
lspconfig.rust_analyzer.setup{
on_attach = on_attach, lsp.on_attach(on_attach)
capabilities = capabilities,
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 = { settings = {
["rust-analyzer"] = { ["rust-analyzer"] = {
cargo = {
features = "all",
},
procMacro = { procMacro = {
enable = true, enable = true,
}, },
@ -20,17 +42,18 @@ lspconfig.rust_analyzer.setup{
command = 'clippy', command = 'clippy',
extraArgs = { "--", "-W", "clippy::pedantic" } extraArgs = { "--", "-W", "clippy::pedantic" }
}, },
},
} }
} })
}
lspconfig.gopls.setup { lsp.configure('tsserver', {
on_attach = on_attach, cmd = { "npx", "typescript-language-server", "--stdio" },
capabilities=capabilities, })
}
-- clangd lsp.configure('html', {
lspconfig.clangd.setup{ cmd = { "npx", "vscode-html-language-server", "--stdio" },
on_attach = on_attach, })
capabilities = capabilities,
} 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 g = vim.g -- global 2?
local wo = vim.wo -- window local local wo = vim.wo -- window local
local bo = vim.bo -- buffer local local bo = vim.bo -- buffer local
@ -43,3 +43,5 @@ o.dir = '/tmp'
-- Buffers -- Buffers
o.hidden = true -- Allow hidden buffers without saving 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 -- git
use 'tpope/vim-fugitive' 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 { use {
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate' run = ':TSUpdate'
} }
-- Language Specfic -- lsp
use 'rust-lang/rust.vim' use {
use 'https://git.sr.ht/~sircmpwn/hare.vim' '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 if packer_bootstrap then
require('packer').sync() require('packer').sync()

Loading…
Cancel
Save