diff --git a/modules/plugins/languages/kotlin.nix b/modules/plugins/languages/kotlin.nix index b4b3e772..869c9e28 100644 --- a/modules/plugins/languages/kotlin.nix +++ b/modules/plugins/languages/kotlin.nix @@ -6,7 +6,8 @@ }: let inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) package; + inherit (lib.types) package enum; + inherit (lib.attrsets) attrNames; inherit (lib.nvim.types) mkGrammarOption; inherit (lib.lists) isList; inherit (lib.nvim.lua) expToLua; @@ -27,6 +28,33 @@ --prefix PATH : ${pkgs.lib.makeBinPath [pkgs.kotlin]} ''; }; + + defaultFormat = "ktlint"; + formats = { + ktlint = { + package = pkgs.kitlint; + nullConfig = '' + table.insert( + ls_sources, + null_ls.builtins.formatting.typstfmt.with({ + command = "${cfg.format.package}/bin/ktlint", + }) + ) + ''; + }; + # https://github.com/Enter-tainer/typstyle + ktfmt = { + package = pkgs.ktfmt; + nullConfig = '' + table.insert( + ls_sources, + null_ls.builtins.formatting.typstfmt.with({ + command = "${cfg.format.package}/bin/ktfmt", + }) + ) + ''; + }; + }; in { options.vim.languages.kotlin = { enable = mkEnableOption "Kotlin/HCL support"; @@ -45,6 +73,21 @@ in { default = kotlinLspWithRuntime; }; }; + format = { + enable = mkEnableOption "Typst document formatting" // {default = config.vim.languages.enableFormat;}; + + type = mkOption { + description = "Kotlin formatter to use"; + type = enum (attrNames formats); + default = defaultFormat; + }; + + package = mkOption { + description = "Kotlin formatter package"; + type = package; + default = formats.${cfg.format.type}.package; + }; + }; }; config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable {