From 16f92ff8a6fe3681a8286e377054296c585935f4 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Thu, 23 Jan 2025 12:21:41 +0100 Subject: [PATCH] plugins/gx: init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strip `lib` from `lib.types.` Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> Fix settingsExample expression Co-authored-by: Matt Sturgeon Use '-version of options for better examples Fix indentation in example lua code Remove trailing space Replace use of literalLua with strings Revert to use literalLua Use lib.mkDefault Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> --- plugins/by-name/gx/default.nix | 122 ++++++++++++++++++ .../plugins/by-name/gx/default.nix | 64 +++++++++ 2 files changed, 186 insertions(+) create mode 100644 plugins/by-name/gx/default.nix create mode 100644 tests/test-sources/plugins/by-name/gx/default.nix diff --git a/plugins/by-name/gx/default.nix b/plugins/by-name/gx/default.nix new file mode 100644 index 0000000000..91623de19f --- /dev/null +++ b/plugins/by-name/gx/default.nix @@ -0,0 +1,122 @@ +{ lib, ... }: +let + inherit (lib.nixvim) defaultNullOpts; + inherit (lib) types; +in +lib.nixvim.plugins.mkNeovimPlugin { + name = "gx"; + packPathName = "gx.nvim"; + package = "gx-nvim"; + description = '' + Implementation of gx without the need of netrw. + ''; + + maintainers = [ lib.maintainers.jolars ]; + + extraOptions = { + disableNetrwGx = lib.mkOption { + default = true; + description = "Disable the `gx` mapping in netrw."; + type = types.bool; + }; + }; + + extraConfig = cfg: { + globals = lib.mkIf cfg.disableNetrwGx { + netrw_nogx = lib.mkDefault true; + }; + }; + + settingsOptions = { + open_browser_app = defaultNullOpts.mkStr null '' + Specify your browser app; default for macOS is `"open"`, Linux `"xdg-open"` + and Windows `"powershell.exe"`. + ''; + + open_browser_args = defaultNullOpts.mkListOf types.str [ ] '' + Arguments provided to the browser app, such as `--background` for macOS's `open`. + ''; + + handlers = defaultNullOpts.mkAttrsOf types.anything { } '' + Enable built-in handlers and configure custom ones. By default, all + handlers are disabled. To enable a built-in handler, set it to `true`. + ''; + + handler_options = { + search_engine = defaultNullOpts.mkStr "google" '' + Search engine to use when searching for text. Built-in options are + `"google"`, `"duckduckgo"`, `"ecosia"`, `"yandex"`, and `"bing"`. You + can also pass a custom search engine, such as + `"https://search.brave.com/search?q="`. + ''; + + select_for_search = defaultNullOpts.mkBool false '' + If your cursor is e.g. on a link, the pattern for the link AND for the word + will always match. This disables this behaviour for default so that the link is + opened without the select option for the word AND link. + ''; + + git_remotes = defaultNullOpts.mkListOf' { + type = types.str; + pluginDefault = [ + "upstream" + "origin" + ]; + description = '' + List of git remotes to search for git issue linking, in priority. + You can also pass a function. + ''; + example = lib.nixvim.literalLua '' + function(fname) + if fname:match("myproject") then + return { "mygit" } + end + return { "upstream", "origin" } + end + ''; + }; + + git_remote_push = defaultNullOpts.mkBool' { + type = types.bool; + pluginDefault = false; + description = '' + Whether to use the push url for git issue linking. + You can also pass a function. + ''; + example = lib.nixvim.literalLua '' + function(fname) + return fname:match("myproject") + end + ''; + }; + }; + }; + + settingsExample = lib.literalExpression '' + { + open_browser_args = [ "--background" ]; + handlers = { + rust = { + name = "rust"; + filetype = [ "toml" ]; + filename = "Cargo.toml"; + handle.__raw = ''' + function(mode, line, _) + local crate = require("gx.helper").find(line, mode, "(%w+)%s-=%s") + + if crate then + return "https://crates.io/crates/" .. crate + end + end + '''; + }; + }; + handler_options = { + search_engine = "duckduckgo"; + git_remotes = [ + "origin" + ]; + }; + }; + ''; +} diff --git a/tests/test-sources/plugins/by-name/gx/default.nix b/tests/test-sources/plugins/by-name/gx/default.nix new file mode 100644 index 0000000000..c1ca0b394c --- /dev/null +++ b/tests/test-sources/plugins/by-name/gx/default.nix @@ -0,0 +1,64 @@ +{ + empty = { + plugins.gx.enable = true; + }; + + default = { + plugins.gx = { + enable = true; + + disableNetrwGx = true; + + settings = { + open_browser_app = null; + open_browser_args = [ ]; + handlers = { }; + handler_options = { + search_engine = "google"; + select_for_search = false; + git_remotes = [ + "upstream" + "origin" + ]; + git_remote_push = false; + }; + }; + }; + }; + + example = { + plugins.gx = { + enable = true; + + settings = { + handlers = { + rust = { + name = "rust"; + filetype = [ "toml" ]; + filename = "Cargo.toml"; + handle.__raw = '' + function(mode, line, _) + local crate = require("gx.helper").find(line, mode, "(%w+)%s-=%s") + + if crate then + return "https://crates.io/crates/" .. crate + end + end + ''; + }; + }; + handler_options = { + search_engine = "duckduckgo"; + git_remotes.__raw = '' + function(fname) + if fname:match("myproject") then + return { "mygit" } + end + return { "upstream", "origin" } + end + ''; + }; + }; + }; + }; +}