Properly set omnifunc and tagfunc on attach when applicable (nvim)

main
Ensar Sarajčić 2022-05-24 13:18:16 +02:00
parent de6f4277d2
commit 7ce4148348
1 changed files with 11 additions and 3 deletions

View File

@ -5,10 +5,8 @@
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
local function on_attach(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- Lsp keymaps
local opts = { buffer = bufnr }
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
@ -18,7 +16,17 @@ local function on_attach(client, bufnr)
vim.keymap.set("n", "<A-CR>", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<Leader>ac", vim.lsp.buf.code_action, opts)
if client.resolved_capabilities.document_formatting then
-- Optional config
if client.server_capabilities.completionProvider then
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
end
if client.server_capabilities.definitionProvider then
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, opts)
vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
end
if client.server_capabilities.document_formatting then
local au_id = vim.api.nvim_create_augroup("LspFormatting", { clear = false })
vim.api.nvim_clear_autocmds({ buffer = bufnr, group = au_id })
vim.api.nvim_create_autocmd("BufWritePre", {