add BufWritePost event
This commit is contained in:
@@ -1,131 +1,131 @@
|
|||||||
return {
|
return {
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
event = { 'BufReadPost', 'BufNewFile' },
|
event = { 'BufReadPost', 'BufWritePost', 'BufNewFile' },
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'williamboman/mason.nvim',
|
'williamboman/mason.nvim',
|
||||||
'williamboman/mason-lspconfig.nvim',
|
'williamboman/mason-lspconfig.nvim',
|
||||||
'hrsh7th/cmp-nvim-lsp',
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
{ 'antosha417/nvim-lsp-file-operations', config = true },
|
{ 'antosha417/nvim-lsp-file-operations', config = true },
|
||||||
{ 'folke/neodev.nvim', config = true },
|
{ 'folke/neodev.nvim', config = true },
|
||||||
},
|
},
|
||||||
|
|
||||||
config = function()
|
config = function()
|
||||||
local lspconfig = require('lspconfig')
|
local lspconfig = require('lspconfig')
|
||||||
local mason_lspconfig = require('mason-lspconfig')
|
local mason_lspconfig = require('mason-lspconfig')
|
||||||
local cmp_nvim_lsp = require('cmp_nvim_lsp')
|
local cmp_nvim_lsp = require('cmp_nvim_lsp')
|
||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
local opts = { buffer = ev.buf, silent = true }
|
local opts = { buffer = ev.buf, silent = true }
|
||||||
|
|
||||||
opts.desc = 'Show LSP references'
|
opts.desc = 'Show LSP references'
|
||||||
keymap.set('n', 'gR', '<cmd>Telescope lsp_references<CR>', opts)
|
keymap.set('n', 'gR', '<cmd>Telescope lsp_references<CR>', opts)
|
||||||
|
|
||||||
opts.desc = 'Go to declaration'
|
opts.desc = 'Go to declaration'
|
||||||
keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
||||||
|
|
||||||
opts.desc = 'Show LSP definitions'
|
opts.desc = 'Show LSP definitions'
|
||||||
keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
|
keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
|
||||||
|
|
||||||
opts.desc = 'Show LSP implementations'
|
opts.desc = 'Show LSP implementations'
|
||||||
keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
|
keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
|
||||||
|
|
||||||
opts.desc = 'Show LSP type definitions'
|
opts.desc = 'Show LSP type definitions'
|
||||||
keymap.set('n', 'gt', '<cmd>Telescope lsp_type_definitions<CR>', opts)
|
keymap.set('n', 'gt', '<cmd>Telescope lsp_type_definitions<CR>', opts)
|
||||||
|
|
||||||
opts.desc = 'See available code actions'
|
opts.desc = 'See available code actions'
|
||||||
keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts)
|
keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts)
|
||||||
|
|
||||||
opts.desc = 'Smart rename'
|
opts.desc = 'Smart rename'
|
||||||
keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||||
|
|
||||||
opts.desc = 'Show buffer diagnostics'
|
opts.desc = 'Show buffer diagnostics'
|
||||||
keymap.set('n', '<leader>D', '<cmd>Telescope diagnostics bufnf=0<CR>', opts)
|
keymap.set('n', '<leader>D', '<cmd>Telescope diagnostics bufnf=0<CR>', opts)
|
||||||
|
|
||||||
opts.desc = 'Show line diagnostics'
|
opts.desc = 'Show line diagnostics'
|
||||||
keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts)
|
keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts)
|
||||||
|
|
||||||
opts.desc = 'Go to previous diagnostic'
|
opts.desc = 'Go to previous diagnostic'
|
||||||
keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
||||||
|
|
||||||
opts.desc = 'Go to next diagnostic'
|
opts.desc = 'Go to next diagnostic'
|
||||||
keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
||||||
|
|
||||||
opts.desc = 'Show documentation for what is under cursor'
|
opts.desc = 'Show documentation for what is under cursor'
|
||||||
keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
||||||
|
|
||||||
opts.desc = 'Restart LSP'
|
opts.desc = 'Restart LSP'
|
||||||
keymap.set('n', '<leader>rs', ':LspRestart<CR>', opts)
|
keymap.set('n', '<leader>rs', ':LspRestart<CR>', opts)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||||
|
|
||||||
local signs = { Error = ' ', Warn = ' ', Hint = ' ', Info = ' ' }
|
local signs = { Error = ' ', Warn = ' ', Hint = ' ', Info = ' ' }
|
||||||
for type, icon in pairs(signs) do
|
for type, icon in pairs(signs) do
|
||||||
local hl = 'DiagnosticSign' .. type
|
local hl = 'DiagnosticSign' .. type
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
|
||||||
end
|
end
|
||||||
|
|
||||||
mason_lspconfig.setup_handlers({
|
mason_lspconfig.setup_handlers({
|
||||||
-- default handler for installed servers
|
-- default handler for installed servers
|
||||||
function(server_name)
|
function(server_name)
|
||||||
lspconfig[server_name].setup({
|
lspconfig[server_name].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
['emmet_ls'] = function()
|
['emmet_ls'] = function()
|
||||||
-- configure emmet language server
|
-- configure emmet language server
|
||||||
lspconfig['emmet_ls'].setup({
|
lspconfig['emmet_ls'].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less', 'svelte' },
|
filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less', 'svelte' },
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
['bashls'] = function()
|
['bashls'] = function()
|
||||||
lspconfig['bashls'].setup({
|
lspconfig['bashls'].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
filetypes = { 'sh', 'bash', 'zsh' },
|
filetypes = { 'sh', 'bash', 'zsh' },
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
['lua_ls'] = function()
|
['lua_ls'] = function()
|
||||||
-- configure lua server (with special settings)
|
-- configure lua server (with special settings)
|
||||||
lspconfig['lua_ls'].setup({
|
lspconfig['lua_ls'].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
-- make the language server recognize "vim" global
|
-- make the language server recognize "vim" global
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
globals = { 'vim' },
|
globals = { 'vim' },
|
||||||
},
|
},
|
||||||
completion = {
|
completion = {
|
||||||
callSnippet = 'Replace',
|
callSnippet = 'Replace',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
prefix = '●',
|
prefix = '●',
|
||||||
},
|
},
|
||||||
signs = {
|
signs = {
|
||||||
active = signs,
|
active = signs,
|
||||||
},
|
},
|
||||||
update_in_insert = true,
|
update_in_insert = true,
|
||||||
underline = true,
|
underline = true,
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
float = {
|
float = {
|
||||||
focusable = false,
|
focusable = false,
|
||||||
style = 'minimal',
|
style = 'minimal',
|
||||||
border = 'rounded',
|
border = 'rounded',
|
||||||
source = true,
|
source = true,
|
||||||
show_header = true,
|
show_header = true,
|
||||||
prefix = '',
|
prefix = '',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user