diff --git a/config/nvim/lua/config_plugins/config_lsp.lua b/config/nvim/lua/config_plugins/config_lsp.lua index ccfb58c7..98e3dc70 100644 --- a/config/nvim/lua/config_plugins/config_lsp.lua +++ b/config/nvim/lua/config_plugins/config_lsp.lua @@ -1,3 +1,17 @@ +-- Set up null_ls first +local null_ls = require("null-ls") +null_ls.setup { + sources = { + null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.diagnostics.mypy, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, + null_ls.builtins.formatting.latexindent, + null_ls.builtins.formatting.trim_whitespace, + null_ls.builtins.hover.dictionary, + }, +} + -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions local opts = { noremap = true, silent = true } @@ -12,6 +26,17 @@ for type, icon in pairs(signs) do vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end +local lsp_formatting = function (bufnr) + vim.lsp.buf.format({ + filter = function (client) + return client.name == "null-ls" + end, + bufnr = bufnr, + timeout_ms = 2000, + -- async = true, + }) +end + -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) @@ -34,9 +59,7 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', 'i', function() - vim.lsp.buf.format({ timeout_ms = 10000, async = false }) - end, bufopts) + vim.keymap.set('n', 'i', lsp_formatting, bufopts) end local lsp_flags = { diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index 77987e70..7631e14c 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -41,6 +41,7 @@ require('packer').startup { 'saadparwaiz1/cmp_luasnip', 'rafamadriz/friendly-snippets', 'windwp/nvim-autopairs', + 'https://github.com/jose-elias-alvarez/null-ls.nvim', } use { 'nvim-treesitter/nvim-treesitter',