Add null-ls and register as LSP formatter

This commit is contained in:
Evie Litherland-Smith 2023-01-31 14:41:46 +00:00
parent 8df1e359a5
commit 17cdc80a80
2 changed files with 27 additions and 3 deletions

View file

@ -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', '<leader>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', '<leader>i', function()
vim.lsp.buf.format({ timeout_ms = 10000, async = false })
end, bufopts)
vim.keymap.set('n', '<leader>i', lsp_formatting, bufopts)
end
local lsp_flags = {

View file

@ -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',