Add lsp-zero and mason
This commit is contained in:
69
init.lua
69
init.lua
@@ -73,47 +73,11 @@ vim.opt.undofile = true
|
|||||||
-- Reserve a space in the gutter
|
-- Reserve a space in the gutter
|
||||||
vim.opt.signcolumn = 'yes'
|
vim.opt.signcolumn = 'yes'
|
||||||
|
|
||||||
-- Install Mason
|
-- Reserve a space in the gutter
|
||||||
require("mason").setup()
|
vim.opt.signcolumn = 'yes'
|
||||||
|
|
||||||
-- Add cmp_nvim_lsp capabilities settings to lspconfig
|
|
||||||
-- This should be executed before you configure any language server
|
|
||||||
local lspconfig_defaults = require('lspconfig').util.default_config
|
|
||||||
lspconfig_defaults.capabilities = vim.tbl_deep_extend(
|
|
||||||
'force',
|
|
||||||
lspconfig_defaults.capabilities,
|
|
||||||
require('cmp_nvim_lsp').default_capabilities()
|
|
||||||
)
|
|
||||||
|
|
||||||
-- This is where you enable features that only work
|
|
||||||
-- if there is a language server active in the file
|
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
|
||||||
desc = 'LSP actions',
|
|
||||||
callback = function(event)
|
|
||||||
local opts = {buffer = event.buf}
|
|
||||||
|
|
||||||
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
|
|
||||||
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
|
|
||||||
vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
|
|
||||||
vim.keymap.set({'n', 'x'}, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
|
|
||||||
vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- You'll find a list of language servers here:
|
|
||||||
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
|
|
||||||
-- These are example language servers.
|
|
||||||
require('lspconfig').gleam.setup({})
|
|
||||||
require('lspconfig').ocamllsp.setup({})
|
|
||||||
-- NOTE: to make any of this work you need a language server.
|
|
||||||
-- If you don't know what that is, watch this 5 min video:
|
|
||||||
-- https://www.youtube.com/watch?v=LaS32vctfOY
|
|
||||||
|
|
||||||
|
-- lsp-zero
|
||||||
local cmp = require('cmp')
|
local cmp = require('cmp')
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
@@ -128,32 +92,7 @@ cmp.setup({
|
|||||||
},
|
},
|
||||||
mapping = cmp.mapping.preset.insert({}),
|
mapping = cmp.mapping.preset.insert({}),
|
||||||
})
|
})
|
||||||
|
-- lsp-zero end
|
||||||
vim.api.nvim_create_autocmd("Filetype", {
|
|
||||||
pattern = { "html", "shtml", "htm" },
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.start({
|
|
||||||
name = "superhtml",
|
|
||||||
cmd = { "superhtml", "lsp" },
|
|
||||||
root_dir = vim.fs.dirname(vim.fs.find({".git"}, { upward = true })[1])
|
|
||||||
})
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
require'lspconfig'.terraformls.setup({})
|
|
||||||
|
|
||||||
require'lspconfig'.pylsp.setup{
|
|
||||||
settings = {
|
|
||||||
pylsp = {
|
|
||||||
plugins = {
|
|
||||||
pycodestyle = {
|
|
||||||
ignore = {'W391'},
|
|
||||||
maxLineLength = 120
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- move paragraphs
|
-- move paragraphs
|
||||||
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
|
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
|
||||||
|
|||||||
91
lua/plugins/lsp-zero.lua
Normal file
91
lua/plugins/lsp-zero.lua
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
return {
|
||||||
|
{
|
||||||
|
'williamboman/mason.nvim',
|
||||||
|
lazy = false,
|
||||||
|
opts = {},
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Autocompletion
|
||||||
|
{
|
||||||
|
'hrsh7th/nvim-cmp',
|
||||||
|
event = 'InsertEnter',
|
||||||
|
config = function()
|
||||||
|
local cmp = require('cmp')
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
sources = {
|
||||||
|
{name = 'nvim_lsp'},
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
['<C-y>'] = cmp.mapping.complete(),
|
||||||
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
||||||
|
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
||||||
|
}),
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
vim.snippet.expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
|
-- LSP
|
||||||
|
{
|
||||||
|
'neovim/nvim-lspconfig',
|
||||||
|
cmd = {'LspInfo', 'LspInstall', 'LspStart'},
|
||||||
|
event = {'BufReadPre', 'BufNewFile'},
|
||||||
|
dependencies = {
|
||||||
|
{'hrsh7th/cmp-nvim-lsp'},
|
||||||
|
{'williamboman/mason.nvim'},
|
||||||
|
{'williamboman/mason-lspconfig.nvim'},
|
||||||
|
},
|
||||||
|
init = function()
|
||||||
|
-- Reserve a space in the gutter
|
||||||
|
-- This will avoid an annoying layout shift in the screen
|
||||||
|
vim.opt.signcolumn = 'yes'
|
||||||
|
end,
|
||||||
|
config = function()
|
||||||
|
local lsp_defaults = require('lspconfig').util.default_config
|
||||||
|
|
||||||
|
-- Add cmp_nvim_lsp capabilities settings to lspconfig
|
||||||
|
-- This should be executed before you configure any language server
|
||||||
|
lsp_defaults.capabilities = vim.tbl_deep_extend(
|
||||||
|
'force',
|
||||||
|
lsp_defaults.capabilities,
|
||||||
|
require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
)
|
||||||
|
|
||||||
|
-- LspAttach is where you enable features that only work
|
||||||
|
-- if there is a language server active in the file
|
||||||
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
|
desc = 'LSP actions',
|
||||||
|
callback = function(event)
|
||||||
|
local opts = {buffer = event.buf}
|
||||||
|
|
||||||
|
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
|
||||||
|
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
|
||||||
|
vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
|
||||||
|
vim.keymap.set({'n', 'x'}, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
|
||||||
|
vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
require('mason-lspconfig').setup({
|
||||||
|
ensure_installed = {},
|
||||||
|
handlers = {
|
||||||
|
-- this first function is the "default handler"
|
||||||
|
-- it applies to every language server without a "custom handler"
|
||||||
|
function(server_name)
|
||||||
|
require('lspconfig')[server_name].setup({})
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
return {
|
|
||||||
{
|
|
||||||
"williamboman/mason.nvim",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user