1
0
Fork 0
dotfiles/.config/nvim/lua/plugins/lsp/null-ls.lua

63 lines
2.1 KiB
Lua
Raw Normal View History

2024-01-02 19:42:41 +01:00
local M = { "nvimtools/none-ls.nvim" }
2024-01-24 00:48:37 +01:00
local f = require("funcs")
M.event = { "BufReadPre", "BufNewFile" }
2024-01-24 00:48:37 +01:00
M.dependencies = { "mason-null-ls.nvim" }
local lsp_maps = function(client, bufnr)
local lsp_mappings = f.empty_map_table()
-- TODO: CONDITIONALLY GATE THIS
lsp_mappings.n["<leader>lf"] = { function() vim.lsp.buf.format() end, desc = "Format" }
lsp_mappings.n["<leader>ld"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }
lsp_mappings.n["[d"] = { function() vim.diagnostic.goto_prev() end, desc = "Previous diagnostic" }
lsp_mappings.n["]d"] = { function() vim.diagnostic.goto_next() end, desc = "Next diagnostic" }
lsp_mappings.n["gl"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }
if f.is_available("telescope.nvim") then
lsp_mappings.n["<leader>lD"] = {
function() require("telescope.builtin").diagnostics() end,
desc = "Search diagnostics",
}
end
if f.is_available "mason-lspconfig.nvim" then
lsp_mappings.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" }
end
if f.is_available "null-ls.nvim" then
lsp_mappings.n["<leader>lI"] = { "<cmd>NullLsInfo<cr>", desc = "Null-ls information" }
end
if client.supports_method "textDocument/codeAction" then
lsp_mappings.n["<leader>la"] = {
function() vim.lsp.buf.code_action() end,
desc = "LSP code action",
}
lsp_mappings.v["<leader>la"] = lsp_mappings.n["<leader>la"]
end
end
M.opts = function()
local nls = require("null-ls")
return {
2024-01-02 19:42:41 +01:00
root_dir = require("null-ls.utils").root_pattern(".null-ls-root", "Makefile", ".git"),
sources = {
2024-01-02 19:42:41 +01:00
-- shell
nls.builtins.formatting.shfmt,
2024-01-02 19:42:41 +01:00
nls.builtins.code_actions.shellcheck,
-- python
nls.builtins.formatting.black,
2024-01-02 19:42:41 +01:00
-- perl
nls.builtins.formatting.perltidy,
-- Various (yaml, markdown, json among others)
nls.builtins.formatting.prettierd,
},
2024-01-24 00:48:37 +01:00
on_attach = lsp_maps
}
end
return M