From ef3ab83254e51e42b17cde9322070eef565a06d6 Mon Sep 17 00:00:00 2001 From: Noah765 Date: Fri, 18 Apr 2025 15:49:11 +0200 Subject: [PATCH 1/4] languages/dart: add necessary dependency of flutter-tools.nvim on lsp --- docs/release-notes/rl-0.8.md | 1 + modules/plugins/languages/dart.nix | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 642599ba..f17ca59e 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -332,3 +332,4 @@ [Noah765](https://github.com/Noah765): - Add missing `flutter-tools.nvim` dependency `plenary.nvim`. +- Add necessary dependency of `flutter-tools.nvim` on lsp diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index 77d92d3b..d8d44d88 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -13,7 +13,7 @@ inherit (lib.strings) optionalString; inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.dag) entryAfter; cfg = config.vim.languages.dart; ftcfg = cfg.flutter-tools; @@ -122,19 +122,21 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config.vim = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { - vim.treesitter.enable = true; - vim.treesitter.grammars = [cfg.treesitter.package]; + treesitter.enable = true; + 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; + lsp.lspconfig.enable = true; + lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig; }) (mkIf ftcfg.enable { - vim.startPlugins = [ + lsp.enable = true; + + startPlugins = [ ( if ftcfg.enableNoResolvePatch then "flutter-tools-patched" @@ -143,7 +145,7 @@ in { "plenary-nvim" ]; - vim.pluginRC.flutter-tools = entryAnywhere '' + pluginRC.flutter-tools = entryAfter ["lsp-setup"] '' require('flutter-tools').setup { lsp = { color = { -- show the derived colours for dart variables From 99d600f40f4bf4d7b50524f760979886acab8ad7 Mon Sep 17 00:00:00 2001 From: Noah765 Date: Fri, 18 Apr 2025 15:51:03 +0200 Subject: [PATCH 2/4] languages/dart: remove invalid config key lsp.flags from flutter-tools.nvim setup The lsp.flags key is not present in the documentation of flutter-tools.nvim and lsp_flags always evaluates to nil. --- modules/plugins/languages/dart.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index d8d44d88..b3747099 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -158,7 +158,6 @@ in { capabilities = capabilities, on_attach = default_on_attach; - flags = lsp_flags, }, ${optionalString cfg.dap.enable '' debugger = { From df0e2060c6cd3471fb1964b99b8dc5bacd36c10e Mon Sep 17 00:00:00 2001 From: Noah765 Date: Fri, 18 Apr 2025 17:05:57 +0200 Subject: [PATCH 3/4] languages/dart: add flutter-tools.flutterPackage option Previously, flutter-tools was dependent on the flutter SDK, which it found in the PATH. Having such undeclared and non-reproducible dependencies is against the principles of nix. The flutterPackage option has been made optional for people who have installed the flutter SDK differently and want to keep it that way. The enableNoResolvePatch option has been retained for people who have installed the flutter SDK using nix outside the scope of nvf and do not want to have to install it twice. The default value has been changed to false, assuming that most people who use nix to install flutter will use the flutterPackage option instead. --- docs/release-notes/rl-0.8.md | 3 ++- modules/plugins/languages/dart.nix | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index f17ca59e..312b1896 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -332,4 +332,5 @@ [Noah765](https://github.com/Noah765): - Add missing `flutter-tools.nvim` dependency `plenary.nvim`. -- Add necessary dependency of `flutter-tools.nvim` on lsp +- Add necessary dependency of `flutter-tools.nvim` on lsp. +- Add the `vim.languages.dart.flutter-tools.flutterPackage` option. diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index b3747099..b61585d4 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -81,16 +81,23 @@ in { description = "Enable flutter-tools for flutter support"; }; + flutterPackage = mkOption { + type = nullOr package; + default = pkgs.flutter; + description = "Flutter package, or null to detect the flutter path at runtime instead."; + }; + enableNoResolvePatch = mkOption { type = bool; - default = true; + default = false; description = '' Whether to patch flutter-tools so that it doesn't resolve symlinks when detecting flutter path. - This is required if you want to use a flutter package built with nix. - If you are using a flutter SDK installed from a different source - and encounter the error "`dart` missing from PATH", disable this option. + This is required if flutterPackage is set to null and the flutter + package in your PATH was built with nix. If you are using a flutter + SDK installed from a different source and encounter the error "`dart` + missing from PATH", leave this option disabled. ''; }; @@ -147,6 +154,7 @@ in { pluginRC.flutter-tools = entryAfter ["lsp-setup"] '' require('flutter-tools').setup { + ${optionalString (ftcfg.flutterPackage != null) "flutter_path = \"${ftcfg.flutterPackage}/bin/flutter\","} 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 From 5db21bae6f9073bf08608449ba7ea50da4040c13 Mon Sep 17 00:00:00 2001 From: Noah765 Date: Sat, 19 Apr 2025 15:51:47 +0200 Subject: [PATCH 4/4] languages/dart: update flutter-tools.enableNoResolvePatch description --- modules/plugins/languages/dart.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index b61585d4..7b9584b9 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -94,10 +94,12 @@ in { Whether to patch flutter-tools so that it doesn't resolve symlinks when detecting flutter path. - This is required if flutterPackage is set to null and the flutter - package in your PATH was built with nix. If you are using a flutter + ::: {.note} + This is required if `flutterPackage` is set to null and the flutter + package in your `PATH` was built with Nix. If you are using a flutter SDK installed from a different source and encounter the error "`dart` - missing from PATH", leave this option disabled. + missing from `PATH`", leave this option disabled. + ::: ''; };