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)
Scope:
- Parsing of symbol tree
- Producing the flattened tree
- Producing the lines shown in the outline based on the symbol tree
- API of exported functions for parser.lua and writer.lua
Note that the formatting of the outline remains the same as before.
Fixes:
- Guide highlights sometimes cover fold marker areas (may be related to
the issue brought up by @silvercircle on reddit)
- Guide highlights do not work when using guide markers of different
widths than the default (such as setting all markers to ascii chars)
All of these issues are now fixed after integrating the a parser
algorithm.
This commit introduces:
1. A better algorithm for flattening & parsing the tree in one go
2. `OutlineFoldMarker` highlight group
3. Fixed inconsistent highlighting of guides and legacy (somewhat weaker
code), through (1).
4. Minor performance improvements
5. Type hints for the symbol tree
6. Removed several functions from writer.lua and parser.lua due to them
being merged into writer.make_outline
This can be seen as a breaking change because functions that were
exported had altered behaviours. However I doubt these functions
actually have any critical use outside of this plugin, hence it isn't
really a breaking change as the user-experience remains the same.
The extraneous left padding on the outline window is now a relic of the
past 🎉
The old implementation, parser.get_lines used a flattened tree and was
inefficient, full of off-by-one corrections.
While trying to look for bug fixes in that function I realized it's the
sort of "if it works, don't touch it" portion of code.
Hence, I figured a complete rewrite is necessary.
Now, the function responsible for making the outline lines lives at
writer.make_outline. Building the flattened tree, getting lines, details
and linenos are now done in one go.
This is a tradeoff between modular design and efficiency.
parser.lua still serve important purposes:
- local parse_result function converts the hierarchical tables from
provider into a nested form tree, used everywhere in outline.nvim. The
type hint of the return value is now defined -- outline.SymbolNode
- preorder_iter is an iterator that traverses the aforementioned tree in
pre-order style. First the parents, all the childrens, and so on until
the last node of the root tree. This is used in writer.make_outline to
abstract a way the traversal code from the code of making the lines.
Thanks to stack overflow I did not have to consult a DS book to figure
out the cleanest way of this traversal method without using recursion.
This, of course, closes#14 on github.
Note that another minor 'breaking' change is that previously, hl for the
guides where grouped per-character, now they are grouped together for
all the guide markers in the same line. This should not be a problem for
those who only style the fg color for guide hl. However, if you're
styling the bg color, they will now take on that bg collectively rather
than individually.
This change eliminates future maintenance burden because controlling
per-character guide highlights requires careful avoidance of off-by-one
errors.
I have tested most common features to work as before.
I may have missed particular edge cases.
Please take note of "scope" at the top of this commit message.