feat(nvim): add nixCats-backed language options
check / lint (push) Successful in 16s

This commit is contained in:
hektor committed 2026-11-04 23:51:07 +01:00
1 parent 0d5027edb7
commit 3e377ce637
12 files changed
+410 -199

No files matched your search

@@ -1,29 +1,51 @@
local nixCatsUtils = require("nixCatsUtils")
local formatters = {
general = {
awk = { "awk" },
html = { "prettierd", "prettier", stop_after_first = true },
json = { "prettierd", "prettier", stop_after_first = true },
jsonc = { "prettierd", "prettier", stop_after_first = true },
markdown = { "prettierd", "prettier", stop_after_first = true },
},
c = {
c = { "clang-format" },
cpp = { "clang-format" },
},
css = { css = { "prettierd", "prettier", stop_after_first = true } },
gdscript = { gdscript = { "gdformat" } },
go = { go = { "gofmt" } },
haskell = { haskell = { "ormolu" } },
lua = { lua = { "stylua" } }, -- configured in stylua.toml
nix = { nix = { "nixfmt" } },
python = { python = { "isort", "black" } },
rust = { rust = { "rustfmt", lsp_format = "fallback" } },
shell = { bash = { "shellcheck" } },
svelte = { svelte = { "eslint_d", "prettierd", "prettier", stop_after_first = true } },
typescript = {
javascript = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
javascriptreact = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
typescript = { "eslint_d", "prettierd", "prettier", stop_after_first = true },
typescriptreact = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
},
yaml = {
-- yaml = { "prettierd", "prettier", stop_after_first = true },
},
}
local formatters_by_ft = {}
for language, language_formatters in pairs(formatters) do
if language == "general" or nixCatsUtils.enableForCategory("languages." .. language) then
for ft, ft_formatters in pairs(language_formatters) do
formatters_by_ft[ft] = ft_formatters
end
end
end
require("conform").setup({
format_after_save = {
lsp_format = "never",
timeout_ms = 500,
},
formatters_by_ft = {
awk = { "awk" },
bash = { "shellcheck" },
c = { "clang-format" },
cpp = { "clang-format" },
css = { "prettierd", "prettier", stop_after_first = true },
gdscript = { "gdformat" },
haskell = { "ormolu" },
html = { "prettierd", "prettier", stop_after_first = true },
javascript = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
javascriptreact = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
json = { "prettierd", "prettier", stop_after_first = true },
jsonc = { "prettierd", "prettier", stop_after_first = true },
lua = { "stylua" }, -- configured in stylua.toml
markdown = { "prettierd", "prettier", stop_after_first = true },
nix = { "nixfmt" },
python = { "isort", "black" },
rust = { "rustfmt", lsp_format = "fallback" },
svelte = { "eslint_d", "prettierd", "prettier", stop_after_first = true },
typescript = { "eslint_d", "prettierd", "prettier", stop_after_first = true },
typescriptreact = { "eslint_d", "eslint", "prettierd", "prettier", stop_after_first = true },
-- yaml = { "prettierd", "prettier", stop_after_first = true },
},
formatters_by_ft = formatters_by_ft,
})
@@ -4,159 +4,186 @@ local cmp_nvim_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_nvim_lsp.default_capabilities()
local servers = {
bashls = {},
eslint = {
settings = {
--Assuming prettier/prettierd will handle formatting, we don't need to see these errors
rulesCustomizations = {
{ rule = "prettier/prettier", severity = "off" },
},
format = false,
c = { clangd = {} },
css = { cssls = {} },
docker = { dockerls = {} },
gdscript = { gdscript = {} },
go = { gopls = {} },
haskell = { hls = { filetypes = { "haskell", "lhaskell", "cabal" } } },
helm = {
helm_ls = {
filetypes = { "helm", "yaml.helm-values" },
},
},
emmet_language_server = {},
gdscript = {},
helm_ls = {
filetypes = { "helm", "yaml.helm-values" },
html = {
emmet_language_server = {},
html = {},
},
hls = { filetypes = { "haskell", "lhaskell", "cabal" } },
html = {},
jsonls = {
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
json = {
jsonls = {
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
},
},
},
},
lua_ls = {
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if
path ~= vim.fn.stdpath("config")
and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc"))
then
return
lua = {
lua_ls = {
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if
path ~= vim.fn.stdpath("config")
and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc"))
then
return
end
end
end
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = {
version = "LuaJIT",
path = {
"lua/?.lua",
"lua/?/init.lua",
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = {
version = "LuaJIT",
path = {
"lua/?.lua",
"lua/?/init.lua",
},
},
},
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
},
},
},
})
end,
settings = {
Lua = {},
})
end,
settings = {
Lua = {},
},
},
},
nixd = {
settings = {
nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }",
expr = 'import (builtins.getFlake ("git+file://" + toString ../../../../../.)).inputs.nixpkgs { }',
nix = {
nixd = {
settings = {
nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }",
expr = 'import (builtins.getFlake ("git+file://" + toString ../../../../../.)).inputs.nixpkgs { }',
},
},
},
options = {
nixos = {
expr = '(builtins.getFlake ("git+file://" + toString ../../../../../.)).nixosConfigurations."'
.. vim.fn.hostname()
.. '".options',
},
home_manager = {
expr = '(builtins.getFlake ("git+file://" + toString ../../../../../.)).homeConfigurations."'
.. vim.fn.expand("$USER")
.. "@"
.. vim.fn.hostname()
.. '".options',
options = {
nixos = {
expr = '(builtins.getFlake ("git+file://" + toString ../../../../../.)).nixosConfigurations."'
.. vim.fn.hostname()
.. '".options',
},
home_manager = {
expr = '(builtins.getFlake ("git+file://" + toString ../../../../../.)).homeConfigurations."'
.. vim.fn.expand("$USER")
.. "@"
.. vim.fn.hostname()
.. '".options',
},
},
},
},
},
openscad_ls = {},
pyright = {},
openscad = { openscad_ls = {} },
python = { pyright = {} },
shell = { bashls = {} },
svelte = {
plugin = {
svelte = {
defaultScriptLanguage = "ts",
svelte = {
plugin = {
svelte = {
defaultScriptLanguage = "ts",
},
},
},
},
tailwindcss = {},
ts_ls = {},
vtsls = {
filetypes = {
"javascript",
"javascriptreact",
"javascript.jsx",
"typescript",
"typescriptreact",
"typescript.tsx",
tailwind = { tailwindcss = {} },
typescript = {
eslint = {
settings = {
--Assuming prettier/prettierd will handle formatting, we don't need to see these errors
rulesCustomizations = {
{ rule = "prettier/prettier", severity = "off" },
},
format = false,
},
},
settings = {
vtsls = {
enableMoveToFileCodeAction = true,
autoUseWorkspaceTsdk = true,
experimental = {
completion = {
enableServerSideFuzzyMatch = true,
ts_ls = {},
vtsls = {
filetypes = {
"javascript",
"javascriptreact",
"javascript.jsx",
"typescript",
"typescriptreact",
"typescript.tsx",
},
settings = {
vtsls = {
enableMoveToFileCodeAction = true,
autoUseWorkspaceTsdk = true,
experimental = {
completion = {
enableServerSideFuzzyMatch = true,
},
},
},
typescript = {
updateImportsOnFileMove = { enabled = "always" },
tsserver = { maxTsServerMemory = 16384 },
suggest = {
completeFunctionCalls = true,
},
inlayHints = {
enumMemberValues = { enabled = true },
functionLikeReturnTypes = { enabled = true },
parameterNames = { enabled = "literals" },
parameterTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
variableTypes = { enabled = false },
},
},
},
typescript = {
updateImportsOnFileMove = { enabled = "always" },
tsserver = { maxTsServerMemory = 16384 },
suggest = {
completeFunctionCalls = true,
},
inlayHints = {
enumMemberValues = { enabled = true },
functionLikeReturnTypes = { enabled = true },
parameterNames = { enabled = "literals" },
parameterTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
variableTypes = { enabled = false },
},
},
},
},
yamlls = {
settings = {
yaml = {
schemaStore = {
-- You must disable built-in schemaStore support if you want to use
-- this plugin and its advanced options like `ignore`.
enable = false,
-- Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "",
yaml = {
yamlls = {
settings = {
yaml = {
schemaStore = {
-- You must disable built-in schemaStore support if you want to use
-- this plugin and its advanced options like `ignore`.
enable = false,
-- Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "",
},
schemas = require("schemastore").yaml.schemas(),
},
schemas = require("schemastore").yaml.schemas(),
},
},
},
}
local typescript_server = require("nixCatsUtils").getCatOrDefault("typescriptServer", "ts_ls")
servers[typescript_server == "vtsls" and "ts_ls" or "vtsls"] = nil
local nixCatsUtils = require("nixCatsUtils")
local typescript_server = nixCatsUtils.getCatOrDefault("typescriptServer", "ts_ls")
servers.typescript[typescript_server == "vtsls" and "ts_ls" or "vtsls"] = nil
for server, config in pairs(servers) do
config.capabilities = capabilities
vim.lsp.config(server, config)
local enabled = {}
for language, language_servers in pairs(servers) do
if nixCatsUtils.enableForCategory("languages." .. language) then
for server, config in pairs(language_servers) do
config.capabilities = capabilities
vim.lsp.config(server, config)
table.insert(enabled, server)
end
end
end
vim.lsp.enable(vim.tbl_keys(servers))
vim.lsp.enable(enabled)
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(e)
@@ -1,33 +1,60 @@
local nixCatsUtils = require("nixCatsUtils")
vim.env.ESLINT_D_PPID = vim.fn.getpid()
local eslint_linter = "eslint_d"
require("lint").linters_by_ft = {
bash = { "shellcheck" },
c = { "clangtidy", "flawfinder" },
cmake = { "cmakelint" },
cpp = { "clangtidy", "flawfinder" }, -- "cpplint", "cppcheck", "flawfinder"
css = { "stylelint" },
dockerfile = { "hadolint" },
editorconfig = { "editorconfig-checker" },
haskell = { "hlint" },
-- html = { "htmlhint" },
-- javascript = { eslint_linter },
-- javascriptreact = { eslint_linter },
gdscript = { "gdlint" },
latex = { "chktex" },
-- lua = { "luacheck", "selene" },
make = { "checkmake" },
-- pandoc = { "proselint", "woke" },
-- python = { "pylint" },
sh = { "shellcheck" },
svelte = { eslint_linter },
systemd = { "systemdlint" },
-- typescript = { eslint_linter },
-- typescriptreact = { eslint_linter },
yaml = { "yamllint" },
local linters = {
general = {
cmake = { "cmakelint" },
editorconfig = { "editorconfig-checker" },
latex = { "chktex" },
make = { "checkmake" },
-- pandoc = { "proselint", "woke" },
systemd = { "systemdlint" },
},
c = {
c = { "clangtidy", "flawfinder" },
cpp = { "clangtidy", "flawfinder" }, -- "cpplint", "cppcheck", "flawfinder"
},
css = { css = { "stylelint" } },
docker = { dockerfile = { "hadolint" } },
gdscript = { gdscript = { "gdlint" } },
haskell = { haskell = { "hlint" } },
html = {
-- html = { "htmlhint" },
},
lua = {
-- lua = { "luacheck", "selene" },
},
python = {
-- python = { "pylint" },
},
shell = {
bash = { "shellcheck" },
sh = { "shellcheck" },
},
svelte = { svelte = { eslint_linter } },
typescript = {
-- javascript = { eslint_linter },
-- javascriptreact = { eslint_linter },
-- typescript = { eslint_linter },
-- typescriptreact = { eslint_linter },
},
yaml = { yaml = { "yamllint" } },
}
local linters_by_ft = {}
for language, language_linters in pairs(linters) do
if language == "general" or nixCatsUtils.enableForCategory("languages." .. language) then
for ft, ft_linters in pairs(language_linters) do
linters_by_ft[ft] = ft_linters
end
end
end
require("lint").linters_by_ft = linters_by_ft
local function has_yamllint_config(buf)
return vim.fs.root(buf, { ".yamllint", ".yamllint.yaml", ".yamllint.yml" }) ~= nil
end
@@ -1 +1,5 @@
if not require("nixCatsUtils").enableForCategory("languages.tailwind") then
return
end
require("tailwind-fold").setup({ ft = { "html", "svelte", "tsx" } })