feat: refactor dart and elixir LSPs according to the new structure

This commit is contained in:
NotAShelf 2023-04-18 03:18:02 +03:00
parent 07d5aee29c
commit 824c852ec1
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
12 changed files with 167 additions and 87 deletions

View file

@ -57,6 +57,8 @@ inputs: let
go.enable = isMaximal; go.enable = isMaximal;
zig.enable = isMaximal; zig.enable = isMaximal;
python.enable = isMaximal; python.enable = isMaximal;
dart.enable = isMaximal;
elixir.enable = isMaximal;
}; };
vim.visuals = { vim.visuals = {

View file

@ -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,
},
}
'';
})
]);
}

View file

@ -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";
};
};
};
};
};
}

View file

@ -1,6 +1,6 @@
_: { _: {
imports = [ imports = [
./flutter-tools.nix ./dart.nix
./config.nix ./config.nix
]; ];
} }

View file

@ -10,6 +10,8 @@ in {
imports = [ imports = [
./markdown ./markdown
./tidal ./tidal
./dart
./elixir
./clang.nix ./clang.nix
./go.nix ./go.nix

View file

@ -6,12 +6,11 @@
}: }:
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.lsp.elixir; cfg = config.vim.languages.elixir;
in { in {
config = mkIf (cfg.enable) { config = mkIf (cfg.enable) {
vim.startPlugins = [ vim.startPlugins = [
"elixir-tools" "elixir-tools"
"plenary-nvim"
]; ];
vim.luaConfigRC.elixir-tools = nvim.dag.entryAnywhere '' vim.luaConfigRC.elixir-tools = nvim.dag.entryAnywhere ''

View file

@ -0,0 +1,11 @@
{
config,
lib,
...
}:
with lib;
with builtins; {
options.vim.languages.elixir = {
enable = mkEnableOption "elixir support";
};
}

View file

@ -15,9 +15,5 @@ _: {
./lsp-signature ./lsp-signature
./lightbulb ./lightbulb
./lspkind ./lspkind
# language specific modules
./flutter-tools-nvim # dart & flutter
./elixir # elixir
]; ];
} }

View file

@ -1,10 +0,0 @@
{
config,
lib,
...
}:
with lib;
with builtins; {
options.vim.lsp.elixir = {
};
}

View file

@ -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,
},
}
'';
};
}

View file

@ -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";
};
};
};
};
}