From 150a9b36d87bcb771138e1117f6be2ce4844015b Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Sun, 2 Jan 2022 22:13:15 -0800 Subject: [PATCH] Add pre 0.6 support for null-ls --- neovim/lua/plugins.lua | 7 ++-- neovim/lua/plugins/lsp.lua | 70 ++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index b8b920c..5c4c5b9 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -16,15 +16,17 @@ local function config_dark_notify() }) end --- Pin version dependent packages +-- Pin version dependent packages due to unstable APIs local pinned_commits = {} if vim.fn.has("nvim-0.6.0") ~= 1 then if vim.fn.has("nvim-0.5.1") == 1 then -- Last commit compatible with 0.5.1 pinned_commits["telescope"] = "80cdb00b221f69348afc4fb4b701f51eb8dd3120" + pinned_commits["null-ls"] = "739a98c12bedaa2430c4a3c08d1d22ad6c16513e" elseif vim.fn.has("nvim-0.5.0") == 1 then - -- Last commit compatible with 0.5.1 + -- Last commit compatible with 0.5.0 pinned_commits["telescope"] = "587a10d1494d8ffa1229246228f0655db2f0a48a" + pinned_commits["null-ls"] = "3e7390735501d0507bf2c2b5c2e7a16f58deeb81" end end @@ -201,6 +203,7 @@ return require("packer").startup({ -- Generic linter/formatters in diagnostics API use({ "jose-elias-alvarez/null-ls.nvim", + commit = pinned_commits["null-ls"], requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, }) diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index 2117e02..dcd8692 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -176,35 +176,47 @@ end function M.config_null_ls() utils.try_require("null-ls", function(null_ls) - null_ls.setup({ - on_attach = default_attach, - capabilities = merged_capabilities(), - sources = { - -- Generic - -- null_ls.builtins.formatting.preittier, - -- null_ls.builtins.formatting.trim_whitespace, - -- null_ls.builtins.formatting.trim_newlines, - -- Fish - -- null_ls.builtins.formatting.fish_indent, - -- Python - null_ls.builtins.formatting.reorder_python_imports, - null_ls.builtins.formatting.black, - null_ls.builtins.diagnostics.mypy, - -- Go - null_ls.builtins.diagnostics.golangci_lint, - -- Text - -- null_ls.builtins.code_actions.proselint, - -- Ansible - -- null_ls.builtins.diagnostics.ansiblelint, - -- Shell - null_ls.builtins.diagnostics.shellcheck, - -- Rust - -- null_ls.builtins.formatting.rustfmt, - -- Lua - null_ls.builtins.diagnostics.luacheck, - null_ls.builtins.formatting.stylua, - }, - }) + local sources = { + -- Generic + -- null_ls.builtins.formatting.preittier, + -- null_ls.builtins.formatting.trim_whitespace, + -- null_ls.builtins.formatting.trim_newlines, + -- Fish + -- null_ls.builtins.formatting.fish_indent, + -- Python + null_ls.builtins.formatting.reorder_python_imports, + null_ls.builtins.formatting.black, + null_ls.builtins.diagnostics.mypy, + -- Go + null_ls.builtins.diagnostics.golangci_lint, + -- Text + -- null_ls.builtins.code_actions.proselint, + -- Ansible + -- null_ls.builtins.diagnostics.ansiblelint, + -- Shell + null_ls.builtins.diagnostics.shellcheck, + -- Rust + -- null_ls.builtins.formatting.rustfmt, + -- Lua + null_ls.builtins.diagnostics.luacheck, + null_ls.builtins.formatting.stylua, + } + + -- HACK: Handle old versions of null_ls for vim < 0.6 that don't support `setup` + if null_ls["setup"] ~= nil then + null_ls.setup({ + on_attach = default_attach, + capabilities = merged_capabilities(), + sources = sources, + }) + else + null_ls.config({ + sources = sources, + }) + require("lspconfig")["null-ls"].setup({ + on_attach = default_attach, + }) + end end) end