From 824c852ec173d6029d8014b7eba26555711b4a55 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 18 Apr 2023 03:18:02 +0300 Subject: [PATCH] feat: refactor dart and elixir LSPs according to the new structure --- extra.nix | 2 + modules/languages/dart/config.nix | 60 +++++++++++++ modules/languages/dart/dart.nix | 90 +++++++++++++++++++ .../dart}/default.nix | 2 +- modules/languages/default.nix | 2 + modules/{lsp => languages}/elixir/config.nix | 3 +- modules/{lsp => languages}/elixir/default.nix | 0 modules/languages/elixir/elixir-tools.nix | 11 +++ modules/lsp/default.nix | 4 - modules/lsp/elixir/elixir-tools.nix | 10 --- modules/lsp/flutter-tools-nvim/config.nix | 33 ------- .../lsp/flutter-tools-nvim/flutter-tools.nix | 37 -------- 12 files changed, 167 insertions(+), 87 deletions(-) create mode 100644 modules/languages/dart/config.nix create mode 100644 modules/languages/dart/dart.nix rename modules/{lsp/flutter-tools-nvim => languages/dart}/default.nix (64%) rename modules/{lsp => languages}/elixir/config.nix (98%) rename modules/{lsp => languages}/elixir/default.nix (100%) create mode 100644 modules/languages/elixir/elixir-tools.nix delete mode 100644 modules/lsp/elixir/elixir-tools.nix delete mode 100644 modules/lsp/flutter-tools-nvim/config.nix delete mode 100644 modules/lsp/flutter-tools-nvim/flutter-tools.nix diff --git a/extra.nix b/extra.nix index 4765bcf..afa2df1 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 0000000..9866db4 --- /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 0000000..21bf960 --- /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 4cbe9c0..da454ec 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 b3b7d34..75d08ab 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 1b1e2a5..e0ef5f9 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 0000000..83da10f --- /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 a6f1e52..7f13e40 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 d3fe1ec..0000000 --- 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 2c97e90..0000000 --- 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 9bd460b..0000000 --- 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"; - }; - }; - }; - }; -}