Add null-ls and register as LSP formatter
This commit is contained in:
parent
8df1e359a5
commit
17cdc80a80
|
@ -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.
|
-- Mappings.
|
||||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||||
local opts = { noremap = true, silent = true }
|
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 })
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||||
end
|
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
|
-- Use an on_attach function to only map the following keys
|
||||||
-- after the language server attaches to the current buffer
|
-- after the language server attaches to the current buffer
|
||||||
local on_attach = function(client, bufnr)
|
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>D', vim.lsp.buf.type_definition, bufopts)
|
||||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, 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>ca', vim.lsp.buf.code_action, bufopts)
|
||||||
vim.keymap.set('n', '<leader>i', function()
|
vim.keymap.set('n', '<leader>i', lsp_formatting, bufopts)
|
||||||
vim.lsp.buf.format({ timeout_ms = 10000, async = false })
|
|
||||||
end, bufopts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local lsp_flags = {
|
local lsp_flags = {
|
||||||
|
|
|
@ -41,6 +41,7 @@ require('packer').startup {
|
||||||
'saadparwaiz1/cmp_luasnip',
|
'saadparwaiz1/cmp_luasnip',
|
||||||
'rafamadriz/friendly-snippets',
|
'rafamadriz/friendly-snippets',
|
||||||
'windwp/nvim-autopairs',
|
'windwp/nvim-autopairs',
|
||||||
|
'https://github.com/jose-elias-alvarez/null-ls.nvim',
|
||||||
}
|
}
|
||||||
use {
|
use {
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
|
|
Loading…
Reference in a new issue