diff --git a/symlinks/config/nvim/lua/esensar/init/plugins.lua b/symlinks/config/nvim/lua/esensar/init/plugins.lua index 1703251..8f7852f 100644 --- a/symlinks/config/nvim/lua/esensar/init/plugins.lua +++ b/symlinks/config/nvim/lua/esensar/init/plugins.lua @@ -76,7 +76,6 @@ return require("packer").startup({ use("hrsh7th/cmp-path") -- Path source for nvim-cmp use("hrsh7th/cmp-nvim-lua") -- Nvim-Lua source for nvim-cmp use("hrsh7th/nvim-cmp") -- completion integration - use("nvim-lua/lsp_extensions.nvim") -- LSP extensions (like closing labels for Dart) use("jose-elias-alvarez/null-ls.nvim") -- Linting and formatting -- LSP language specific diff --git a/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua b/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua index ea7aa36..4d6f86c 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/diagnostic.lua @@ -4,6 +4,7 @@ local null_ls = require("null-ls") local custom_sources = require("esensar.lsp.null-ls_sources") +local common_config = require("esensar.lsp.server_config") null_ls.setup({ sources = { @@ -50,16 +51,7 @@ null_ls.setup({ custom_sources.formatters.gdformat, custom_sources.diagnostics.gdlint, }, - on_attach = function(client) - if client.resolved_capabilities.document_formatting then - vim.cmd([[ - augroup LspFormatting - autocmd! * - autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync() - augroup END - ]]) - end - end, + on_attach = common_config.on_attach, }) vim.keymap.set("n", "]w", vim.diagnostic.goto_next) diff --git a/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua b/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua index dc24744..4e66c4e 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/jdtls_setup.lua @@ -9,15 +9,14 @@ function M.setup() require("jdtls").setup_dap() require("jdtls.setup").add_commands() local on_attach = function(client, bufnr) - vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" - common_config.on_attach(client, bufnr) + local opts = { buffer = bufnr } local code_action_fun = function() require("jdtls").code_action() end - vim.keymap.set("n", "", code_action_fun) - vim.keymap.set("n", "ac", code_action_fun) + vim.keymap.set("n", "", code_action_fun, opts) + vim.keymap.set("n", "ac", code_action_fun, opts) end local root_markers = { "gradlew", "pom.xml" } diff --git a/symlinks/config/nvim/lua/esensar/lsp/server_config.lua b/symlinks/config/nvim/lua/esensar/lsp/server_config.lua index 0933a85..b83d076 100644 --- a/symlinks/config/nvim/lua/esensar/lsp/server_config.lua +++ b/symlinks/config/nvim/lua/esensar/lsp/server_config.lua @@ -4,8 +4,8 @@ local M = {} -M.on_attach = function(_, bufnr) - vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" +M.on_attach = function(client, bufnr) + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") -- Lsp keymaps local opts = { buffer = bufnr } @@ -18,6 +18,15 @@ M.on_attach = function(_, bufnr) vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 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 + vim.cmd([[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync() + augroup END + ]]) + end end return M