From 90a5a42742850dc95e8cab2c3de936718d9055cc Mon Sep 17 00:00:00 2001 From: diniamo Date: Sat, 21 Dec 2024 01:15:10 +0100 Subject: [PATCH] languages/odin: init --- docs/release-notes/rl-0.8.md | 6 ++- modules/plugins/languages/default.nix | 1 + modules/plugins/languages/odin.nix | 71 +++++++++++++++++++++++++++ modules/plugins/languages/zig.nix | 1 + 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 modules/plugins/languages/odin.nix diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 36209ff7..03d4d010 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -13,4 +13,8 @@ [haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim -- Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim] +- Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim]. + +[diniamo](https://github.com/diniamo): + +- Add Odin support under `vim.languages.odin`. diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 48945b38..ee9f55e1 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -37,6 +37,7 @@ in { ./csharp.nix ./julia.nix ./nu.nix + ./odin.nix ]; options.vim.languages = { diff --git a/modules/plugins/languages/odin.nix b/modules/plugins/languages/odin.nix new file mode 100644 index 00000000..7a32db93 --- /dev/null +++ b/modules/plugins/languages/odin.nix @@ -0,0 +1,71 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) isList; + inherit (lib.types) either listOf package str enum; + inherit (lib.nvim.lua) expToLua; + inherit (lib.nvim.types) mkGrammarOption; + + defaultServer = "ols"; + servers = { + ols = { + package = pkgs.ols; + lspConfig = '' + lspconfig.ols.setup { + capabilities = capabilities, + on_attach = default_on_attach, + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else "{'${cfg.lsp.package}/bin/ols'}" + } + } + ''; + }; + }; + + cfg = config.vim.languages.odin; +in { + options.vim.languages.odin = { + enable = mkEnableOption "Odin language support"; + + treesitter = { + enable = mkEnableOption "Odin treesitter" // {default = config.vim.languages.enableTreesitter;}; + package = mkGrammarOption pkgs "odin"; + }; + + lsp = { + enable = mkEnableOption "Odin LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "Odin LSP server to use"; + }; + + package = mkOption { + description = "Ols package, or the command to run as a list of strings"; + type = either package (listOf str); + default = pkgs.ols; + }; + }; + }; + + 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.odin-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + ]); +} diff --git a/modules/plugins/languages/zig.nix b/modules/plugins/languages/zig.nix index 7ae8a5c2..3618d6d8 100644 --- a/modules/plugins/languages/zig.nix +++ b/modules/plugins/languages/zig.nix @@ -57,6 +57,7 @@ in { }; }; }; + config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { vim.treesitter.enable = true;