nvim/lua/setupformat.lua

138 lines
3 KiB
Lua
Raw Normal View History

2024-03-12 01:28:22 -04:00
-- BY LANG
-- https://github.com/mhartington/formatter.nvim/tree/master/lua/formatter/filetypes
-- Utilities for creating configurations
local util = require("formatter.util")
2024-03-12 15:22:20 -04:00
local defaults = require("formatter.defaults")
2024-03-12 01:28:22 -04:00
-- 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 = {
2024-03-31 22:21:06 -04:00
json = {
require("formatter.filetypes.json").prettierd,
function()
return {
exe = "prettierd",
args = { util.escape_path(util.get_current_buffer_file_path()) },
stdin = true,
}
end,
},
2024-03-14 20:49:32 -04:00
yaml = {
require("formatter.filetypes.yaml").yamlfmt,
function()
return {
exe = "yamlfmt",
args = { "-in" },
stdin = true,
}
end,
},
2024-03-21 15:49:14 -04:00
java = {
require("formatter.filetypes.java").clangformat,
function()
return {
exe = "clang-format",
args = {
"--style=Google",
"--assume-filename=.java",
},
stdin = true,
}
end,
},
2024-03-12 01:28:22 -04:00
-- Formatter configurations for filetype "lua" go here
-- and will be executed in order
2024-03-12 15:22:20 -04:00
typescript = {
require("formatter.filetypes.typescript").eslint_d,
2024-03-21 15:49:14 -04:00
function()
return {
args = {
"--stdin",
"--fix-to-stdout",
},
exe = "eslint_d",
stdin = true,
try_node_modules = true,
}
end,
2024-03-12 15:22:20 -04:00
},
2024-03-14 20:49:32 -04:00
cpp = {
require("formatter.filetypes.c").clangformat,
function()
return {
util.copyf(defaults.clangformat),
}
end,
},
h = {
require("formatter.filetypes.c").clangformat,
function()
return {
util.copyf(defaults.clangformat),
}
end,
},
c = {
require("formatter.filetypes.c").clangformat,
function()
return {
util.copyf(defaults.clangformat),
}
end,
},
2024-03-12 01:28:22 -04:00
kotlin = {
require("formatter.filetypes.kotlin").ktlint,
function()
return {
exe = "ktlint",
args = {
"--stdin",
"--format",
"--log-level=none",
},
stdin = true,
}
end,
},
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,
},
-- 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,
},
},
})