Compare commits

...

2 commits

Author SHA1 Message Date
diniamo
21c322671b
Merge b73a6f2228 into 42c5228dc1 2024-10-31 13:46:32 +00:00
diniamo
b73a6f2228 Squash merge julia into custom 2024-10-31 14:46:26 +01:00
4 changed files with 112 additions and 5 deletions

View file

@ -65,17 +65,14 @@ isMaximal: {
r.enable = isMaximal; r.enable = isMaximal;
tailwind.enable = isMaximal; tailwind.enable = isMaximal;
typst.enable = isMaximal; typst.enable = isMaximal;
clang = { clang.enable = isMaximal;
enable = isMaximal;
lsp.server = "clangd";
};
scala.enable = isMaximal; scala.enable = isMaximal;
rust = { rust = {
enable = isMaximal; enable = isMaximal;
crates.enable = isMaximal; crates.enable = isMaximal;
}; };
csharp.enable = isMaximal; csharp.enable = isMaximal;
julia.enable = isMaximal;
}; };
visuals = { visuals = {

View file

@ -192,6 +192,10 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to
- Add C# support under `vim.languages.csharp`, with support for both - Add C# support under `vim.languages.csharp`, with support for both
omnisharp-roslyn and csharp-language-server. omnisharp-roslyn and csharp-language-server.
- Add Julia support under `vim.languages.julia`. Note that the entirety of
Julia is bundled with nvf, if you enabled the module, since there is no way
to provide only the LSP server.
[Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd()
- Make Neovim's configuration file entirely Lua based. This comes with a few - Make Neovim's configuration file entirely Lua based. This comes with a few

View file

@ -29,6 +29,7 @@ in {
./typst.nix ./typst.nix
./zig.nix ./zig.nix
./csharp.nix ./csharp.nix
./julia.nix
]; ];
options.vim.languages = { options.vim.languages = {

View file

@ -0,0 +1,105 @@
{
lib,
pkgs,
config,
...
}: let
inherit (builtins) attrNames isList;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) either listOf package str enum;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
defaultServer = "julials";
servers = {
julials = {
package = pkgs.julia.withPackages ["LanguageServer"];
internalFormatter = true;
lspConfig = ''
lspconfig.julials.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''
{
"${cfg.lsp.package}/bin/julia",
"--startup-file=no",
"--history-file=no",
"--eval",
[[
using LanguageServer
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
project_path = let
dirname(something(
## 1. Finds an explicitly set project (JULIA_PROJECT)
Base.load_path_expand((
p = get(ENV, "JULIA_PROJECT", nothing);
p === nothing ? nothing : isempty(p) ? nothing : p
)),
## 2. Look for a Project.toml file in the current working directory,
## or parent directories, with $HOME as an upper boundary
Base.current_project(),
## 3. First entry in the load path
get(Base.load_path(), 1, nothing),
## 4. Fallback to default global environment,
## this is more or less unreachable
Base.load_path_expand("@v#.#"),
))
end
@info "Running language server" VERSION pwd() project_path depot_path
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path)
server.runlinter = true
run(server)
]]
}
''
}
}
'';
};
};
cfg = config.vim.languages.julia;
in {
options = {
vim.languages.julia = {
enable = mkEnableOption "Julia language support";
treesitter = {
enable = mkEnableOption "Julia treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "julia";
};
lsp = {
enable = mkEnableOption "Julia LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "Julia LSP server to use";
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
description = "Julia LSP server package, or the command to run as a list of strings";
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.julia-lsp = servers.${cfg.lsp.server}.lspConfig;
})
]);
}