From 7ce4148348b0dbe230ff0297b8c466d83874543f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Tue, 24 May 2022 13:18:16 +0200 Subject: [PATCH] Properly set omnifunc and tagfunc on attach when applicable (nvim) --- .../config/nvim/lua/esensar/lsp/server_config.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/symlinks/config/nvim/lua/esensar/lsp/server_config.lua b/symlinks/config/nvim/lua/esensar/lsp/server_config.lua index dc868a3..1240f42 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/server_config.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/server_config.lua @@ -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", "", 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", "", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "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", "", 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", {