This also fixes a typo from an old commit (did not catch the bug because
all this time I was testing with the same window!), and put
auto_update_events into outline_items since it makes more sense, and is
closer to highlight_hovered_item and (the new) auto_follow_cursor.
Added code_buf to state since it appears to be used quite often now.
Previously on each outline open, the `writer.make_outline` function
might be called at least 4 times(!), after this refactor it will only be
called once. And on update cursor autocmds, also called once (previously
at least twice).
behaviour:
- Now the outline window focus and highlight can update on each cursor
move (previously CursorHold, dependent on updatetime). This is now
configurable as well.
- During fold-all/unfold-all operations, now the cursor will remain on
the same node (rather than same line in outline buffer).
- The performance improvement is not significantly observable since even
the old implementation can appear instant. One may even argue I am
fixing a problem that did not exist, but implementation-wise it's just
so much better now.
config:
- outline_window.auto_update_events, list of events to be passed to
create_user_autocmd for updating cursor focus in outline, and updating
outline items (refetching symbols), using keys cursor and items
respectively.
- outline_window.show_cursorline now supports 2 other string values:
'focus_in_outline'/'focus_in_code' which controls when to enable
cursorline. Setting to true retains the default behaviour of always
showing the cursorline. This was added because now that the cursor
focus on the outline could change on each CursorMoved, the cursorline
may pose to be qute attention-seeking during the outline cursor
updates. Hence `focus_in_outline` is added so that when focus is in
code, the cursorline for outline window is not shown.
'focus_in_code' is added so that a user who disabled
highlight_hovered_item can keep track of position in outline when
focus is in code, disabling cursorline when focus is in outline.
At any given time, if hide cursor is enabled and show_cursorline is a
string value, hiding of cursor will not be done if cursorline is not
shown in the the given situation.
implementation:
- The reason for the improvement in performance as described in the
first paragraph is due to merging of finding hover item and finding
the deepest matched node to put cursor, into writer.make_outline. This
done, when previously done in separate function, because after the
separate function (namely _highlight_hovered_item) finishes,
writer.make_outline is called *again* anyway.
- Autocmds to update cursor position in outline is now done per buffer
rather than global.
Somehow the auto unfold and unfold depth options still work perfectly,
for this we should thank simrat or which ever contributor that
modularized the folding module and made it adaptable :)
Closes#27
- Highlight group 'OutlineJumpHighlight' (links to Visual by default)
- Config: outline_window.jump_highlight_duration (integer for
milliseconds, or boolean to enable/disable)
This commit introduces a basic framework for symbol filtering in
outline.nvim, where users can set per-filetype kinds to filter - include
or exclude for each filetype.
As a side effect the checking of symbol inclusion function has been
improved to O(1) time-complexity (previously O(n)). You can see this
from types/outline.lua and config.lua: a lookup table is used to check
if a kind is filtered, rather than looping through a list each time.
Former takes O(1) for lookup whereas the old implementation would be
O(n) for *each* node!
The old symbols.blacklist option *still works as expected*.
The schema for the new confit is detailed in #23 and types/outline.lua.
By the way, this commit also closes#23.
These should equivalent:
symbols.blacklist = { 'Function', 'Method' }
symbols.filter = { 'Function', 'Method', exclude=true }
symbols.filter = {
['*'] = { 'Function', 'Method', exclude=true }
}
And these should be equivalent:
symbols.blacklist = {}
symbols.filter = false
symbols.filter = nil
symbols.filter = { ['*'] = false }
symbols.filter = { ['*'] = { exclude = true } }
symbols.filter = { exclude = true }
The last two of which could be considered unidiomatic.
When multiple filetypes are specified, filetype specific filters
are NOT merged with the default ('*') filter, they are independent. If a
filetype is used, the default filter is not considered. The default
filter is only considered if a filetype filter for the given buffer is
not provided.
LIMITATIONS:
This is carried over from the implementation from symbols-outline:
filters can only be applied to parents at the moment. I.e.: If some node
has a kind that is excluded, all its children will NOT be considered.
Filters are only applied to children if its parent was not excluded
during filtering.
Also extracted all types into types module, and updated conversion
script to use the new symbols.filter opt.
NOTE:
On outline open it appears that parsing functions are called twice?
I should definitely add tests soon.
- Provider priorities can now be configured through `providers.priority`
- Each provider can have a get_status() function that returns a string
for its status. For LSP it returns the client name.
- :OutlineStatus logic refactored, together with provider checking
functions in `providers/init.lua`
- Switch from vim.lsp.buf_get_clients to vim.lsp.get_active_clients
(former was deprecated)
- Fixed a careless mistake from symbols-outline that seems to be an
unreachable bug (lsp)
Hopefully this commit fixes#1.
- Improved algorithm that finds the items to set hover-highlight
- Now we can set cursor on the nearest parent if the leaf node is folded
in the outline.
- Set cursor column appropriate depending on whether lineno is enabled.
API:
- parser.preorder_iter now supports an optional argument as function,
which determines whether to explore children. By default, folded
parents will not explore children. This can now be overridden.
Behaviour:
- If you fold a nested node and hit <C-g>, you can go back to the
nearest parent
- The column that cursor goes to is no longer arbitrarily chosen
It appears that simrat or whoever wrote this code thought the column was
1-indexed, however it is 0-indexed, so the old code was always putting
the cursor on the 2nd column.
Now, we put it in the first column. If lineno is enabled, we set the
cursor the be at the column of lineno padding, this makes both the
lineno and the markers visible.
Unfortunately the so-called 'improved' algorithm for
_highlight_current_item is still not the best. The most optimal would be
O(n). However, to make sure we stop refactoring now that it works OK and
can already fix an issue, I will leave this to posterity.
Tested to work (for me).
- Config
- Renamed auto_goto -> auto_jump (because goto implies change of
cursor focus)
- Renamed down/up_and_goto -> down/up_and_jump
Existing config that use the old keys *WILL STILL WORK*. But users are
recommended to update to avoid inconsistency. I promise the number of
config changes like this will decrease inverse-exponentially after the
plugin refactor :)
- Docs
- Improved wording
- Lineno
- Fixed alignment (no way I was taking max line num of the *Outline*
buf this whole time!)
- Fixed appearance of lineno column hl blending if hide_cursor is one
(please see the comment added)