From 53e89665cee037b37a87801823992c11f29ca76d Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Fri, 15 May 2026 14:39:03 +0200 Subject: [PATCH 1/3] treesitter: support usage of `pkgs.tree-sitter-grammars` --- docs/manual/release-notes/rl-0.9.md | 4 ++++ lib/types/default.nix | 2 +- lib/types/languages.nix | 13 ++++++++++++- modules/plugins/treesitter/treesitter.nix | 8 ++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index a36a19c0..35d8def7 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -291,6 +291,10 @@ [Snoweuph](https://github.com/snoweuph) +- Allow the usage of `pks.tree-sitter-grammars` in + {option}`vim.treesitter.grammars` and language module tree-sitter package + options created via `mkGrammarOption`. + - Add `emmet-ls` to the supported LSPs for all languages it supports. - Added {option}`vim.treesitter.queries` to support adding custom queries. diff --git a/lib/types/default.nix b/lib/types/default.nix index 9b5469db..57fb43fe 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -10,7 +10,7 @@ in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; - inherit (typesLanguage) diagnostics mkGrammarOption; + inherit (typesLanguage) diagnostics mkGrammarOption mkTreesitterGrammarOption; inherit (typesLsp) mkLspPresetEnableOption; inherit (customTypes) char hexColor mergelessListOf deprecatedSingleOrListOf enumWithRename; } diff --git a/lib/types/languages.nix b/lib/types/languages.nix index 23a08890..6960ecb3 100644 --- a/lib/types/languages.nix +++ b/lib/types/languages.nix @@ -33,6 +33,17 @@ default = ["vimPlugins" "nvim-treesitter" "grammarPlugins" grammar]; nullable = true; }; + + # Prefer using `mkGrammarOption` and only use this, for grammars, + # not in `vimPlugins.nvim-treesitter.grammarPlugins`. + # Grammars from `tree-sitter-grammars.tree-sitter-` should mostly + # just work, but should be tested extra, as we currently only use them + # for a small subset of language modules. + mkTreesitterGrammarOption = pkgs: grammar: + mkPackageOption pkgs ["${grammar} treesitter"] { + default = ["tree-sitter-grammars" "tree-sitter-${grammar}"]; + nullable = true; + }; in { - inherit diagnostics diagnosticSubmodule mkGrammarOption; + inherit diagnostics diagnosticSubmodule mkGrammarOption mkTreesitterGrammarOption; } diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index a58fda45..876ee9e9 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -41,8 +41,12 @@ in { ''; description = '' List of treesitter grammars to install. For grammars to be installed properly, - you must use grammars from `pkgs.vimPlugins.nvim-treesitter.parsers` or `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`. - You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars. + you must use grammars from one of those: + - `pkgs.vimPlugins.nvim-treesitter.parsers` + - `pkgs.vimPlugins.nvim-treesitter.grammarPlugins` + - `pkgs.tree-sitter-grammars` (mostly untested) + + You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars shipped with `nvim-treesitter`. For languages already supported by nvf, you may use {option}`vim.language..treesitter` options, which will automatically add From a7b8cca73a462388394637c25b5d148ee7284fac Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Fri, 15 May 2026 14:39:27 +0200 Subject: [PATCH 2/3] lsp/presets/millet: init --- modules/plugins/lsp/presets/default.nix | 1 + modules/plugins/lsp/presets/millet.nix | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 modules/plugins/lsp/presets/millet.nix diff --git a/modules/plugins/lsp/presets/default.nix b/modules/plugins/lsp/presets/default.nix index d8bde108..4827f598 100644 --- a/modules/plugins/lsp/presets/default.nix +++ b/modules/plugins/lsp/presets/default.nix @@ -35,6 +35,7 @@ ./lua-language-server.nix ./markdown-oxide.nix ./marksman.nix + ./millet.nix ./neocmakelsp.nix ./nil.nix ./nimlsp.nix diff --git a/modules/plugins/lsp/presets/millet.nix b/modules/plugins/lsp/presets/millet.nix new file mode 100644 index 00000000..e63d5267 --- /dev/null +++ b/modules/plugins/lsp/presets/millet.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.millet; +in { + options.vim.lsp.presets.millet = { + enable = mkLspPresetEnableOption "millet" "Millet Standard ML" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.millet = { + enable = true; + cmd = [(getExe pkgs.millet)]; + root_markers = [".git" "millet.toml"]; + }; + }; +} From 93bfa8f4e0c3cd82849635f72501a6341de591c3 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Fri, 15 May 2026 14:39:51 +0200 Subject: [PATCH 3/3] languages/standard-ml: init --- configuration.nix | 1 + docs/manual/release-notes/rl-0.9.md | 2 + modules/plugins/languages/default.nix | 1 + modules/plugins/languages/standard-ml.nix | 114 ++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 modules/plugins/languages/standard-ml.nix diff --git a/configuration.nix b/configuration.nix index 22c845f9..962383cd 100644 --- a/configuration.nix +++ b/configuration.nix @@ -115,6 +115,7 @@ isMaximal: { fluent.enable = false; jq.enable = false; fish.enable = false; + standard-ml.enable = false; # Nim LSP is broken on Darwin and therefore # should be disabled by default. Users may still enable diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 35d8def7..a1c95e9f 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -407,6 +407,8 @@ - Added [`biomejs`](https://biomejs.dev/) as extra diagnostics provider to `languages.ts`. +- Added `languages.standard-ml`. + - Added `languages.vue`. - Add `languages.fluent` using the official plugin. This only provides diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 1be4b25f..896e18c3 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -14,6 +14,7 @@ in { ./clojure.nix ./cmake.nix ./css.nix + ./standard-ml.nix ./scss.nix ./elixir.nix ./elm.nix diff --git a/modules/plugins/languages/standard-ml.nix b/modules/plugins/languages/standard-ml.nix new file mode 100644 index 00000000..a64ad825 --- /dev/null +++ b/modules/plugins/languages/standard-ml.nix @@ -0,0 +1,114 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.options) literalExpression mkEnableOption mkOption; + inherit (lib.types) enum listOf; + inherit (lib.attrsets) attrNames genAttrs; + inherit (lib.generators) mkLuaInline; + inherit (lib.meta) getExe; + inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.types) mkTreesitterGrammarOption; + + cfg = config.vim.languages.standard-ml; + + defaultServers = ["millet"]; + servers = ["millet"]; + + defaultFormat = ["smlfmt"]; + formats = { + smlfmt = { + command = getExe pkgs.smlfmt; + stdin = false; + args = mkLuaInline '' + function(self, ctx) + return { + "--force", + "-tab-width", ctx.shiftwidth, + "-indent-width", ctx.shiftwidth, + "$FILENAME", + } + end + ''; + }; + }; +in { + options.vim.languages.standard-ml = { + enable = mkEnableOption "Standard ML support"; + + treesitter = { + enable = + mkEnableOption "Standard ML treesitter" + // { + default = config.vim.languages.enableTreesitter; + defaultText = literalExpression "config.vim.languages.enableTreesitter"; + }; + package = mkTreesitterGrammarOption pkgs "sml"; + }; + + lsp = { + enable = + mkEnableOption "Standard ML LSP support" + // { + default = config.vim.lsp.enable; + defaultText = literalExpression "config.vim.lsp.enable"; + }; + servers = mkOption { + type = listOf (enum servers); + default = defaultServers; + description = "Standard ML LSP server to use"; + }; + }; + + format = { + enable = + mkEnableOption "Standard ML formatting" + // { + default = config.vim.languages.enableFormat; + defaultText = literalExpression "config.vim.languages.enableFormat"; + }; + + type = mkOption { + description = "Standard ML formatter to use"; + type = listOf (enum (attrNames formats)); + default = defaultFormat; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter = { + enable = true; + grammars = [cfg.treesitter.package]; + }; + }) + + (mkIf cfg.lsp.enable { + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["sml"]; + }); + }; + }) + + (mkIf cfg.format.enable { + vim.formatter.conform-nvim = { + enable = true; + setupOpts = { + formatters_by_ft.sml = cfg.format.type; + formatters = + mapListToAttrs (name: { + inherit name; + value = formats.${name}; + }) + cfg.format.type; + }; + }; + }) + ]); +}