LspAttach autocmd instead of on_attach fn
This commit is contained in:
parent
5a8f49e2ca
commit
542b72024f
117
init.lua
117
init.lua
|
@ -351,6 +351,12 @@ require'packer'.startup(function(use)
|
|||
use 'vim-airline/vim-airline'
|
||||
use 'vim-airline/vim-airline-themes'
|
||||
use 'romgrk/barbar.nvim'
|
||||
use {'luckasRanarison/clear-action.nvim', config = function()
|
||||
require'clear-action'.setup {
|
||||
signs = { enable = false },
|
||||
popup = { enable = true },
|
||||
}
|
||||
end}
|
||||
use {'MattesGroeger/vim-bookmarks', config = function()
|
||||
vim.g.bookmark_no_default_key_mappings = 1
|
||||
vim.g.bookmark_save_per_working_dir = 1
|
||||
|
@ -923,66 +929,73 @@ capabilities.textDocument.foldingRange = {
|
|||
}
|
||||
|
||||
---- lsp: language servers ----
|
||||
--- Performs keymaps and other setup specific to buffers with LSP enabled
|
||||
--- @param bufnr number
|
||||
--- @diagnostic disable-next-line: unused-local
|
||||
local function on_attach(client, bufnr)
|
||||
require'which-key'.register({
|
||||
['<Leader>l'] = {
|
||||
D = {vim.lsp.buf.declaration, 'Declaration'},
|
||||
d = {'<Cmd>Telescope lsp_definitions<CR>', 'Definition'},
|
||||
i = {'<Cmd>Telescope lsp_implementations<CR>', 'Implementation'},
|
||||
a = {vim.lsp.buf.code_action, 'Code action'},
|
||||
r = {vim.lsp.buf.rename, 'Rename'},
|
||||
h = {function() vim.lsp.inlay_hint(0, nil) end, 'Inlay hints'},
|
||||
l = {vim.lsp.codelens.refresh, 'Show codelenses'},
|
||||
L = {vim.lsp.codelens.run, 'Run codelens'},
|
||||
t = {'<Cmd>Telescope lsp_type_definitions<CR>', 'Type definition'},
|
||||
u = {'<Cmd>Telescope lsp_references<CR>', 'Usages/references'}
|
||||
},
|
||||
g = {
|
||||
d = {vim.lsp.buf.definition, 'Goto definition'},
|
||||
D = {vim.lsp.buf.implementation, 'Goto implementation'},
|
||||
a = {vim.lsp.buf.code_action, 'Code action'},
|
||||
R = {vim.lsp.buf.rename, 'Rename'},
|
||||
y = {vim.lsp.buf.type_definition, 'Type definition'},
|
||||
},
|
||||
[']'] = {
|
||||
g = {vim.diagnostic.goto_next, 'Next diagnostic'},
|
||||
e = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.ERROR } end, 'Next error'},
|
||||
w = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.WARN } end, 'Next warning'},
|
||||
q = {vim.diagnostic.setqflist, 'Quickfix diagnostics'},
|
||||
},
|
||||
['['] = {
|
||||
g = {vim.diagnostic.goto_prev, 'Previous diagnostic'},
|
||||
e = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.ERROR } end, 'Previous error'},
|
||||
w = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.WARN } end, 'Previous warning'},
|
||||
},
|
||||
['<C-h>'] = {vim.lsp.buf.document_highlight, 'Highlight object under cursor'},
|
||||
}, {buffer = bufnr})
|
||||
-- Hover
|
||||
require'which-key'.register({
|
||||
['K'] = {vim.lsp.buf.hover, 'Documentation'},
|
||||
['<C-k>'] = {vim.lsp.buf.signature_help, 'Function signature'},
|
||||
}, {buffer = bufnr})
|
||||
require'which-key'.register({
|
||||
['<M-k>'] = {vim.lsp.buf.signature_help, 'Function signature'}
|
||||
}, {buffer = bufnr, mode = 'i'})
|
||||
au('LspAttach', {
|
||||
callback = function (event)
|
||||
local bufnr = event.buf
|
||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
||||
local function code_action()
|
||||
local ok, clear_action = pcall(require, 'clear-action')
|
||||
if ok then
|
||||
clear_action.code_action()
|
||||
else
|
||||
vim.lsp.buf.code_action()
|
||||
end
|
||||
end
|
||||
require'which-key'.register({
|
||||
['<Leader>l'] = {
|
||||
D = {vim.lsp.buf.declaration, 'Declaration'},
|
||||
d = {'<Cmd>Telescope lsp_definitions<CR>', 'Definition'},
|
||||
i = {'<Cmd>Telescope lsp_implementations<CR>', 'Implementation'},
|
||||
a = {code_action, 'Code action'},
|
||||
r = {vim.lsp.buf.rename, 'Rename'},
|
||||
h = {function() vim.lsp.inlay_hint(0, nil) end, 'Inlay hints'},
|
||||
l = {vim.lsp.codelens.refresh, 'Show codelenses'},
|
||||
L = {vim.lsp.codelens.run, 'Run codelens'},
|
||||
t = {'<Cmd>Telescope lsp_type_definitions<CR>', 'Type definition'},
|
||||
u = {'<Cmd>Telescope lsp_references<CR>', 'Usages/references'}
|
||||
},
|
||||
g = {
|
||||
d = {vim.lsp.buf.definition, 'Goto definition'},
|
||||
D = {vim.lsp.buf.implementation, 'Goto implementation'},
|
||||
a = {code_action, 'Code action'},
|
||||
R = {vim.lsp.buf.rename, 'Rename'},
|
||||
y = {vim.lsp.buf.type_definition, 'Type definition'},
|
||||
},
|
||||
[']'] = {
|
||||
g = {vim.diagnostic.goto_next, 'Next diagnostic'},
|
||||
e = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.ERROR } end, 'Next error'},
|
||||
w = {function() vim.diagnostic.goto_next { severity = vim.diagnostic.severity.WARN } end, 'Next warning'},
|
||||
q = {vim.diagnostic.setqflist, 'Quickfix diagnostics'},
|
||||
},
|
||||
['['] = {
|
||||
g = {vim.diagnostic.goto_prev, 'Previous diagnostic'},
|
||||
e = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.ERROR } end, 'Previous error'},
|
||||
w = {function() vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.WARN } end, 'Previous warning'},
|
||||
},
|
||||
['<C-h>'] = {vim.lsp.buf.document_highlight, 'Highlight object under cursor'},
|
||||
}, {buffer = bufnr})
|
||||
-- Hover
|
||||
require'which-key'.register({
|
||||
['K'] = {vim.lsp.buf.hover, 'Documentation'},
|
||||
['<C-k>'] = {vim.lsp.buf.signature_help, 'Function signature'},
|
||||
}, {buffer = bufnr})
|
||||
require'which-key'.register({
|
||||
['<M-k>'] = {vim.lsp.buf.signature_help, 'Function signature'}
|
||||
}, {buffer = bufnr, mode = 'i'})
|
||||
|
||||
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||||
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||||
|
||||
require'nvim-navic'.attach(client, bufnr)
|
||||
end
|
||||
require'nvim-navic'.attach(client, bufnr)
|
||||
end
|
||||
})
|
||||
|
||||
-- Enable language servers
|
||||
local default = {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
}
|
||||
|
||||
require'lspconfig'.lua_ls.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
|
@ -1054,7 +1067,6 @@ au('FileType', {
|
|||
capabilities = capabilities,
|
||||
|
||||
on_attach = function (client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
jdtls.setup_dap()
|
||||
end,
|
||||
}
|
||||
|
@ -1071,7 +1083,6 @@ au('FileType', {
|
|||
require'lspconfig'.sqls.setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = function (client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
local ok, sqls = pcall(require, 'sqls')
|
||||
if not ok then return end
|
||||
sqls.on_attach(client, bufnr)
|
||||
|
@ -1123,7 +1134,6 @@ require'rust-tools'.setup {
|
|||
-- Enable standalone file (i.e. no cargo) support
|
||||
standalone = true,
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
['rust-analyzer'] = {
|
||||
cargo = {
|
||||
|
@ -1267,7 +1277,6 @@ vim.keymap.set('n', '<Leader>t', '<Cmd>NvimTreeFindFile<CR>', {desc = 'Nvim Tree
|
|||
|
||||
|
||||
---- treesitter ----
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
-- Configure the nvim-ts-autotag plugin
|
||||
autotag = {
|
||||
|
|
Loading…
Reference in a new issue