diff --git a/extra.nix b/extra.nix index 4765bcfd..afa2df10 100644 --- a/extra.nix +++ b/extra.nix @@ -57,6 +57,8 @@ inputs: let go.enable = isMaximal; zig.enable = isMaximal; python.enable = isMaximal; + dart.enable = isMaximal; + elixir.enable = isMaximal; }; vim.visuals = { diff --git a/modules/languages/dart/config.nix b/modules/languages/dart/config.nix new file mode 100644 index 00000000..9866db40 --- /dev/null +++ b/modules/languages/dart/config.nix @@ -0,0 +1,60 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +with builtins; let + cfg = config.vim.languages.dart; + ftcfg = cfg.flutter-tools; + servers = { + dart = { + package = pkgs.dart; + lspConfig = '' + lspconfig.dart.setup{ + capabilities = capabilities; + on_attach=default_on_attach; + cmd = {"${pkgs.dart}/bin/dart"}; + ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"} + } + ''; + }; + }; +in { + 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.dart-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + + (mkIf (ftcfg.enable) { + vim.startPlugins = ["flutter-tools"]; + + vim.luaConfigRC.flutter-tools = nvim.dag.entryAnywhere '' + require('flutter-tools').setup { + lsp = { + color = { -- show the derived colours for dart variables + enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 + background = ${boolToString ftcfg.color.highlightBackground}, -- highlight the background + foreground = ${boolToString ftcfg.color.highlightForeground}, -- highlight the foreground + virtual_text = ${boolToString ftcfg.color.virtualText.enable}, -- show the highlight using virtual text + virtual_text_str = ${ftcfg.color.virtualText.character} -- the virtual text character to highlight + }, + + capabilities = capabilities, + on_attach = default_on_attach; + flags = lsp_flags, + }, + } + + ''; + }) + ]); +} diff --git a/modules/languages/dart/dart.nix b/modules/languages/dart/dart.nix new file mode 100644 index 00000000..21bf9600 --- /dev/null +++ b/modules/languages/dart/dart.nix @@ -0,0 +1,90 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +with builtins; let + cfg = config.vim.languages.dart; + defaultServer = "dart"; + servers = { + dart = { + package = pkgs.dart; + lspConfig = '' + lspconfig.dart.setup{ + capabilities = capabilities; + on_attach=default_on_attach; + cmd = {"${pkgs.dart}/bin/dart"}; + ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"} + } + ''; + }; + }; +in { + options.vim.languages.dart = { + enable = mkEnableOption "Dart language support"; + + treesitter = { + enable = mkOption { + description = "Enable Dart treesitter"; + type = types.bool; + default = config.vim.languages.enableTreesitter; + }; + package = nvim.types.mkGrammarOption pkgs "dart"; + }; + + lsp = { + enable = mkOption { + description = "Enable Dart LSP support"; + type = types.bool; + default = config.vim.languages.enableLSP; + }; + server = mkOption { + description = "The Dart LSP server to use"; + type = with types; enum (attrNames servers); + default = defaultServer; + }; + package = mkOption { + description = "Dart LSP server package"; + type = types.package; + default = servers.${cfg.lsp.server}.package; + }; + opts = mkOption { + description = "Options to pass to Dart LSP server"; + type = with types; nullOr str; + default = null; + }; + }; + + flutter-tools = { + enable = mkEnableOption "Enable flutter-tools for flutter support"; + + color = { + enable = mkEnableOption "Whether or mot to highlight color variables at all"; + + highlightBackground = mkOption { + type = types.bool; + default = false; + description = "Highlight the background"; + }; + + highlightForeground = mkOption { + type = types.bool; + default = false; + description = "Highlight the foreground"; + }; + + virtualText = { + enable = mkEnableOption "Show the highlight using virtual text"; + + character = mkOption { + type = types.str; + default = "■"; + description = "Virtual text character to highlight"; + }; + }; + }; + }; + }; +} diff --git a/modules/lsp/flutter-tools-nvim/default.nix b/modules/languages/dart/default.nix similarity index 64% rename from modules/lsp/flutter-tools-nvim/default.nix rename to modules/languages/dart/default.nix index 4cbe9c02..da454ec0 100644 --- a/modules/lsp/flutter-tools-nvim/default.nix +++ b/modules/languages/dart/default.nix @@ -1,6 +1,6 @@ _: { imports = [ - ./flutter-tools.nix + ./dart.nix ./config.nix ]; } diff --git a/modules/languages/default.nix b/modules/languages/default.nix index b3b7d348..75d08abe 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -10,6 +10,8 @@ in { imports = [ ./markdown ./tidal + ./dart + ./elixir ./clang.nix ./go.nix diff --git a/modules/lsp/elixir/config.nix b/modules/languages/elixir/config.nix similarity index 98% rename from modules/lsp/elixir/config.nix rename to modules/languages/elixir/config.nix index 1b1e2a5a..e0ef5f9d 100644 --- a/modules/lsp/elixir/config.nix +++ b/modules/languages/elixir/config.nix @@ -6,12 +6,11 @@ }: with lib; with builtins; let - cfg = config.vim.lsp.elixir; + cfg = config.vim.languages.elixir; in { config = mkIf (cfg.enable) { vim.startPlugins = [ "elixir-tools" - "plenary-nvim" ]; vim.luaConfigRC.elixir-tools = nvim.dag.entryAnywhere '' diff --git a/modules/lsp/elixir/default.nix b/modules/languages/elixir/default.nix similarity index 100% rename from modules/lsp/elixir/default.nix rename to modules/languages/elixir/default.nix diff --git a/modules/languages/elixir/elixir-tools.nix b/modules/languages/elixir/elixir-tools.nix new file mode 100644 index 00000000..83da10fc --- /dev/null +++ b/modules/languages/elixir/elixir-tools.nix @@ -0,0 +1,11 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; { + options.vim.languages.elixir = { + enable = mkEnableOption "elixir support"; + }; +} diff --git a/modules/lsp/default.nix b/modules/lsp/default.nix index a6f1e52e..7f13e405 100644 --- a/modules/lsp/default.nix +++ b/modules/lsp/default.nix @@ -15,9 +15,5 @@ _: { ./lsp-signature ./lightbulb ./lspkind - - # language specific modules - ./flutter-tools-nvim # dart & flutter - ./elixir # elixir ]; } diff --git a/modules/lsp/elixir/elixir-tools.nix b/modules/lsp/elixir/elixir-tools.nix deleted file mode 100644 index d3fe1ec2..00000000 --- a/modules/lsp/elixir/elixir-tools.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ - config, - lib, - ... -}: -with lib; -with builtins; { - options.vim.lsp.elixir = { - }; -} diff --git a/modules/lsp/flutter-tools-nvim/config.nix b/modules/lsp/flutter-tools-nvim/config.nix deleted file mode 100644 index 2c97e90b..00000000 --- a/modules/lsp/flutter-tools-nvim/config.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ - config, - lib, - ... -}: -with lib; -with builtins; let - cfg = config.vim.lsp; - ftcfg = cfg.dart.flutter-tools; -in { - config = mkIf (cfg.enable && ftcfg.enable) { - vim.startPlugins = ["flutter-tools"]; - - vim.luaConfigRC.flutter-tools = nvim.dag.entryAnywhere '' - require('flutter-tools').setup { - lsp = { - color = { -- show the derived colours for dart variables - enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 - background = ${boolToString ftcfg.color.highlightBackground}, -- highlight the background - foreground = ${boolToString ftcfg.color.highlightForeground}, -- highlight the foreground - virtual_text = ${boolToString ftcfg.color.virtualText.enable}, -- show the highlight using virtual text - virtual_text_str = ${ftcfg.color.virtualText.character} -- the virtual text character to highlight - }, - - capabilities = capabilities, - on_attach = default_on_attach; - flags = lsp_flags, - }, - } - - ''; - }; -} diff --git a/modules/lsp/flutter-tools-nvim/flutter-tools.nix b/modules/lsp/flutter-tools-nvim/flutter-tools.nix deleted file mode 100644 index 9bd460be..00000000 --- a/modules/lsp/flutter-tools-nvim/flutter-tools.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ - config, - lib, - ... -}: -with lib; -with builtins; { - options.vim.lsp.dart.flutter-tools = { - enable = mkEnableOption "Enable flutter-tools for flutter support"; - - color = { - enable = mkEnableOption "Whether or mot to highlight color variables at all"; - - highlightBackground = mkOption { - type = types.bool; - default = false; - description = "Highlight the background"; - }; - - highlightForeground = mkOption { - type = types.bool; - default = false; - description = "Highlight the foreground"; - }; - - virtualText = { - enable = mkEnableOption "Show the highlight using virtual text"; - - character = mkOption { - type = types.str; - default = "■"; - description = "Virtual text character to highlight"; - }; - }; - }; - }; -}