From 14179505b3ad2148c6a6f8c6d31a7510b6eb134d Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 19 Jul 2023 22:49:06 +0300 Subject: [PATCH] feat: breadcrumbs --- configuration.nix | 6 +- flake.lock | 34 ++++++ flake.nix | 12 ++ lib/types/plugins.nix | 2 + modules/ui/breadcrumbs/breadcrumbs.nix | 5 + modules/ui/breadcrumbs/config.nix | 157 +++++++++++++++++++++++++ modules/ui/breadcrumbs/default.nix | 6 + modules/ui/default.nix | 1 + 8 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 modules/ui/breadcrumbs/breadcrumbs.nix create mode 100644 modules/ui/breadcrumbs/config.nix create mode 100644 modules/ui/breadcrumbs/default.nix diff --git a/configuration.nix b/configuration.nix index a38a2da..588dc62 100644 --- a/configuration.nix +++ b/configuration.nix @@ -54,7 +54,10 @@ inputs: let nix.enable = true; html.enable = isMaximal; - clang.enable = isMaximal; + clang = { + enable = isMaximal; + lsp.server = "clangd"; + }; sql.enable = isMaximal; rust = { enable = isMaximal; @@ -189,6 +192,7 @@ inputs: let colorizer.enable = true; modes-nvim.enable = false; # the theme looks terrible with catppuccin illuminate.enable = true; + breadcrumbs.enable = true; smartcolumn = { enable = true; columnAt.languages = { diff --git a/flake.lock b/flake.lock index 69727ee..5064370 100644 --- a/flake.lock +++ b/flake.lock @@ -1077,6 +1077,38 @@ "type": "github" } }, + "nvim-navbuddy": { + "flake": false, + "locked": { + "lastModified": 1688569844, + "narHash": "sha256-011RT/wnQdBR1vMrXFwxbicBAgdcd4eQYPbok/o3CIE=", + "owner": "SmiteshP", + "repo": "nvim-navbuddy", + "rev": "244a4cded6f2b568403684131d148048efe4e8af", + "type": "github" + }, + "original": { + "owner": "SmiteshP", + "repo": "nvim-navbuddy", + "type": "github" + } + }, + "nvim-navic": { + "flake": false, + "locked": { + "lastModified": 1689447657, + "narHash": "sha256-fcSer6l6oX0qnOcRfNSZImmtkqjdH0WSUkptjaFj0AI=", + "owner": "SmiteshP", + "repo": "nvim-navic", + "rev": "e6da6f74d89de65258ea7e98e22103ff5de6dcf5", + "type": "github" + }, + "original": { + "owner": "SmiteshP", + "repo": "nvim-navic", + "type": "github" + } + }, "nvim-neoclip": { "flake": false, "locked": { @@ -1397,6 +1429,8 @@ "nvim-dap-ui": "nvim-dap-ui", "nvim-lightbulb": "nvim-lightbulb", "nvim-lspconfig": "nvim-lspconfig", + "nvim-navbuddy": "nvim-navbuddy", + "nvim-navic": "nvim-navic", "nvim-neoclip": "nvim-neoclip", "nvim-notify": "nvim-notify", "nvim-session-manager": "nvim-session-manager", diff --git a/flake.nix b/flake.nix index 67d3825..43df359 100644 --- a/flake.nix +++ b/flake.nix @@ -143,6 +143,7 @@ url = "github:tversteeg/registers.nvim"; flake = false; }; + nvim-neoclip = { url = "github:AckslD/nvim-neoclip.lua"; flake = false; @@ -248,6 +249,7 @@ url = "github:b3nj5m1n/kommentary"; flake = false; }; + comment-nvim = { url = "github:numToStr/Comment.nvim"; flake = false; @@ -455,6 +457,16 @@ }; # UI + nvim-navbuddy = { + url = "github:SmiteshP/nvim-navbuddy"; + flake = false; + }; + + nvim-navic = { + url = "github:SmiteshP/nvim-navic"; + flake = false; + }; + noice-nvim = { url = "github:folke/noice.nvim"; flake = false; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 111fd8c..854ac6e 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -87,6 +87,8 @@ with lib; let "nvim-surround" "nvim-dap" "nvim-dap-ui" + "nvim-navic" + "nvim-navbuddy" ]; # You can either use the name of the plugin or a package. pluginsType = with types; diff --git a/modules/ui/breadcrumbs/breadcrumbs.nix b/modules/ui/breadcrumbs/breadcrumbs.nix new file mode 100644 index 0000000..6583b8f --- /dev/null +++ b/modules/ui/breadcrumbs/breadcrumbs.nix @@ -0,0 +1,5 @@ +{lib, ...}: { + options.vim.ui.breadcrumbs = { + enable = lib.mkEnableOption "breadcrumbs"; + }; +} diff --git a/modules/ui/breadcrumbs/config.nix b/modules/ui/breadcrumbs/config.nix new file mode 100644 index 0000000..38e0703 --- /dev/null +++ b/modules/ui/breadcrumbs/config.nix @@ -0,0 +1,157 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.ui.breadcrumbs; +in { + config = mkIf cfg.enable { + vim.startPlugins = [ + "nvim-navbuddy" + "nvim-navic" + "nvim-lspconfig" + ]; + + vim.luaConfigRC.breadcrumbs = nvim.dag.entryAfter ["lspconfig"] '' + local navbuddy = require("nvim-navbuddy") + local actions = require("nvim-navbuddy.actions") + + require("lspconfig").clangd.setup { + on_attach = function(client, bufnr) + navbuddy.attach(client, bufnr) + end + } + + navbuddy.setup { + window = { + border = "single", -- "rounded", "double", "solid", "none" + -- or an array with eight chars building up the border in a clockwise fashion + -- starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }. + size = "60%", -- Or table format example: { height = "40%", width = "100%"} + position = "50%", -- Or table format example: { row = "100%", col = "0%"} + scrolloff = nil, -- scrolloff value within navbuddy window + sections = { + left = { + size = "20%", + border = nil, -- You can set border style for each section individually as well. + }, + mid = { + size = "40%", + border = nil, + }, + right = { + -- No size option for right most section. It fills to + -- remaining area. + border = nil, + preview = "leaf", -- Right section can show previews too. + -- Options: "leaf", "always" or "never" + } + }, + }, + node_markers = { + enabled = true, + icons = { + leaf = " ", + leaf_selected = " → ", + branch = " ", + }, + }, + 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 = "󰊄 ", + }, + use_default_mappings = true, -- If set to false, only mappings set + -- by user are set. Else default + -- mappings are used for keys + -- that are not set by user + mappings = { + [""] = actions.close(), -- Close and cursor to original location + ["q"] = actions.close(), + + ["j"] = actions.next_sibling(), -- down + ["k"] = actions.previous_sibling(), -- up + + ["h"] = actions.parent(), -- Move to left panel + ["l"] = actions.children(), -- Move to right panel + ["0"] = actions.root(), -- Move to first panel + + ["v"] = actions.visual_name(), -- Visual selection of name + ["V"] = actions.visual_scope(), -- Visual selection of scope + + ["y"] = actions.yank_name(), -- Yank the name to system clipboard "+ + ["Y"] = actions.yank_scope(), -- Yank the scope to system clipboard "+ + + ["i"] = actions.insert_name(), -- Insert at start of name + ["I"] = actions.insert_scope(), -- Insert at start of scope + + ["a"] = actions.append_name(), -- Insert at end of name + ["A"] = actions.append_scope(), -- Insert at end of scope + + ["r"] = actions.rename(), -- Rename currently focused symbol + + ["d"] = actions.delete(), -- Delete scope + + ["f"] = actions.fold_create(), -- Create fold of current scope + ["F"] = actions.fold_delete(), -- Delete fold of current scope + + ["c"] = actions.comment(), -- Comment out current scope + + [""] = actions.select(), -- Goto selected symbol + ["o"] = actions.select(), + + ["J"] = actions.move_down(), -- Move focused node down + ["K"] = actions.move_up(), -- Move focused node up + + ["t"] = actions.telescope({ -- Fuzzy finder at current level. + layout_config = { -- All options that can be + height = 0.60, -- passed to telescope.nvim's + width = 0.60, -- default can be passed here. + prompt_position = "top", + preview_width = 0.50 + }, + layout_strategy = "horizontal" + }), + + ["g?"] = actions.help(), -- Open mappings help window + }, + lsp = { + auto_attach = false, -- If set to true, you don't need to manually use attach function + preference = nil, -- list of lsp server names in order of preference + }, + source_buffer = { + follow_node = true, -- Keep the current node in focus on the source buffer + highlight = true, -- Highlight the currently focused node + reorient = "smart", -- "smart", "top", "mid" or "none" + scrolloff = nil -- scrolloff value when navbuddy is open + } + } + + ''; + }; +} diff --git a/modules/ui/breadcrumbs/default.nix b/modules/ui/breadcrumbs/default.nix new file mode 100644 index 0000000..02c6351 --- /dev/null +++ b/modules/ui/breadcrumbs/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./config.nix + ./breadcrumbs.nix + ]; +} diff --git a/modules/ui/default.nix b/modules/ui/default.nix index 980a04a..1c63c40 100644 --- a/modules/ui/default.nix +++ b/modules/ui/default.nix @@ -6,5 +6,6 @@ _: { ./smartcolumn ./colorizer ./illuminate + ./breadcrumbs ]; }