detect correct formatter
This commit is contained in:
parent
becace1ab8
commit
d86c6ac9f4
3 changed files with 38 additions and 16 deletions
|
@ -57,7 +57,7 @@ M.whichkey = {
|
||||||
l = {
|
l = {
|
||||||
name = "LSP",
|
name = "LSP",
|
||||||
a = { function() vim.lsp.buf.code_action() end, "Code Action" },
|
a = { function() vim.lsp.buf.code_action() end, "Code Action" },
|
||||||
f = { function() vim.lsp.buf.format { async = true } end, "Format" },
|
f = { function() require("funcs").format { async = true } end, "Format" },
|
||||||
j = { function() vim.diagnostic.goto_next() end, "Next Diagnostic" },
|
j = { function() vim.diagnostic.goto_next() end, "Next Diagnostic" },
|
||||||
k = { function() vim.diagnostic.goto_prev() end, "Prev Diagnostic" },
|
k = { function() vim.diagnostic.goto_prev() end, "Prev Diagnostic" },
|
||||||
l = { function() vim.lsp.codelens.run() end, "CodeLens Action" },
|
l = { function() vim.lsp.codelens.run() end, "CodeLens Action" },
|
||||||
|
|
|
@ -22,6 +22,18 @@ function M.lazy_load(tb)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.on_file_open(plugin_name)
|
||||||
|
M.lazy_load {
|
||||||
|
events = { "BufRead", "BufWinEnter", "BufNewFile" },
|
||||||
|
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
|
||||||
|
plugin = plugin_name,
|
||||||
|
condition = function()
|
||||||
|
local file = vim.fn.expand "%"
|
||||||
|
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
function M.gitsigns()
|
function M.gitsigns()
|
||||||
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
||||||
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
|
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
|
||||||
|
@ -37,18 +49,6 @@ function M.gitsigns()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.on_file_open(plugin_name)
|
|
||||||
M.lazy_load {
|
|
||||||
events = { "BufRead", "BufWinEnter", "BufNewFile" },
|
|
||||||
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
|
|
||||||
plugin = plugin_name,
|
|
||||||
condition = function()
|
|
||||||
local file = vim.fn.expand "%"
|
|
||||||
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.bootstrap()
|
function M.bootstrap()
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
|
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
|
||||||
|
@ -100,6 +100,28 @@ function M.map(section)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.format_filter(client)
|
||||||
|
local filetype = vim.bo.filetype
|
||||||
|
local n = require "null-ls"
|
||||||
|
local s = require "null-ls.sources"
|
||||||
|
local method = n.methods.FORMATTING
|
||||||
|
local available_formatters = s.get_available(filetype, method)
|
||||||
|
|
||||||
|
if #available_formatters > 0 then
|
||||||
|
return client.name == "null-ls"
|
||||||
|
elseif client.supports_method "textDocument/formatting" then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.format(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
opts.filter = opts.filter or M.format_filter
|
||||||
|
return vim.lsp.buf.format(opts)
|
||||||
|
end
|
||||||
|
|
||||||
-- Modified version of a function stolen from LunarVim
|
-- Modified version of a function stolen from LunarVim
|
||||||
function M.buf_kill(kill_command, bufnr, force)
|
function M.buf_kill(kill_command, bufnr, force)
|
||||||
kill_command = kill_command or "bd"
|
kill_command = kill_command or "bd"
|
||||||
|
|
|
@ -14,8 +14,8 @@ local diagnostics = null_ls.builtins.diagnostics
|
||||||
null_ls.setup {
|
null_ls.setup {
|
||||||
debug = false,
|
debug = false,
|
||||||
sources = {
|
sources = {
|
||||||
-- formatting.black.with { extra_args = { "--fast" } },
|
formatting.black.with { extra_args = { "--fast" } },
|
||||||
-- formatting.stylua,
|
-- formatting.stylua,
|
||||||
-- diagnostics.flake8,
|
-- diagnostics.flake8,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue