From 78b6f8e1e5b37a7789216e17a96ebc117660f0e7 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 29 Jan 2025 11:39:27 +0100 Subject: [PATCH] plugins/easy-dotnet: init --- plugins/by-name/easy-dotnet/default.nix | 54 +++++ .../plugins/by-name/easy-dotnet/default.nix | 186 ++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 plugins/by-name/easy-dotnet/default.nix create mode 100644 tests/test-sources/plugins/by-name/easy-dotnet/default.nix diff --git a/plugins/by-name/easy-dotnet/default.nix b/plugins/by-name/easy-dotnet/default.nix new file mode 100644 index 00000000..ee0eff59 --- /dev/null +++ b/plugins/by-name/easy-dotnet/default.nix @@ -0,0 +1,54 @@ +{ lib, config, ... }: +lib.nixvim.plugins.mkNeovimPlugin { + name = "easy-dotnet"; + packPathName = "easy-dotnet.nvim"; + package = "easy-dotnet-nvim"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + settingsExample = lib.literalExpression '' + { + test_runner = { + enable_buffer_test_execution = true; + viewmode = "float"; + }; + auto_bootstrap_namespace = true; + terminal.__raw = ''' + function(path, action, args) + local commands = { + run = function() + return string.format("dotnet run --project %s %s", path, args) + end, + test = function() + return string.format("dotnet test %s %s", path, args) + end, + restore = function() + return string.format("dotnet restore %s %s", path, args) + end, + build = function() + return string.format("dotnet build %s %s", path, args) + end, + } + + local command = commands[action]() .. "\r" + require("toggleterm").exec(command, nil, nil, nil, "float") + end + '''; + picker = "fzf"; + } + ''; + + extraConfig = cfg: { + warnings = lib.nixvim.mkWarnings "plugins.easy-dotnet" ( + lib.mapAttrsToList + (pickerName: pluginName: { + when = (cfg.settings.picker or null == pickerName) && (!config.plugins.${pluginName}.enable); + message = "You have chosen to use '${pickerName}' as a picker but 'plugins.${pluginName}' is not enabled."; + }) + { + fzf = "fzf-lua"; + telescope = "telescope"; + } + ); + }; +} diff --git a/tests/test-sources/plugins/by-name/easy-dotnet/default.nix b/tests/test-sources/plugins/by-name/easy-dotnet/default.nix new file mode 100644 index 00000000..05cb2564 --- /dev/null +++ b/tests/test-sources/plugins/by-name/easy-dotnet/default.nix @@ -0,0 +1,186 @@ +{ + empty = { + plugins.easy-dotnet.enable = true; + }; + + defaults = { + plugins = { + telescope.enable = true; + web-devicons.enable = true; + easy-dotnet = { + enable = true; + + settings = { + get_sdk_path.__raw = '' + function() + local sdk_version = vim.trim(vim.fn.system("dotnet --version")) + local sdk_list = vim.trim(vim.fn.system("dotnet --list-sdks")) + local base = nil + for line in sdk_list:gmatch("[^\n]+") do + if line:find(sdk_version, 1, true) then + base = vim.fs.normalize(line:match("%[(.-)%]")) + break + end + end + local sdk_path = polyfills.fs.joinpath(base, sdk_version):gsub("Program Files", '"Program Files"') + return sdk_path + end + ''; + terminal.__raw = '' + function(path, action, args) + local commands = { + run = function() return string.format("dotnet run --project %s %s", path, args) end, + test = function() return string.format("dotnet test %s %s", path, args) end, + restore = function() return string.format("dotnet restore %s %s", path, args) end, + build = function() return string.format("dotnet build %s %s", path, args) end, + } + local command = commands[action]() + if require("easy-dotnet.extensions").isWindows() == true then command = command .. "\r" end + vim.cmd("vsplit") + vim.cmd("term " .. command) + end + ''; + secrets = { + path.__raw = '' + function() + local path = "" + local home_dir = vim.fn.expand("~") + if require("easy-dotnet.extensions").isWindows() then + local secret_path = home_dir .. "\\AppData\\Roaming\\Microsoft\\UserSecrets\\" .. secret_guid .. "\\secrets.json" + path = secret_path + else + local secret_path = home_dir .. "/.microsoft/usersecrets/" .. secret_guid .. "/secrets.json" + path = secret_path + end + return path + end + ''; + }; + test_runner = { + viewmode = "split"; + enable_buffer_test_execution = true; + noBuild = true; + noRestore = true; + icons = { + passed = ""; + skipped = ""; + failed = ""; + success = ""; + reload = ""; + test = ""; + sln = "󰘐"; + project = "󰘐"; + dir = ""; + package = ""; + }; + mappings = { + run_test_from_buffer = { + lhs = "r"; + desc = "run test from buffer"; + }; + debug_test_from_buffer = { + lhs = "d"; + desc = "run test from buffer"; + }; + filter_failed_tests = { + lhs = "fe"; + desc = "filter failed tests"; + }; + debug_test = { + lhs = "d"; + desc = "debug test"; + }; + go_to_file = { + lhs = "g"; + desc = "go to file"; + }; + run_all = { + lhs = "R"; + desc = "run all tests"; + }; + run = { + lhs = "r"; + desc = "run test"; + }; + peek_stacktrace = { + lhs = "p"; + desc = "peek stacktrace of failed test"; + }; + expand = { + lhs = "o"; + desc = "expand"; + }; + expand_node = { + lhs = "E"; + desc = "expand node"; + }; + expand_all = { + lhs = "-"; + desc = "expand all"; + }; + collapse_all = { + lhs = "W"; + desc = "collapse all"; + }; + close = { + lhs = "q"; + desc = "close testrunner"; + }; + refresh_testrunner = { + lhs = ""; + desc = "refresh testrunner"; + }; + }; + additional_args = [ ]; + }; + csproj_mappings = true; + fsproj_mappings = true; + auto_bootstrap_namespace = { + type = "block_scoped"; + enabled = true; + }; + picker = "telescope"; + }; + }; + }; + }; + + example = { + plugins = { + fzf-lua.enable = true; + easy-dotnet = { + enable = true; + + settings = { + test_runner = { + enable_buffer_test_execution = true; + viewmode = "float"; + }; + auto_bootstrap_namespace = true; + terminal.__raw = '' + function(path, action, args) + local commands = { + run = function() + return string.format("dotnet run --project %s %s", path, args) + end, + test = function() + return string.format("dotnet test %s %s", path, args) + end, + restore = function() + return string.format("dotnet restore %s %s", path, args) + end, + build = function() + return string.format("dotnet build %s %s", path, args) + end, + } + + local command = commands[action]() .. "\r" + require("toggleterm").exec(command, nil, nil, nil, "float") + end + ''; + picker = "fzf"; + }; + }; + }; + }; +}