From 18bf52e540c745deb2c50fe3967cbe229a70bfe4 Mon Sep 17 00:00:00 2001 From: Soliprem <73885403+Soliprem@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:43:16 +0100 Subject: [PATCH] languages/gleam: init (#482) * modules/gleam: init * gleam: not using formatter * configuration: gleam set to false * docs: added changelog entry for gleam * gleam: fixed lsp and treesitter * gleam: capitalisation --- configuration.nix | 1 + docs/release-notes/rl-0.7.md | 1 + modules/plugins/languages/default.nix | 1 + modules/plugins/languages/gleam.nix | 71 +++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 modules/plugins/languages/gleam.nix diff --git a/configuration.nix b/configuration.nix index 723070a7..aadd1f83 100644 --- a/configuration.nix +++ b/configuration.nix @@ -65,6 +65,7 @@ isMaximal: { python.enable = isMaximal; dart.enable = isMaximal; bash.enable = isMaximal; + gleam.enable = false; r.enable = isMaximal; tailwind.enable = isMaximal; typst.enable = isMaximal; diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 6d6a83c5..59267ddf 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -359,6 +359,7 @@ The changes are, in no particular order: - Add LSP and Treesitter support for Assembly under `vim.languages.assembly` - Move [which-key](https://github.com/folke/which-key.nvim) to the new spec - Add LSP and Treesitter support for Nushell under `vim.languages.nu` +- Add LSP and Treesitter support for Gleam under `vim.languages.gleam` [Bloxx12](https://github.com/Bloxx12) diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 97b00910..a69d3e8d 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -9,6 +9,7 @@ in { ./clang.nix ./css.nix ./elixir.nix + ./gleam.nix ./go.nix ./hcl.nix ./kotlin.nix diff --git a/modules/plugins/languages/gleam.nix b/modules/plugins/languages/gleam.nix new file mode 100644 index 00000000..284d3443 --- /dev/null +++ b/modules/plugins/languages/gleam.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) enum either listOf package str; + inherit (lib.nvim.lua) expToLua; + inherit (lib.nvim.types) mkGrammarOption; + + cfg = config.vim.languages.gleam; + + defaultServer = "gleam"; + servers = { + gleam = { + package = pkgs.gleam; + lspConfig = '' + lspconfig.gleam.setup{ + capabilities = capabilities, + on_attach = default_on_attach, + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/gleam", "lsp"}'' + } + } + ''; + }; + }; +in { + options.vim.languages.gleam = { + enable = mkEnableOption "Gleam language support"; + + treesitter = { + enable = mkEnableOption "Gleam treesitter" // {default = config.vim.languages.enableTreesitter;}; + package = mkGrammarOption pkgs "gleam"; + }; + + lsp = { + enable = mkEnableOption "Gleam LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "Gleam LSP server to use"; + }; + + package = mkOption { + type = either package (listOf str); + default = servers.${cfg.lsp.server}.package; + description = "Gleam LSP server package, or the command to run as a list of strings"; + }; + }; + }; + + 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.gleam-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + ]); +}