diff --git a/README.md b/README.md index b816b02..3f05c89 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,39 @@ outline. This section may be relevant to you if your existing config uses the mentioned features: +- **Config**: Configuration options have been significantly restructured to +provide better consistency and understandability. Please see the [default config](#configuration) for an example of the full list. + - Options that control the looks +and behaviour of outline window is now moved to `outline_window` table; + - Options that control the items that show up are now in `outline_items` + - Options for the preview window is in `preview_window`. + - Symbol icons are now in `symbols.icons`, symbol blacklists are in + `symbols.blacklist` + - Lsp blacklists are now in `providers.lsp.blacklist_clients`. + - Fold options are now in `symbol_folding` with `fold_markers` being + `symbol_folding.markers`, consistent to `guides.markers`. + + The reasoning for the above is simple. When you see 'border' under + `preview_window` you can directly infer it controls the border for the preview + window. Previously, for example, when you see `winblend` or `wrap`: is it for + the outline window or the preview window? Furthermore, this change also aids + extensibility to the configuration, and avoids cluttering the root setup opts + namespace. + + If you disagree with this decision, you are always free to switch back to the + original symbols-outline.nvim, or you could pin a commit in this fork if you + still want to use the features and fixes from here. + - **Config**: `keymaps.focus_location` RENAMED to `keymaps.peek_location` to avoid confusion with focus window commands. - **Config**: Marker icons used for guides can now be customized. `show_guides` REMOVED in favor of `guides.enabled`. + You can set `guides = false` to disable guides altogether, or set `guides = + true` to enable it but use default configuration for the guides. Otherwise, + please use `guides.enabled` if your configuration for `guides` is a table. + - **Behaviour**: Removed hover floating window from `toggle_preview`. - Instead, you can set `open_hover_on_preview=true` (true by default) so that the `hover_symbol` action can be triggered when `toggle_preview`is @@ -113,7 +140,8 @@ for a screenshot) - Added function and command to show provider and outline window status, somewhat like `:LspInfo`. -- Move down/up by one line and peek_location immediately. +- Move down/up by one line and peek_location immediately, default bindings are +`` and `` just like Aerial. - Flash highlight when using goto/peek location. @@ -125,7 +153,7 @@ for a screenshot) - New restore location keymap option to go back to corresponding outline location synced with code (see config `restore_location`). -Screen recordings of some of the features is shown at the bottom of the readme. +Screen recordings of some of the features is shown at the [bottom of the readme](#recipes). ## PRs @@ -279,11 +307,12 @@ Table of contents * [Setup](#setup) * [Configuration](#configuration) * [Terminology](#terminology) - * [Options](#options) + * [Default options](#default-options) * [Commands](#commands) - * [Lua API](#lua-api) * [Default keymaps](#default-keymaps) * [Highlights](#highlights) +* [Lua API](#lua-api) +* [Tips](#tips) * [Recipes](#recipes) @@ -295,17 +324,15 @@ Table of contents ## Installation -Use `hedyhli/symbols-outline.nvim` if you wish to use this fork. - Packer: ```lua -use 'simrat39/symbols-outline.nvim' +use 'hedyhli/symbols-outline.nvim' ``` Lazy: ```lua { - "simrat39/symbols-outline.nvim", + "hedyhli/symbols-outline.nvim", config = function() -- Example mapping to toggle outline vim.keymap.set("n", "tt", "SymbolsOutline", @@ -321,11 +348,11 @@ Lazy: Lazy with lazy-loading: ```lua { - "simrat39/symbols-outline.nvim", + "hedyhli/symbols-outline.nvim", cmd = { "SymbolsOutline", "SymbolsOutlineOpen" }, keys = { -- Example mapping to toggle outline - { "tt", "SymbolsOutline", desc = "Toggle outline window" }, + { "tt", "SymbolsOutline", desc = "Toggle outline" }, }, opts = { -- Your setup opts here @@ -350,8 +377,14 @@ require("symbols-outline").setup({}) ## Configuration +The configuration structure has been heavily improved and refactored in this +plugin. For details and reasoning, see [breaking changes](#-breaking-changes). + ### Terminology +Check this list if you there's any confusion with the terms used in the +configuration. + - **Provider**: Source of the items in the outline view. Could be LSP, CoC, etc. - **Node**: An item in the outline view - **Fold**: Collapse a collapsible node @@ -363,23 +396,56 @@ require("symbols-outline").setup({}) provided by provider. - **Focus**: Which window the cursor is in -### Options +### Default options Pass a table to the setup call with your configuration options. Default values are shown: ```lua -local opts = { - -- Where to open the split window: right/left - position = 'right', - -- Whether width is relative to existing windows - relative_width = true, - -- Percentage or integer of columns - width = 25, +{ + outline_window = { + -- Where to open the split window: right/left + position = 'right', + -- Percentage or integer of columns + width = 25, + -- Whether width is relative to existing windows + relative_width = true, + + -- Behaviour changed in this fork: + -- Auto close the outline window if goto_location is triggered and not for + -- peek_location + auto_close = false, + -- Automatically go to location in code when navigating outline window. + -- Only in this fork + auto_goto = false, + + -- Vim options for the outline window + show_numbers = false, + show_relative_numbers = false, + show_cursorline = true, -- Only in this fork + + -- Whether to wrap long lines, or let them flow off the window + wrap = false, + -- Only in this fork: + -- Whether to focus on the outline window when it is opened. + -- Set to false to remain focus on your previous buffer when opening + -- symbols-outline. + focus_on_open = true, + }, + + outline_items = { + -- Whether to highlight the currently hovered symbol (high cpu usage) + highlight_hovered_item = true, + -- Show extra details with the symbols (lsp dependent) + show_symbol_details = true, + -- Only in this fork. + -- Show line numbers of each symbol next to them. + -- Why? See this comment: + -- https://github.com/simrat39/symbols-outline.nvim/issues/212#issuecomment-1793503563 + show_symbol_lineno = false, + }, - -- Whether to highlight the currently hovered symbol (high cpu usage) - highlight_hovered_item = true, -- Options for outline guides. -- Only in this fork guides = { @@ -391,54 +457,35 @@ local opts = { horizontal = '─', }, }, - -- Automatically open preview of code on hover - auto_preview = false, - -- Automatically open hover_symbol when opening toggle_preview (see keymaps). - -- If you disable this you can still open hover_symbol using your keymap - -- below. - -- Only in this fork - open_hover_on_preview = true, - -- Border option for floating preview window. - -- Options include: single/double/rounded/solid/shadow or an array of border - -- characters. - -- See :help nvim_open_win() and search for "border" option. - border = 'single', - -- Behaviour changed in this fork: - -- Auto close the outline window if goto_location is triggered and not for - -- peek_location - auto_close = false, - -- Automatically go to location in code when navigating outline window. - -- Only in this fork - auto_goto = false, - -- Vim options for the outline window - show_numbers = false, - show_relative_numbers = false, - show_cursorline = true, -- Only in this fork - -- Show extra details with the symbols (lsp dependent) - show_symbol_details = true, - -- Only in this fork. - -- Show line numbers of each symbol next to them. - -- Why? See this comment: - -- https://github.com/simrat39/symbols-outline.nvim/issues/212#issuecomment-1793503563 - show_symbol_lineno = false, - -- Highlight group for the preview background - preview_bg_highlight = 'Pmenu', - -- Depth past which nodes will be folded by default - autofold_depth = nil, - -- Automatically unfold hovered symbol - auto_unfold_hover = true, - fold_markers = { '', '' }, - -- Whether to wrap long lines, or let them flow off the window - wrap = false, + symbol_folding = { + -- Depth past which nodes will be folded by default + autofold_depth = nil, + -- Automatically unfold hovered symbol + auto_unfold_hover = true, + markers = { '', '' }, + }, - -- Only in this fork: - -- Whether to focus on the outline window when it is opened. - -- Set to false to remain focus on your previous buffer when opening - -- symbols-outline. - focus_on_open = true, - -- Pseudo-transparency of the preview window - winblend = 0 + preview_window = { + -- Automatically open preview of code location when navigating outline window + auto_preview = false, + -- Automatically open hover_symbol when opening preview (see keymaps for + -- hover_symbol). + -- If you disable this you can still open hover_symbol using your keymap + -- below. + -- Only in this fork + open_hover_on_preview = true, + -- Border option for floating preview window. + -- Options include: single/double/rounded/solid/shadow or an array of border + -- characters. + -- See :help nvim_open_win() and search for "border" option. + border = 'single', + border_hl = 'Pmenu', + -- Highlight group for the preview background + bg_hl = 'Pmenu', + -- Pseudo-transparency of the preview window + winblend = 0 + }, -- These keymaps can be a string or a table for multiple keys keymaps = { @@ -479,52 +526,58 @@ local opts = { up_and_goto = '', }, - -- Lsp clients to ignore - lsp_blacklist = {}, - -- Symbols to ignore. - -- Possible values: lua/symbols-outline/symbols.lua - symbol_blacklist = {}, + providers = { + lsp = { + -- Lsp client names to ignore + blacklist_clients = {}, + }, + }, symbols = { - -- Changed in this fork - File = { icon = "󰈔", hl = "@text.uri" }, - Module = { icon = "󰆧", hl = "@namespace" }, - Namespace = { icon = "󰅪", hl = "@namespace" }, - Package = { icon = "󰏗", hl = "@namespace" }, - Class = { icon = "𝓒", hl = "@type" }, - Method = { icon = "ƒ", hl = "@method" }, - Property = { icon = "", hl = "@method" }, - Field = { icon = "󰆨", hl = "@field" }, - Constructor = { icon = "", hl = "@constructor" }, - Enum = { icon = "ℰ", hl = "@type" }, - Interface = { icon = "󰜰", hl = "@type" }, - Function = { icon = "", hl = "@function" }, - Variable = { icon = "", hl = "@constant" }, - Constant = { icon = "", hl = "@constant" }, - String = { icon = "𝓐", hl = "@string" }, - Number = { icon = "#", hl = "@number" }, - Boolean = { icon = "⊨", hl = "@boolean" }, - Array = { icon = "󰅪", hl = "@constant" }, - Object = { icon = "⦿", hl = "@type" }, - Key = { icon = "🔐", hl = "@type" }, - Null = { icon = "NULL", hl = "@type" }, - EnumMember = { icon = "", hl = "@field" }, - Struct = { icon = "𝓢", hl = "@type" }, - Event = { icon = "🗲", hl = "@type" }, - Operator = { icon = "+", hl = "@operator" }, - TypeParameter = { icon = "𝙏", hl = "@parameter" }, - Component = { icon = "󰅴", hl = "@function" }, - Fragment = { icon = "󰅴", hl = "@constant" }, - -- ccls - TypeAlias = { icon = ' ', hl = '@type' }, - Parameter = { icon = ' ', hl = '@parameter' }, - StaticMethod = { icon = ' ', hl = '@function' }, - Macro = { icon = ' ', hl = '@macro' }, + -- Symbols to ignore. + -- Possible values are the Keys in the icons table below. + blacklist = {}, + -- Changed in this fork to fix deprecated icons not showing. + icons = { + File = { icon = "󰈔", hl = "@text.uri" }, + Module = { icon = "󰆧", hl = "@namespace" }, + Namespace = { icon = "󰅪", hl = "@namespace" }, + Package = { icon = "󰏗", hl = "@namespace" }, + Class = { icon = "𝓒", hl = "@type" }, + Method = { icon = "ƒ", hl = "@method" }, + Property = { icon = "", hl = "@method" }, + Field = { icon = "󰆨", hl = "@field" }, + Constructor = { icon = "", hl = "@constructor" }, + Enum = { icon = "ℰ", hl = "@type" }, + Interface = { icon = "󰜰", hl = "@type" }, + Function = { icon = "", hl = "@function" }, + Variable = { icon = "", hl = "@constant" }, + Constant = { icon = "", hl = "@constant" }, + String = { icon = "𝓐", hl = "@string" }, + Number = { icon = "#", hl = "@number" }, + Boolean = { icon = "⊨", hl = "@boolean" }, + Array = { icon = "󰅪", hl = "@constant" }, + Object = { icon = "⦿", hl = "@type" }, + Key = { icon = "🔐", hl = "@type" }, + Null = { icon = "NULL", hl = "@type" }, + EnumMember = { icon = "", hl = "@field" }, + Struct = { icon = "𝓢", hl = "@type" }, + Event = { icon = "🗲", hl = "@type" }, + Operator = { icon = "+", hl = "@operator" }, + TypeParameter = { icon = "𝙏", hl = "@parameter" }, + Component = { icon = "󰅴", hl = "@function" }, + Fragment = { icon = "󰅴", hl = "@constant" }, + -- Added ccls symbols in this fork + TypeAlias = { icon = ' ', hl = '@type' }, + Parameter = { icon = ' ', hl = '@parameter' }, + StaticMethod = { icon = ' ', hl = '@function' }, + Macro = { icon = ' ', hl = '@macro' }, + }, }, } ``` -To find out exactly what some of the options do, check out the +To find out exactly what some of the options do, please see the [recipes](#recipes) section of the readme at the bottom for screen-recordings. ## Commands @@ -576,7 +629,47 @@ To find out exactly what some of the options do, check out the With bang, it can be understood as the converse of `focus_location`. -### Lua API +## Default keymaps + +These mappings are active for the outline window. + +| Key | Action | +| ---------- | -------------------------------------------------- | +| Escape | Close outline | +| ? | Show help message | +| Enter | Go to symbol location in code | +| o | Go to symbol location in code without losing focus | +| Ctrl+k | Go up and goto location | +| Ctrl+j | Go down and goto location | +| Ctrl+g | Go to code location in outline window | +| Ctrl+Space | Hover current symbol | +| K | Toggles the current symbol preview | +| r | Rename symbol | +| a | Code actions | +| h | Fold symbol or parent symbol | +| Tab | Toggle fold under cursor | +| Shift+Tab | Toggle all folds | +| l | Unfold symbol | +| W | Fold all symbols | +| E | Unfold all symbols | +| R | Reset all folding | + +## Highlights + +| Highlight | Purpose | +| ----------------------- | -------------------------------------- | +| FocusedSymbol | Highlight of the focused symbol | +| Pmenu | Highlight of the preview popup windows | +| SymbolsOutlineConnector | Highlight of the table connectors | +| Comment | Highlight of the info virtual text | + + +Note that some highlights are configurable such as the preview window border and +background. Please see [configuration options](#default-options). + +## Lua API + +Symbols-outline provides the following public API for use in lua. ```lua require'symbols-outline' @@ -630,40 +723,17 @@ require'symbols-outline' With `opts.focus_outline=false`, cursor focus will remain on code window. +## Tips -## Default keymaps +- To open the outline but don't focus on it, you can use `:SymbolsOutline!` or +`:SymbolsOutlineOpen`. -These mappings are active for the outline window. + This is useful in autocmds, say you have a filetype that, whenever a buffer with + that filetype is opened you want to open the outline. -| Key | Action | -| ---------- | -------------------------------------------------- | -| Escape | Close outline | -| ? | Show help message | -| Enter | Go to symbol location in code | -| o | Go to symbol location in code without losing focus | -| Ctrl+k | Go up and goto location | -| Ctrl+j | Go down and goto location | -| Ctrl+g | Go to code location in outline window | -| Ctrl+Space | Hover current symbol | -| K | Toggles the current symbol preview | -| r | Rename symbol | -| a | Code actions | -| h | Fold symbol or parent symbol | -| Tab | Toggle fold under cursor | -| Shift+Tab | Toggle all folds | -| l | Unfold symbol | -| W | Fold all symbols | -| E | Unfold all symbols | -| R | Reset all folding | - -## Highlights - -| Highlight | Purpose | -| ----------------------- | -------------------------------------- | -| FocusedSymbol | Highlight of the focused symbol | -| Pmenu | Highlight of the preview popup windows | -| SymbolsOutlineConnector | Highlight of the table connectors | -| Comment | Highlight of the info virtual text | +- After navigating around in the outline window, you can use `` (default + mapping for `restore_location`) to go back to the corresponding outline + location based on the code location. ## Recipes @@ -671,30 +741,40 @@ These mappings are active for the outline window. Behaviour you may want to achieve and the combination of configuration options to achieve it. +Code snippets in this section are to be placed in `.setup({ })` directly +unless specified otherwise. + **Unfold all others except currently hovered item** ```lua -autofold_depth = 1, -auto_unfold_hover = true, +symbol_folding = { + autofold_depth = 1, + auto_unfold_hover = true, +}, ``` image -Any other recipes you think others may also find useful? Feel free to open a PR. - **Use outline window as a quick-jump window** ```lua -auto_preview = true, +preview_window = { + auto_preview = true, +}, ``` https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/a473d791-d1b9-48e9-917f-b816b564a645 +Note that in the recording I have `preview_window.open_hover_on_preview = +false`. + Alternatively, if you want to automatically navigate to the corresponding code -location and not use the preview window: +location directly and not use the preview window: ```lua -auto_goto = true, +outline_window = { + auto_goto = true, +}, ``` This feature was added by @stickperson in an upstream PR 🙌 @@ -704,21 +784,30 @@ https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/3d06e342-97ac-40 Or, you can use keys `` and `` to achieve the same effect, whilst not having `auto_goto` on by default. +This feature is newly added in this fork. **Hide the extra details after each symbol name** ```lua -show_symbol_details = false, +outline_items = { + show_symbol_details = false, +}, ``` **Show line numbers next to each symbol to jump to that symbol quickly** +This feature is newly added in this fork. + ```lua -show_symbol_lineno = true, +outline_items = { + show_symbol_lineno = false, +}, ``` -The default highlight group is `LineNr`. +The default highlight group for the line numbers is `LineNr`. image +--- +Any other recipes you think others may also find useful? Feel free to open a PR. diff --git a/lua/symbols-outline/config.lua b/lua/symbols-outline/config.lua index 41de111..795d241 100644 --- a/lua/symbols-outline/config.lua +++ b/lua/symbols-outline/config.lua @@ -3,9 +3,6 @@ local vim = vim local M = {} M.defaults = { - position = 'right', - width = 25, - highlight_hovered_item = true, guides = { enabled = true, markers = { @@ -15,24 +12,39 @@ M.defaults = { horizontal = '─', }, }, - border = 'single', - relative_width = true, - auto_close = false, - auto_goto = false, - auto_preview = false, - open_hover_on_preview = true, - show_numbers = false, - show_relative_numbers = false, - show_cursorline = true, - show_symbol_details = true, - show_symbol_lineno = false, - preview_bg_highlight = 'Pmenu', - winblend = 0, - autofold_depth = nil, - auto_unfold_hover = true, - fold_markers = { '', '' }, - wrap = false, - focus_on_open = true, + outline_items = { + show_symbol_details = true, + show_symbol_lineno = false, + highlight_hovered_item = true, + }, + outline_window = { + position = 'right', + width = 25, + relative_width = true, + wrap = false, + focus_on_open = true, + auto_close = false, + auto_goto = false, + show_numbers = false, + show_relative_numbers = false, + show_cursorline = true, + }, + preview_window = { + auto_preview = false, + width = 50, + min_width = 100, + relative_width = true, + bg_hl = 'Pmenu', + border = 'single', + border_hl = 'Pmenu', + open_hover_on_preview = true, + winblend = 0, + }, + symbol_folding = { + autofold_depth = nil, + auto_unfold_hover = true, + markers = { '', '' }, + }, keymaps = { show_help = '?', close = { '', 'q' }, @@ -53,53 +65,59 @@ M.defaults = { down_and_goto = '', up_and_goto = '', }, - lsp_blacklist = {}, - symbol_blacklist = {}, - symbols = { - File = { icon = '󰈔', hl = '@text.uri' }, - Module = { icon = '󰆧', hl = '@namespace' }, - Namespace = { icon = '󰅪', hl = '@namespace' }, - Package = { icon = '󰏗', hl = '@namespace' }, - Class = { icon = '𝓒', hl = '@type' }, - Method = { icon = 'ƒ', hl = '@method' }, - Property = { icon = '', hl = '@method' }, - Field = { icon = '󰆨', hl = '@field' }, - Constructor = { icon = '', hl = '@constructor' }, - Enum = { icon = 'ℰ', hl = '@type' }, - Interface = { icon = '󰜰', hl = '@type' }, - Function = { icon = '', hl = '@function' }, - Variable = { icon = '', hl = '@constant' }, - Constant = { icon = '', hl = '@constant' }, - String = { icon = '𝓐', hl = '@string' }, - Number = { icon = '#', hl = '@number' }, - Boolean = { icon = '⊨', hl = '@boolean' }, - Array = { icon = '󰅪', hl = '@constant' }, - Object = { icon = '⦿', hl = '@type' }, - Key = { icon = '🔐', hl = '@type' }, - Null = { icon = 'NULL', hl = '@type' }, - EnumMember = { icon = '', hl = '@field' }, - Struct = { icon = '𝓢', hl = '@type' }, - Event = { icon = '🗲', hl = '@type' }, - Operator = { icon = '+', hl = '@operator' }, - TypeParameter = { icon = '𝙏', hl = '@parameter' }, - Component = { icon = '󰅴', hl = '@function' }, - Fragment = { icon = '󰅴', hl = '@constant' }, - -- ccls - TypeAlias = { icon = ' ', hl = '@type' }, - Parameter = { icon = ' ', hl = '@parameter' }, - StaticMethod = { icon = ' ', hl = '@function' }, - Macro = { icon = ' ', hl = '@macro' }, + providers = { + lsp = { + blacklist_clients = {}, + }, }, + symbols = { + blacklist = {}, + icons = { + File = { icon = '󰈔', hl = '@text.uri' }, + Module = { icon = '󰆧', hl = '@namespace' }, + Namespace = { icon = '󰅪', hl = '@namespace' }, + Package = { icon = '󰏗', hl = '@namespace' }, + Class = { icon = '𝓒', hl = '@type' }, + Method = { icon = 'ƒ', hl = '@method' }, + Property = { icon = '', hl = '@method' }, + Field = { icon = '󰆨', hl = '@field' }, + Constructor = { icon = '', hl = '@constructor' }, + Enum = { icon = 'ℰ', hl = '@type' }, + Interface = { icon = '󰜰', hl = '@type' }, + Function = { icon = '', hl = '@function' }, + Variable = { icon = '', hl = '@constant' }, + Constant = { icon = '', hl = '@constant' }, + String = { icon = '𝓐', hl = '@string' }, + Number = { icon = '#', hl = '@number' }, + Boolean = { icon = '⊨', hl = '@boolean' }, + Array = { icon = '󰅪', hl = '@constant' }, + Object = { icon = '⦿', hl = '@type' }, + Key = { icon = '🔐', hl = '@type' }, + Null = { icon = 'NULL', hl = '@type' }, + EnumMember = { icon = '', hl = '@field' }, + Struct = { icon = '𝓢', hl = '@type' }, + Event = { icon = '🗲', hl = '@type' }, + Operator = { icon = '+', hl = '@operator' }, + TypeParameter = { icon = '𝙏', hl = '@parameter' }, + Component = { icon = '󰅴', hl = '@function' }, + Fragment = { icon = '󰅴', hl = '@constant' }, + -- ccls + TypeAlias = { icon = ' ', hl = '@type' }, + Parameter = { icon = ' ', hl = '@parameter' }, + StaticMethod = { icon = ' ', hl = '@function' }, + Macro = { icon = ' ', hl = '@macro' }, + }, + }, } -M.options = {} +M.o = {} function M.has_numbers() - return M.options.show_numbers or M.options.show_relative_numbers + return M.o.outline_window.show_numbers or M.o.outline_window.show_relative_numbers end function M.get_position_navigation_direction() - if M.options.position == 'left' then + if M.o.outline_window.position == 'left' then return 'h' else return 'l' @@ -107,15 +125,15 @@ function M.get_position_navigation_direction() end function M.get_window_width() - if M.options.relative_width then - return math.ceil(vim.o.columns * (M.options.width / 100)) + if M.o.outline_window.relative_width then + return math.ceil(vim.o.columns * (M.o.outline_window.width / 100)) else - return M.options.width + return M.o.outline_window.width end end function M.get_split_command() - if M.options.position == 'left' then + if M.o.outline_window.position == 'left' then return 'topleft vs' else return 'botright vs' @@ -136,7 +154,7 @@ function M.is_symbol_blacklisted(kind) if kind == nil then return false end - return has_value(M.options.symbol_blacklist, kind) + return has_value(M.o.symbols.blacklist, kind) end function M.is_client_blacklisted(client_id) @@ -144,17 +162,21 @@ function M.is_client_blacklisted(client_id) if not client then return false end - return has_value(M.options.lsp_blacklist, client.name) + return has_value(M.o.providers.lsp.blacklist_clients, client.name) end function M.show_help() print 'Current keymaps:' - print(vim.inspect(M.options.keymaps)) + print(vim.inspect(M.o.keymaps)) end function M.setup(options) vim.g.symbols_outline_loaded = 1 - M.options = vim.tbl_deep_extend('force', {}, M.defaults, options or {}) + M.o = vim.tbl_deep_extend('force', {}, M.defaults, options or {}) + local guides = M.o.guides + if type(guides) == 'boolean' and guides then + M.o.guides = M.defaults.guides + end end return M diff --git a/lua/symbols-outline/folding.lua b/lua/symbols-outline/folding.lua index df1626c..20a22cd 100644 --- a/lua/symbols-outline/folding.lua +++ b/lua/symbols-outline/folding.lua @@ -1,12 +1,12 @@ local M = {} -local config = require 'symbols-outline.config' +local cfg = require 'symbols-outline.config' M.is_foldable = function(node) return node.children and #node.children > 0 end local get_default_folded = function(depth) - local fold_past = config.options.autofold_depth + local fold_past = cfg.o.symbol_folding.autofold_depth if not fold_past then return false else @@ -17,7 +17,7 @@ end M.is_folded = function(node) if node.folded ~= nil then return node.folded - elseif node.hovered and config.options.auto_unfold_hover then + elseif node.hovered and cfg.o.symbol_folding.auto_unfold_hover then return false else return get_default_folded(node.depth) diff --git a/lua/symbols-outline/hover.lua b/lua/symbols-outline/hover.lua index 683811d..6c5b5b5 100644 --- a/lua/symbols-outline/hover.lua +++ b/lua/symbols-outline/hover.lua @@ -1,5 +1,5 @@ local so = require 'symbols-outline' -local soconfig = require 'symbols-outline.config' +local cfg = require 'symbols-outline.config' local util = vim.lsp.util local M = {} @@ -40,7 +40,7 @@ function M.show_hover() end -- FIXME local bufnr, winnr = util.open_floating_preview(markdown_lines, 'markdown', config) - local winhi = 'Normal:' .. soconfig.options.preview_bg_highlight + local winhi = 'Normal:' .. cfg.o.preview_window.bg_hl vim.api.nvim_win_set_option(winnr, 'winhighlight', winhi) end ) diff --git a/lua/symbols-outline/init.lua b/lua/symbols-outline/init.lua index e929b1a..005f506 100644 --- a/lua/symbols-outline/init.lua +++ b/lua/symbols-outline/init.lua @@ -2,7 +2,7 @@ local parser = require 'symbols-outline.parser' local providers = require 'symbols-outline.providers.init' local ui = require 'symbols-outline.ui' local writer = require 'symbols-outline.writer' -local config = require 'symbols-outline.config' +local cfg = require 'symbols-outline.config' local utils = require 'symbols-outline.utils.init' local View = require 'symbols-outline.view' local folding = require 'symbols-outline.folding' @@ -11,7 +11,7 @@ local M = {} local function setup_global_autocmd() if - config.options.highlight_hovered_item or config.options.auto_unfold_hover + cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then vim.api.nvim_create_autocmd('CursorHold', { pattern = '*', @@ -107,7 +107,7 @@ end -- Wraps __goto_location and handles auto_close function M._goto_location(change_focus) M.__goto_location(change_focus) - if change_focus and config.options.auto_close then + if change_focus and cfg.o.outline_window.auto_close then M.close_outline() end end @@ -130,7 +130,7 @@ function M._toggle_fold(move_cursor, node_index) end local function setup_buffer_autocmd() - if config.options.auto_preview then + if cfg.o.preview_window.auto_preview then vim.api.nvim_create_autocmd('CursorMoved', { buffer = 0, callback = require('symbols-outline.preview').show, @@ -141,7 +141,7 @@ local function setup_buffer_autocmd() callback = require('symbols-outline.preview').close, }) end - if config.options.auto_goto then + if cfg.o.outline_window.auto_goto then vim.api.nvim_create_autocmd('CursorMoved', { buffer = 0, callback = function() @@ -261,76 +261,76 @@ local function setup_keymaps(bufnr) utils.nmap(bufnr, ...) end -- goto_location of symbol and focus that window - map(config.options.keymaps.goto_location, function() + map(cfg.o.keymaps.goto_location, function() M._goto_location(true) end) -- goto_location of symbol but stay in outline - map(config.options.keymaps.peek_location, function() + map(cfg.o.keymaps.peek_location, function() M._goto_location(false) end) -- Navigate to corresponding outline location for current code location - map(config.options.keymaps.restore_location, function() + map(cfg.o.keymaps.restore_location, function() M._map_follow_cursor() end) -- Move down/up in outline and peek that location in code - map(config.options.keymaps.down_and_goto, function() + map(cfg.o.keymaps.down_and_goto, function() M._move_and_goto('down') end) -- Move down/up in outline and peek that location in code - map(config.options.keymaps.up_and_goto, function() + map(cfg.o.keymaps.up_and_goto, function() M._move_and_goto('up') end) -- hover symbol map( - config.options.keymaps.hover_symbol, + cfg.o.keymaps.hover_symbol, require('symbols-outline.hover').show_hover ) -- preview symbol map( - config.options.keymaps.toggle_preview, + cfg.o.keymaps.toggle_preview, require('symbols-outline.preview').toggle ) -- rename symbol map( - config.options.keymaps.rename_symbol, + cfg.o.keymaps.rename_symbol, require('symbols-outline.rename').rename ) -- code actions map( - config.options.keymaps.code_actions, + cfg.o.keymaps.code_actions, require('symbols-outline.code_action').show_code_actions ) -- show help map( - config.options.keymaps.show_help, + cfg.o.keymaps.show_help, require('symbols-outline.config').show_help ) -- close outline - map(config.options.keymaps.close, function() + map(cfg.o.keymaps.close, function() M.view:close() end) -- toggle fold selection - map(config.options.keymaps.fold_toggle, M._toggle_fold) + map(cfg.o.keymaps.fold_toggle, M._toggle_fold) -- fold selection - map(config.options.keymaps.fold, function() + map(cfg.o.keymaps.fold, function() M._set_folded(true) end) -- unfold selection - map(config.options.keymaps.unfold, function() + map(cfg.o.keymaps.unfold, function() M._set_folded(false) end) -- toggle fold all - map(config.options.keymaps.fold_toggle_all, M._toggle_all_fold) + map(cfg.o.keymaps.fold_toggle_all, M._toggle_all_fold) -- fold all - map(config.options.keymaps.fold_all, function() + map(cfg.o.keymaps.fold_all, function() M._set_all_folded(true) end) -- unfold all - map(config.options.keymaps.unfold_all, function() + map(cfg.o.keymaps.unfold_all, function() M._set_all_folded(false) end) -- fold reset - map(config.options.keymaps.fold_reset, function() + map(cfg.o.keymaps.fold_reset, function() M._set_all_folded(nil) end) end @@ -362,7 +362,7 @@ local function handler(response, opts) M._highlight_current_item(M.state.code_win) - if not config.options.focus_on_open or (opts and not opts.focus_outline) then + if not cfg.o.outline_window.focus_on_open or (opts and not opts.focus_outline) then vim.fn.win_gotoid(M.state.code_win) end end @@ -561,7 +561,7 @@ end ---Set up configuration options for symbols-outline. function M.setup(opts) - config.setup(opts) + cfg.setup(opts) ui.setup_highlights() M.view = View:new() diff --git a/lua/symbols-outline/parser.lua b/lua/symbols-outline/parser.lua index e0088ed..4c8b79f 100644 --- a/lua/symbols-outline/parser.lua +++ b/lua/symbols-outline/parser.lua @@ -1,6 +1,6 @@ local symbols = require 'symbols-outline.symbols' local ui = require 'symbols-outline.ui' -local config = require 'symbols-outline.config' +local cfg = require 'symbols-outline.config' local t_utils = require 'symbols-outline.utils.table' local lsp_utils = require 'symbols-outline.utils.lsp_utils' local folding = require 'symbols-outline.folding' @@ -17,7 +17,7 @@ local function parse_result(result, depth, hierarchy, parent) local ret = {} for index, value in pairs(result) do - if not config.is_symbol_blacklisted(symbols.kinds[value.kind]) then + if not cfg.is_symbol_blacklisted(symbols.kinds[value.kind]) then -- the hierarchy is basically a table of booleans which tells whether -- the parent was the last in its group or not local hir = hierarchy or {} @@ -99,7 +99,7 @@ function M.get_lines(flattened_outline_items) for node_line, node in ipairs(flattened_outline_items) do local depth = node.depth - local marker_space = (config.options.fold_markers and 1) or 0 + local marker_space = (cfg.o.symbol_folding.markers and 1) or 0 local line = t_utils.str_to_table(string.rep(' ', depth + marker_space)) local running_length = 1 @@ -118,15 +118,15 @@ function M.get_lines(flattened_outline_items) end for index, _ in ipairs(line) do - if config.options.guides.enabled then - local guide_markers = config.options.guides.markers + if cfg.o.guides.enabled then + local guide_markers = cfg.o.guides.markers if index == 1 then line[index] = '' -- if index is last, add a bottom marker if current item is last, -- else add a middle marker elseif index == #line then -- add fold markers - local fold_markers = config.options.fold_markers + local fold_markers = cfg.o.symbol_folding.markers if fold_markers and folding.is_foldable(node) then if folding.is_folded(node) then line[index] = fold_markers[1] @@ -184,14 +184,14 @@ function M.get_lines(flattened_outline_items) local hl_start = #string_prefix local hl_end = #string_prefix + #node.icon - local hl_type = config.options.symbols[symbols.kinds[node.kind]].hl + local hl_type = cfg.o.symbols.icons[symbols.kinds[node.kind]].hl table.insert(hl_info, { node_line, hl_start, hl_end, hl_type }) node.prefix_length = #string_prefix + #node.icon + 1 end local final_hl = {} - if config.options.show_symbol_lineno then + if cfg.o.outline_items.show_symbol_lineno then -- Width of the highest lineno value local max_width = #tostring(lineno_max) -- Padded prefix to the right of lineno for better readability if linenos @@ -209,7 +209,7 @@ function M.get_lines(flattened_outline_items) }) node.prefix_length = node.prefix_length + total_offset end - if config.options.guides.enabled then + if cfg.o.guides.enabled then for _, hl in ipairs(guide_hl_info) do table.insert(final_hl, { hl[1], @@ -222,7 +222,7 @@ function M.get_lines(flattened_outline_items) else -- Merge lists hl_info and guide_hl_info final_hl = hl_info - if config.options.guides.enabled then + if cfg.o.guides.enabled then for _, hl in ipairs(guide_hl_info) do table.insert(final_hl, hl) end diff --git a/lua/symbols-outline/preview.lua b/lua/symbols-outline/preview.lua index 0a3e725..0a62eb9 100644 --- a/lua/symbols-outline/preview.lua +++ b/lua/symbols-outline/preview.lua @@ -1,5 +1,5 @@ local so = require 'symbols-outline' -local config = require 'symbols-outline.config' +local cfg = require 'symbols-outline.config' local hover = require 'symbols-outline.hover' local M = {} @@ -31,11 +31,11 @@ local function get_offset() local width = 53 local height = 0 - if config.has_numbers() then + if cfg.has_numbers() then width = width + 4 end - if config.options.position == 'right' then + if cfg.o.outline_window.position == 'right' then width = 0 - width else width = vim.api.nvim_win_get_width(outline_winnr) + 1 @@ -91,10 +91,10 @@ local function setup_preview_buf() end local function set_bg_hl() - local winhi = 'Normal:' .. config.options.preview_bg_highlight + local winhi = 'Normal:' .. cfg.o.preview_window.bg_hl vim.api.nvim_win_set_option(state.preview_win, 'winhighlight', winhi) -- vim.api.nvim_win_set_option(state.hover_win, 'winhighlight', winhi) - local winblend = config.options.winblend + local winblend = cfg.o.preview_window.winblend vim.api.nvim_win_set_option(state.preview_win, 'winblend', winblend) -- vim.api.nvim_win_set_option(state.hover_win, 'winblend', winblend) end @@ -119,7 +119,7 @@ local function show_preview() col = offsets[2], -- Position preview window middle-aligned vertically row = math.ceil((height - winheight) / 2), - border = config.options.border, + border = cfg.o.preview_window.border, }) setup_preview_buf() else @@ -134,7 +134,7 @@ function M.show() show_preview() set_bg_hl() - if config.options.open_hover_on_preview then + if cfg.o.preview_window.open_hover_on_preview then hover.show_hover() end end diff --git a/lua/symbols-outline/rename.lua b/lua/symbols-outline/rename.lua index b9d413d..9f626ac 100644 --- a/lua/symbols-outline/rename.lua +++ b/lua/symbols-outline/rename.lua @@ -19,7 +19,7 @@ function M.rename() local params = get_rename_params(node, so.state.code_win) - local new_name = vim.fn.input('New Name: ', node.name) + local new_name = vim.fn.input({ prompt = 'New Name: ', default = node.name }) if not new_name or new_name == '' or new_name == node.name then return end diff --git a/lua/symbols-outline/symbols.lua b/lua/symbols-outline/symbols.lua index f58d3ee..fee46b4 100644 --- a/lua/symbols-outline/symbols.lua +++ b/lua/symbols-outline/symbols.lua @@ -40,7 +40,7 @@ M.kinds = { } function M.icon_from_kind(kind) - local symbols = config.options.symbols + local symbols = config.o.symbols.icons if type(kind) == 'string' then return symbols[kind].icon diff --git a/lua/symbols-outline/view.lua b/lua/symbols-outline/view.lua index 15d5ba9..8ad0857 100644 --- a/lua/symbols-outline/view.lua +++ b/lua/symbols-outline/view.lua @@ -1,4 +1,4 @@ -local config = require 'symbols-outline.config' +local cfg = require('symbols-outline.config') local View = {} @@ -14,9 +14,9 @@ function View:setup_view() -- delete buffer when window is closed / buffer is hidden vim.api.nvim_buf_set_option(self.bufnr, 'bufhidden', 'delete') -- create a split - vim.cmd(config.get_split_command()) + vim.cmd(cfg.get_split_command()) -- resize to a % of the current window size - vim.cmd('vertical resize ' .. config.get_window_width()) + vim.cmd('vertical resize ' .. cfg.get_window_width()) -- get current (outline) window and attach our buffer to it self.winnr = vim.api.nvim_get_current_win() @@ -30,7 +30,7 @@ function View:setup_view() vim.api.nvim_win_set_option(self.winnr, 'relativenumber', false) vim.api.nvim_win_set_option(self.winnr, 'winfixwidth', true) vim.api.nvim_win_set_option(self.winnr, 'list', false) - vim.api.nvim_win_set_option(self.winnr, 'wrap', config.options.wrap) + vim.api.nvim_win_set_option(self.winnr, 'wrap', cfg.o.outline_window.wrap) vim.api.nvim_win_set_option(self.winnr, 'linebreak', true) -- only has effect when wrap=true vim.api.nvim_win_set_option(self.winnr, 'breakindent', true) -- only has effect when wrap=true -- Would be nice to use guides.markers.vertical as part of showbreak to keep @@ -43,15 +43,15 @@ function View:setup_view() vim.api.nvim_buf_set_option(self.bufnr, 'filetype', 'Outline') vim.api.nvim_buf_set_option(self.bufnr, 'modifiable', false) - if config.options.show_numbers or config.options.show_relative_numbers then + if cfg.o.outline_window.show_numbers or cfg.o.outline_window.show_relative_numbers then vim.api.nvim_win_set_option(self.winnr, 'nu', true) end - if config.options.show_relative_numbers then + if cfg.o.outline_window.show_relative_numbers then vim.api.nvim_win_set_option(self.winnr, 'rnu', true) end - if config.options.show_cursorline then + if cfg.o.outline_window.show_cursorline then vim.api.nvim_win_set_option(self.winnr, 'cursorline', true) end end diff --git a/lua/symbols-outline/writer.lua b/lua/symbols-outline/writer.lua index 96ad3a7..2d67888 100644 --- a/lua/symbols-outline/writer.lua +++ b/lua/symbols-outline/writer.lua @@ -1,5 +1,5 @@ local parser = require 'symbols-outline.parser' -local config = require 'symbols-outline.config' +local cfg = require('symbols-outline.config') local ui = require 'symbols-outline.ui' local M = {} @@ -52,7 +52,7 @@ function M.write_details(bufnr, lines) if not is_buffer_outline(bufnr) then return end - if not config.options.show_symbol_details then + if not cfg.o.outline_items.show_symbol_details then return end @@ -69,7 +69,7 @@ function M.write_lineno(bufnr, lines, max) if not is_buffer_outline(bufnr) then return end - if not config.options.show_symbol_lineno then + if not cfg.o.outline_items.show_symbol_lineno then return end local maxwidth = #tostring(max) @@ -90,7 +90,7 @@ local function clear_virt_text(bufnr) end M.add_hover_highlights = function(bufnr, nodes) - if not config.options.highlight_hovered_item then + if not cfg.o.outline_items.highlight_hovered_item then return end @@ -101,7 +101,7 @@ M.add_hover_highlights = function(bufnr, nodes) goto continue end - local marker_fac = (config.options.fold_markers and 1) or 0 + local marker_fac = (cfg.o.symbol_folding.markers and 1) or 0 if node.prefix_length then ui.add_hover_highlight( bufnr,