From 32a64af2318beac3c89d4d1fa0b73ce237c5cf1e Mon Sep 17 00:00:00 2001 From: Haseeb Majid Date: Thu, 21 Sep 2023 13:48:05 +0100 Subject: [PATCH] plugins/navic: init + tests (#597) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Haseeb Majid Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> --- plugins/bufferlines/navic.nix | 121 ++++++++++++++++++ plugins/default.nix | 1 + .../plugins/bufferlines/navic.nix | 49 +++++++ 3 files changed, 171 insertions(+) create mode 100644 plugins/bufferlines/navic.nix create mode 100644 tests/test-sources/plugins/bufferlines/navic.nix diff --git a/plugins/bufferlines/navic.nix b/plugins/bufferlines/navic.nix new file mode 100644 index 00000000..0d187c54 --- /dev/null +++ b/plugins/bufferlines/navic.nix @@ -0,0 +1,121 @@ +{ + lib, + pkgs, + config, + ... +}: +with lib; let + cfg = config.plugins.navic; + helpers = import ../helpers.nix {inherit lib;}; + mkListStr = helpers.defaultNullOpts.mkNullable (types.listOf types.str); +in { + options.plugins.navic = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "nvim-navic"; + + package = helpers.mkPackageOption "nvim-navic" pkgs.vimPlugins.nvim-navic; + + icons = + mapAttrs + ( + name: default: + helpers.defaultNullOpts.mkStr default "icon for ${name}." + ) + { + File = "󰈙 "; + Module = " "; + Namespace = "󰌗 "; + Package = " "; + Class = "󰌗 "; + Method = "󰆧 "; + Property = " "; + Field = " "; + Constructor = " "; + Enum = "󰕘"; + Interface = "󰕘"; + Function = "󰊕 "; + Variable = "󰆧 "; + Constant = "󰏿 "; + String = "󰀬 "; + Number = "󰎠 "; + Boolean = "◩ "; + Array = "󰅪 "; + Object = "󰅩 "; + Key = "󰌋 "; + Null = "󰟢 "; + EnumMember = " "; + Struct = "󰌗 "; + Event = " "; + Operator = "󰆕 "; + TypeParameter = "󰊄 "; + }; + + lsp = { + autoAttach = helpers.defaultNullOpts.mkBool false '' + Enable to have nvim-navic automatically attach to every LSP for current buffer. Its disabled by default. + ''; + + preference = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" '' + Table ranking lsp_servers. Lower the index, higher the priority of the server. If there are more than one server attached to a buffer. In the example below will prefer clangd over pyright + + Example: `[ "clangd" "pyright" ]`. + ''; + }; + + highlight = helpers.defaultNullOpts.mkBool false '' + If set to true, will add colors to icons and text as defined by highlight groups NavicIcons* (NavicIconsFile, NavicIconsModule.. etc.), NavicText and NavicSeparator. + ''; + + separator = helpers.defaultNullOpts.mkStr " > " '' + Icon to separate items. to use between items. + ''; + + depthLimit = helpers.defaultNullOpts.mkInt 0 '' + Maximum depth of context to be shown. If the context hits this depth limit, it is truncated. + ''; + + depthLimitIndicator = helpers.defaultNullOpts.mkStr ".." '' + Icon to indicate that depth_limit was hit and the shown context is truncated. + ''; + + safeOutput = helpers.defaultNullOpts.mkBool true '' + Sanitize the output for use in statusline and winbar. + ''; + + lazyUpdateContext = helpers.defaultNullOpts.mkBool false '' + If true, turns off context updates for the "CursorMoved" event. + ''; + + click = helpers.defaultNullOpts.mkBool false '' + Single click to goto element, double click to open nvim-navbuddy on the clicked element. + ''; + }; + + config = let + setupOptions = with cfg; + { + inherit + icons + highlight + separator + click + ; + lsp = with lsp; { + auto_attach = autoAttach; + inherit preference; + }; + depth_limit = depthLimit; + safe_output = safeOutput; + lazy_update_context = lazyUpdateContext; + } + // cfg.extraOptions; + in + mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = '' + require('nvim-navic').setup(${helpers.toLuaObject setupOptions}) + ''; + }; +} diff --git a/plugins/default.nix b/plugins/default.nix index a62a626f..660a2642 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -2,6 +2,7 @@ imports = [ ./bufferlines/barbar.nix ./bufferlines/bufferline.nix + ./bufferlines/navic.nix ./colorschemes/ayu.nix ./colorschemes/base16.nix diff --git a/tests/test-sources/plugins/bufferlines/navic.nix b/tests/test-sources/plugins/bufferlines/navic.nix new file mode 100644 index 00000000..c5e76a24 --- /dev/null +++ b/tests/test-sources/plugins/bufferlines/navic.nix @@ -0,0 +1,49 @@ +{ + empty = { + plugins.navic.enable = true; + }; + + defaults = { + plugins.navic = { + enable = true; + + icons = { + File = "󰆧 "; + Module = " "; + Namespace = "󰌗 "; + Package = " "; + Class = "󰌗 "; + Method = "󰆧 "; + Property = " "; + Field = " "; + Constructor = " "; + Enum = "󰕘"; + Interface = "󰕘"; + Function = "󰊕 "; + Variable = "󰆧 "; + Constant = "󰏿 "; + String = "󰀬 "; + Number = "󰎠 "; + Boolean = "◩ "; + Array = "󰅪 "; + Object = "󰅩 "; + Key = "󰌋 "; + Null = "󰟢 "; + EnumMember = " "; + Struct = "󰌗 "; + Event = " "; + Operator = "󰆕 "; + TypeParameter = "󰊄 "; + }; + lsp = { + autoAttach = true; + preference = ["clangd" "pyright"]; + }; + highlight = true; + separator = " | "; + depthLimit = 10; + safeOutput = false; + click = true; + }; + }; +}