1
0
Fork 0
dotfiles/.config/nvim/lua/config/language.lua

205 lines
5 KiB
Lua

---@diagnostic disable: missing-fields
---@class config.language
local M = {}
---@type table<string, conform.FormatterUnit>
M.formatters_by_ft = {
css = { "prettier" },
scss = { "prettier" },
lua = { "stylua" },
python = { "black" },
sh = { "shfmt" },
}
---@type table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride>
M.formatters = {
injected = { options = { ignore_errors = true } },
shfmt = { prepend_args = { "-i", "4", "-ci" } },
}
---@type table<string,table>
M.linters_by_ft = {
dockerfile = { "hadolint" },
markdown = { "markdownlint" },
}
---@type table<string,table>
M.linters = {}
---@type Array<string>
M.mason_install = {
"ansible-lint",
"ansible-language-server",
"basedpyright",
"bash-language-server",
"codelldb",
"debugpy",
"dockerfile-language-server",
"docker-compose-language-service",
"helm-ls",
"json-lsp",
"lua-language-server",
"hadolint",
"marksman",
"markdownlint",
"prettier",
"ruff-lsp",
"rust-analyzer",
"yaml-language-server",
}
---@type Array<string>
M.treesitter_install = {
"bash",
"c",
"diff",
"dockerfile",
"helm",
"html",
"json",
"jsonc",
"json5",
"lua",
"luadoc",
"luap",
"markdown",
"markdown_inline",
"ninja",
"python",
"query",
"regex",
"ron",
"rst",
"rust",
"toml",
"vim",
"vimdoc",
"xml",
"yaml",
}
---@type lspconfig.options
M.lsp = {
intelephense = {
init_options = {
storagePath = os.getenv("XDG_CACHE_HOME") .. "/intelephense",
globalStoragePath = os.getenv("XDG_CONFIG_HOME") .. "/intelephense",
licenceKey = require("lib").get_secret("intelephense")
},
},
jsonls = {
on_new_config = function(new_config)
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas())
end,
settings = {
json = {
format = {
enable = true,
},
validate = { enable = true },
},
},
},
lua_ls = {
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = "Replace",
},
},
},
},
ruff_lsp = {
keys = {
{
"<leader>co",
function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { "source.organizeImports" },
diagnostics = {},
},
})
end,
desc = "Organize Imports",
},
},
},
yamlls = {
capabilities = {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
},
},
on_new_config = function(new_config)
new_config.settings.yaml.schemas = vim.tbl_deep_extend(
"force",
new_config.settings.yaml.schemas or {},
require("schemastore").yaml.schemas()
)
end,
settings = {
redhat = { telemetry = { enabled = false } },
yaml = {
keyOrdering = false,
format = {
enable = true,
},
validate = true,
schemaStore = {
enable = false,
url = "",
},
},
},
},
}
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
M.lsp_setup = {
ruff_lsp = function()
LazyVim.lsp.on_attach(function(client, _)
if client.name == "ruff_lsp" then
client.server_capabilities.hoverProvider = false
client.server_capabilities.renameProvider = false
end
end)
end,
rust_analyzer = function()
return true
end,
["*"] = function(server, opts)
local base = vim.lsp.protocol.make_client_capabilities()
local cmp = require("cmp_nvim_lsp").default_capabilities()
vim.tbl_deep_extend("force", opts.capabilities, base)
vim.tbl_deep_extend("force", opts.capabilities, cmp)
require("lspconfig")[server].setup(opts)
end,
}
setmetatable(M, {
__index = function(_, k)
if k == "lsp" then
for l, _ in pairs(M.lsp) do
M.lsp[l].mason = false
return M.lsp
end
end
return require("custom." .. k)
end,
})
M.dap = {}
return M