1
0
Fork 0
forked from foxora/nix

added toml formatter, split each language into lsp and format

This commit is contained in:
foxora 2026-03-05 05:50:50 +00:00
parent 56d2fe2922
commit 67c8d10658
4 changed files with 184 additions and 125 deletions

View file

@ -1,92 +1,110 @@
local servers = {} local servers = {}
servers.lua_ls = { if nixCats("lang.lua.lsp") then
settings = { servers.lua_ls = {
Lua = { settings = {
formatters = { Lua = {
ignoreComments = false, formatters = {
ignoreComments = false,
},
signatureHelp = { enable = true },
diagnostics = {
globals = { "nixCats", "vim" },
-- disable = { 'missing-fields' },
},
workspace = {
-- make the server aware of the neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
},
telemetry = { enabled = false },
},
}
end
if nixCats("lang.nix.lsp") then
servers.nil_ls = {
settings = {},
}
end
if nixCats("lang.rust.lsp") then
local rust_analyzer_cmd = os.getenv("RUST_ANALYZER_CMD")
servers.rust_analyzer = {
cmd = { rust_analyzer_cmd },
settings = {
server = {
-- For debugging rust-analyzer, to see log location do :LspInfo in neovim
-- extraEnv = { {["RA_LOG"]="project_model=debug"} },
},
cargo = {
allFeatures = false,
allTargets = false,
buildScripts = { enable = true },
target = "x86_64-unknown-linux-gnu",
}, },
signatureHelp = { enable = true },
diagnostics = { diagnostics = {
globals = { "nixCats", "vim" }, enable = true,
-- disable = { 'missing-fields' },
},
workspace = {
-- make the server aware of the neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
}, },
}, },
telemetry = { enabled = false }, }
}, end
}
servers.nil_ls = { if nixCats("lang.zig.lsp") then
settings = {}, servers.zls = {
} settings = {},
}
end
local rust_analyzer_cmd = os.getenv("RUST_ANALYZER_CMD") if nixCats("lang.elixir.lsp") then
servers.rust_analyzer = { local elixir_ls_cmd = os.getenv("ELIXIR_LS_CMD")
cmd = { rust_analyzer_cmd }, servers.elixirls = {
settings = { cmd = { elixir_ls_cmd },
server = { settings = {},
-- For debugging rust-analyzer, to see log location do :LspInfo in neovim }
-- extraEnv = { {["RA_LOG"]="project_model=debug"} }, end
},
cargo = {
allFeatures = false,
allTargets = false,
buildScripts = { enable = true },
target = "x86_64-unknown-linux-gnu",
},
diagnostics = {
enable = true,
},
},
}
servers.zls = { if nixCats("lang.gleam.lsp") then
settings = {}, servers.gleam = {
} settings = {},
}
end
local elixir_ls_cmd = os.getenv("ELIXIR_LS_CMD") if nixCats("lang.haskell.lsp") then
servers.elixirls = { servers.hls = {
cmd = { elixir_ls_cmd }, settings = {},
settings = {}, }
} end
servers.gleam = { if nixCats("lang.java.lsp") then
settings = {}, local java_home = os.getenv("JAVA_HOME")
} servers.jdtls = {
settings = {
servers.hls = { java = {
settings = {}, contentProvider = { preferred = "fernflower" },
} configuration = {
runtimes = {
local java_home = os.getenv("JAVA_HOME") {
servers.jdtls = { name = "OpenJDK 17",
settings = { path = os.getenv("OPENJDK_17"),
java = { },
contentProvider = { preferred = "fernflower" }, {
configuration = { name = "OpenJDK 21",
runtimes = { path = os.getenv("OPENJDK_21"),
{ },
name = "OpenJDK 17",
path = os.getenv("OPENJDK_17"),
},
{
name = "OpenJDK 21",
path = os.getenv("OPENJDK_21"),
}, },
}, },
}, },
}, },
}, }
} end
servers.protols = { if nixCats("lang.protobuf.lsp") then
settings = {}, servers.protols = {
} settings = {},
}
end
-- Taken from nixCats example: -- Taken from nixCats example:
-- If you were to comment out this autocommand -- If you were to comment out this autocommand

View file

@ -56,11 +56,12 @@ return {
conform.setup({ conform.setup({
formatters_by_ft = { formatters_by_ft = {
lua = nixCats("lang.lua") and { "stylua" } or nil, lua = nixCats("lang.lua.format") and { "stylua" } or nil,
nix = nixCats("lang.nix") and { "alejandra" } or nil, nix = nixCats("lang.nix.format") and { "alejandra" } or nil,
rust = nixCats("lang.rust") and { "rustfmt", lsp_format = "fallback" } or nil, rust = nixCats("lang.rust.format") and { "rustfmt", lsp_format = "fallback" } or nil,
haskell = nixCats("lang.haskell") and { "ormolu" } or nil, haskell = nixCats("lang.haskell.format") and { "ormolu" } or nil,
proto = nixCats("lang.protobuf") and { "buf" } or nil, proto = nixCats("lang.protobuf.format") and { "buf" } or nil,
toml = nixCats("lang.toml.format") and { "taplo" } or nil,
}, },
format_on_save = { format_on_save = {
timeout_ms = 500, timeout_ms = 500,

View file

@ -1,12 +1,12 @@
return { return {
{ {
"vim-fugitive", "vim-fugitive",
for_cat = "git", enabled = nixCats("git") or false,
cmd = { "Git", "Gvdiffsplit" }, cmd = { "Git", "Gvdiffsplit" },
}, },
{ {
"resolve-nvim", "resolve-nvim",
for_cat = "git", enabled = nixCats("git") or false,
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
after = function(plugin) after = function(plugin)
require("resolve").setup({ require("resolve").setup({

View file

@ -55,43 +55,51 @@ in {
tree-sitter tree-sitter
]; ];
lang = { lang = {
lua = [ lua = {
lua-language-server lsp = [lua-language-server];
stylua format = [stylua];
]; };
nix = [ nix = {
nil lsp = [nil];
nix-doc # TODO: i forgot what this is for format = [alejandra];
alejandra docs = [nix-doc]; # TODO: i forgot how to integrate this into neovim
]; };
rust = [ rust = {
cargo lsp = [cargo mpkgs.rust-analyzer];
mpkgs.rust-analyzer
# nightly rustfmt has nicer features :3 # nightly rustfmt has nicer features :3
inputs.fenix.packages.${system}.complete.rustfmt format = [inputs.fenix.packages.${system}.complete.rustfmt];
]; };
zig = [ zig = {
zls lsp = [zls];
]; # TODO: needs formatter field
elixir = [ };
elixir-ls elixir = {
]; lsp = [elixir-ls];
gleam = [ # TODO: needs formatter field
gleam };
]; gleam = {
haskell = [ lsp = [gleam];
haskell-language-server # TODO: needs formatter field
ormolu };
]; haskell = {
java = [ lsp = [haskell-language-server];
jdt-language-server format = [ormolu];
javaPackages.compiler.openjdk17 };
javaPackages.compiler.openjdk21 java = {
]; lsp = [
protobuf = [ jdt-language-server
protols javaPackages.compiler.openjdk17
buf javaPackages.compiler.openjdk21
]; ];
# TODO: needs formatter field
};
protobuf = {
lsp = [protols];
format = [buf];
};
toml = {
format = [taplo];
};
}; };
}; };
@ -239,15 +247,47 @@ in {
git = false; # not really setup yet git = false; # not really setup yet
lang = { lang = {
lua = true; lua = {
nix = true; lsp = true;
rust = true; format = true;
zig = true; };
elixir = true; nix = {
gleam = true; lsp = true;
haskell = true; format = true;
java = true; docs = true;
protobuf = true; };
rust = {
lsp = true;
format = true;
};
zig = {
lsp = true;
format = true;
};
elixir = {
lsp = true;
format = true;
};
gleam = {
lsp = true;
format = true;
};
haskell = {
lsp = true;
format = true;
};
java = {
lsp = true;
format = true;
};
protobuf = {
lsp = true;
format = true;
};
toml = {
lsp = true;
format = true;
};
}; };
}; };
}; };