formater
This commit is contained in:
90
vim/.vim/lua/plugins/formatter.lua
Normal file
90
vim/.vim/lua/plugins/formatter.lua
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
return {
|
||||||
|
"mhartington/formatter.nvim",
|
||||||
|
config = function()
|
||||||
|
-- Utilities for creating configurations
|
||||||
|
local util = require("formatter.util")
|
||||||
|
|
||||||
|
-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
|
||||||
|
require("formatter").setup({
|
||||||
|
-- Enable or disable logging
|
||||||
|
logging = true,
|
||||||
|
-- Set the log level
|
||||||
|
log_level = vim.log.levels.WARN,
|
||||||
|
-- All formatter configurations are opt-in
|
||||||
|
filetype = {
|
||||||
|
-- Formatter configurations for filetype "lua" go here
|
||||||
|
-- and will be executed in order
|
||||||
|
lua = {
|
||||||
|
-- "formatter.filetypes.lua" defines default configurations for the
|
||||||
|
-- "lua" filetype
|
||||||
|
-- require("formatter.filetypes.lua").stylua,
|
||||||
|
-- You can also define your own configuration
|
||||||
|
function()
|
||||||
|
-- Supports conditional formatting
|
||||||
|
if util.get_current_buffer_file_name() == "special.lua" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Full specification of configurations is down below and in Vim help
|
||||||
|
-- files
|
||||||
|
return {
|
||||||
|
exe = "stylua",
|
||||||
|
args = {
|
||||||
|
"--search-parent-directories",
|
||||||
|
"--stdin-filepath",
|
||||||
|
util.escape_path(util.get_current_buffer_file_path()),
|
||||||
|
"--",
|
||||||
|
"-",
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
html = {
|
||||||
|
require("formatter.defaults").prettier,
|
||||||
|
},
|
||||||
|
xml = {
|
||||||
|
function()
|
||||||
|
return {
|
||||||
|
exe = "tidy",
|
||||||
|
args = {
|
||||||
|
"-quiet",
|
||||||
|
"-xml",
|
||||||
|
"--indent yes",
|
||||||
|
"--indent-spaces 2",
|
||||||
|
"--sort-attributes alpha",
|
||||||
|
-- "--verical-space yes",
|
||||||
|
"--literal-attributes yes",
|
||||||
|
"--tidy-mark no",
|
||||||
|
},
|
||||||
|
stdin = true,
|
||||||
|
try_node_modules = true,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- java = {
|
||||||
|
-- function()
|
||||||
|
-- return {
|
||||||
|
-- exe = "google-java-format",
|
||||||
|
-- }
|
||||||
|
-- end,
|
||||||
|
-- },
|
||||||
|
|
||||||
|
-- Use the special "*" filetype for defining formatter configurations on
|
||||||
|
-- any filetype
|
||||||
|
["*"] = {
|
||||||
|
-- "formatter.filetypes.any" defines default configurations for any
|
||||||
|
-- filetype
|
||||||
|
require("formatter.filetypes.any").remove_trailing_whitespace,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
vim.cmd([[
|
||||||
|
augroup FormatAutogroup
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePost * FormatWrite
|
||||||
|
augroup END
|
||||||
|
]])
|
||||||
|
end,
|
||||||
|
}
|
10
vim/.vim/lua/plugins/lint.lua
Normal file
10
vim/.vim/lua/plugins/lint.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
return {
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
config = function()
|
||||||
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||||||
|
callback = function()
|
||||||
|
require("lint").try_lint()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
@ -1,93 +0,0 @@
|
|||||||
return {
|
|
||||||
"jose-elias-alvarez/null-ls.nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
config = function()
|
|
||||||
local null_ls = require("null-ls")
|
|
||||||
local use_google = require("utils").use_google
|
|
||||||
local TableConcat = require("utils").TableConcat
|
|
||||||
|
|
||||||
local sources = {
|
|
||||||
-- *
|
|
||||||
null_ls.builtins.formatting.trim_whitespace,
|
|
||||||
-- Catch insensitive, inconsiderate writing.
|
|
||||||
null_ls.builtins.diagnostics.alex,
|
|
||||||
|
|
||||||
-- Codespell finds common misspellings in text files.
|
|
||||||
null_ls.builtins.diagnostics.codespell,
|
|
||||||
-- null_ls.builtins.diagnostics.cspell, null_ls.builtins.code_actions.cspell,
|
|
||||||
|
|
||||||
-- An English prose linter. Can fix some issues via code actions.
|
|
||||||
null_ls.builtins.code_actions.proselint,
|
|
||||||
|
|
||||||
-- Reformats Java source code according to Google Java Style.
|
|
||||||
null_ls.builtins.formatting.google_java_format,
|
|
||||||
|
|
||||||
-- XML
|
|
||||||
-- null_ls.builtins.diagnostics.tidy,
|
|
||||||
-- null_ls.builtins.formatting.xmlformat,
|
|
||||||
-- null_ls.builtins.formatting.xq,
|
|
||||||
-- null_ls.builtins.formatting.xmllint.with({ extra_args = { "--pretty", "2" } }),
|
|
||||||
null_ls.builtins.formatting.tidy.with({
|
|
||||||
filetypes = { "xml" },
|
|
||||||
args = {
|
|
||||||
"-xml",
|
|
||||||
"-quiet",
|
|
||||||
"-wrap",
|
|
||||||
"--tidy-mark",
|
|
||||||
"no",
|
|
||||||
"--indent",
|
|
||||||
"yes",
|
|
||||||
"--indent-spaces",
|
|
||||||
"2",
|
|
||||||
"--indent-attributes",
|
|
||||||
"yes",
|
|
||||||
"--sort-attributes",
|
|
||||||
"alpha",
|
|
||||||
"--wrap-attributes",
|
|
||||||
"yes",
|
|
||||||
"--vertical-space",
|
|
||||||
"yes",
|
|
||||||
"-",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
null_ls.builtins.formatting.stylua,
|
|
||||||
}
|
|
||||||
|
|
||||||
if not use_google then
|
|
||||||
TableConcat(sources, {
|
|
||||||
-- Bazel
|
|
||||||
null_ls.builtins.diagnostics.buildifier,
|
|
||||||
null_ls.builtins.formatting.buildifier,
|
|
||||||
-- Golang
|
|
||||||
null_ls.builtins.diagnostics.golangci_lint,
|
|
||||||
null_ls.builtins.formatting.gofmt,
|
|
||||||
null_ls.builtins.formatting.goimports_reviser,
|
|
||||||
-- Misc
|
|
||||||
null_ls.builtins.formatting.htmlbeautifier,
|
|
||||||
null_ls.builtins.formatting.jq,
|
|
||||||
null_ls.builtins.formatting.mdformat,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
||||||
null_ls.setup({
|
|
||||||
on_init = function(new_client, _)
|
|
||||||
new_client.offset_encoding = "utf-8"
|
|
||||||
end,
|
|
||||||
sources = sources,
|
|
||||||
-- you can reuse a shared lspconfig on_attach callback here
|
|
||||||
on_attach = function(client, bufnr)
|
|
||||||
if client.supports_method("textDocument/formatting") then
|
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
group = augroup,
|
|
||||||
buffer = bufnr,
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format({ async = false })
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}
|
|
Reference in New Issue
Block a user