mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-04-15 00:58:37 +00:00
language/dart: migrate to vim.lsp.servers
This commit is contained in:
parent
8a51914ba4
commit
bd164c5d43
2 changed files with 68 additions and 74 deletions
|
@ -118,6 +118,23 @@ in {
|
||||||
|
|
||||||
# 2025-04-05
|
# 2025-04-05
|
||||||
(mkRemovedOptionModule ["vim" "languages" "clang" "lsp" "opts"] lspOptRemovalMsg)
|
(mkRemovedOptionModule ["vim" "languages" "clang" "lsp" "opts"] lspOptRemovalMsg)
|
||||||
|
(mkRemovedOptionModule ["vim" "languages" "dart" "lsp" "opts"] lspOptRemovalMsg)
|
||||||
|
|
||||||
|
(mkRenamedOptionModule
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "color" "enable"]
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "setupOpts" "lsp" "color" "enabled"])
|
||||||
|
(mkRenamedOptionModule
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "color" "highlightBackground"]
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "setupOpts" "lsp" "color" "background"])
|
||||||
|
(mkRenamedOptionModule
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "color" "highlightForeground"]
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "setupOpts" "lsp" "color" "foreground"])
|
||||||
|
(mkRenamedOptionModule
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "color" "virtualText" "enable"]
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "setupOpts" "lsp" "color" "virtual_text"])
|
||||||
|
(mkRenamedOptionModule
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "color" "virtualText" "character"]
|
||||||
|
["vim" "languages" "dart" "flutter-tools" "setupOpts" "lsp" "color" "virtual_text_str"])
|
||||||
]
|
]
|
||||||
|
|
||||||
# Migrated via batchRenameOptions. Further batch renames must be below this line.
|
# Migrated via batchRenameOptions. Further batch renames must be below this line.
|
||||||
|
|
|
@ -5,35 +5,38 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) attrNames;
|
inherit (builtins) attrNames;
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.trivial) boolToString;
|
|
||||||
inherit (lib.lists) isList;
|
|
||||||
inherit (lib.options) mkEnableOption mkOption;
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
inherit (lib.types) enum either listOf package nullOr str bool;
|
inherit (lib.types) enum listOf bool attrsOf anything either nullOr;
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.nvim.lua) expToLua;
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.types) mkGrammarOption luaInline mkPluginSetupOption;
|
||||||
inherit (lib.nvim.dag) entryAnywhere;
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.languages.dart;
|
cfg = config.vim.languages.dart;
|
||||||
ftcfg = cfg.flutter-tools;
|
ftcfg = cfg.flutter-tools;
|
||||||
|
|
||||||
defaultServer = "dart";
|
defaultServer = ["dart"];
|
||||||
servers = {
|
servers = {
|
||||||
dart = {
|
dart.options = {
|
||||||
package = pkgs.dart;
|
cmd = [(getExe pkgs.dart) "language-server" "--protocol=lsp"];
|
||||||
lspConfig = ''
|
filetypes = ["dart"];
|
||||||
lspconfig.dartls.setup{
|
root_markers = ["pubspec.yaml"];
|
||||||
capabilities = capabilities;
|
init_options = {
|
||||||
on_attach=default_on_attach;
|
onlyAnalyzeProjectsWithOpenFiles = true;
|
||||||
cmd = ${
|
suggestFromUnimportedLibraries = true;
|
||||||
if isList cfg.lsp.package
|
closingLabels = true;
|
||||||
then expToLua cfg.lsp.package
|
outline = true;
|
||||||
else ''{"${cfg.lsp.package}/bin/dart", "language-server", "--protocol=lsp"}''
|
flutterOutline = true;
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
dart = {
|
||||||
|
completeFunctionCalls = true;
|
||||||
|
showTodos = true;
|
||||||
};
|
};
|
||||||
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"}
|
};
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
|
@ -49,21 +52,9 @@ in {
|
||||||
enable = mkEnableOption "Dart LSP support";
|
enable = mkEnableOption "Dart LSP support";
|
||||||
server = mkOption {
|
server = mkOption {
|
||||||
description = "The Dart LSP server to use";
|
description = "The Dart LSP server to use";
|
||||||
type = enum (attrNames servers);
|
type = listOf (enum (attrNames servers));
|
||||||
default = defaultServer;
|
default = defaultServer;
|
||||||
};
|
};
|
||||||
package = mkOption {
|
|
||||||
type = either package (listOf str);
|
|
||||||
default = servers.${cfg.lsp.server}.package;
|
|
||||||
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
|
|
||||||
description = "Dart LSP server package, or the command to run as a list of strings";
|
|
||||||
};
|
|
||||||
|
|
||||||
opts = mkOption {
|
|
||||||
type = nullOr str;
|
|
||||||
default = null;
|
|
||||||
description = "Options to pass to Dart LSP server";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dap = {
|
dap = {
|
||||||
|
@ -94,28 +85,29 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
color = {
|
setupOpts = mkPluginSetupOption "flutter-tools" {
|
||||||
enable = mkEnableOption "highlighting color variables";
|
lsp = {
|
||||||
|
# putting this here so that deprecation warnings in deprecations.nix can point to this
|
||||||
|
color = mkOption {
|
||||||
|
type = attrsOf anything;
|
||||||
|
default = {};
|
||||||
|
description = "Show derived colors for dart variables";
|
||||||
|
};
|
||||||
|
|
||||||
highlightBackground = mkOption {
|
capabilities = mkOption {
|
||||||
type = bool;
|
type = nullOr (either (attrsOf anything) luaInline);
|
||||||
default = false;
|
default = mkLuaInline "capabilities";
|
||||||
description = "Highlight the background";
|
description = "LSP capabilities";
|
||||||
};
|
};
|
||||||
|
|
||||||
highlightForeground = mkOption {
|
on_attach = mkOption {
|
||||||
type = bool;
|
type = luaInline;
|
||||||
default = false;
|
default = mkLuaInline "default_on_attach";
|
||||||
description = "Highlight the foreground";
|
description = "Lua function to run on attach";
|
||||||
};
|
};
|
||||||
|
|
||||||
virtualText = {
|
debugger = {
|
||||||
enable = mkEnableOption "Show the highlight using virtual text";
|
enabled = mkEnableOption "debugger support" // {default = cfg.dap.enable;};
|
||||||
|
|
||||||
character = mkOption {
|
|
||||||
type = str;
|
|
||||||
default = "■";
|
|
||||||
description = "Virtual text character to highlight";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -129,8 +121,12 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.servers =
|
||||||
vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig;
|
mapListToAttrs (name: {
|
||||||
|
inherit name;
|
||||||
|
value = servers.${name}.options;
|
||||||
|
})
|
||||||
|
cfg.lsp.server;
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf ftcfg.enable {
|
(mkIf ftcfg.enable {
|
||||||
|
@ -140,26 +136,7 @@ in {
|
||||||
else ["flutter-tools-nvim"];
|
else ["flutter-tools-nvim"];
|
||||||
|
|
||||||
vim.pluginRC.flutter-tools = entryAnywhere ''
|
vim.pluginRC.flutter-tools = entryAnywhere ''
|
||||||
require('flutter-tools').setup {
|
require('flutter-tools').setup(${toLuaObject ftcfg.setupOpts})
|
||||||
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,
|
|
||||||
},
|
|
||||||
${optionalString cfg.dap.enable ''
|
|
||||||
debugger = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
''}
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue