Commit Graph

564 Commits

Author SHA1 Message Date
hedy
d65696a9cf feat: Optionally not auto-update cursors position
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.
2023-11-18 11:14:18 +08:00
hedy
82ab53a167 chore: stylua 2023-11-18 10:02:04 +08:00
hedy
3b4116c2c6 refactor: Use default key for default filtering
Inspired by lazyvim
2023-11-18 10:01:07 +08:00
hedy
d35ee70f95 feat: Better highlight-hover/follow-cursor procedures
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 :)
2023-11-18 09:34:16 +08:00
hedyhli
4812bc286d Auto generate vim docs 2023-11-17 23:40:43 +00:00
~hedy
cc10a7f23b Merge pull request #29 from One234Fi/One234Fi-patch-1
Update README.md
2023-11-18 07:40:19 +08:00
One234Fi
e2c8f92ffb Update README.md
Add missing comma after `goto_and_close = "<S-Cr>"` in the default config's keymaps
2023-11-17 16:24:21 -06:00
hedy
a1aa652fb2 feat: Center view on jump/goto 2023-11-17 12:34:14 +08:00
hedy
62dea5bff9 docs: Consistent quoting 2023-11-17 09:30:55 +08:00
hedy
dc55a8b942 chore(fmt): Finally let's use stylua
Hoping it's as good as go-fmt
2023-11-17 09:28:33 +08:00
hedyhli
d400d4f025 Auto generate vim docs 2023-11-16 14:17:24 +00:00
hedy
a083267101 Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-16 22:16:54 +08:00
hedy
134b7e2f39 feat: Jump highlight customizations
Closes #27

- Highlight group 'OutlineJumpHighlight' (links to Visual by default)
- Config: outline_window.jump_highlight_duration (integer for
  milliseconds, or boolean to enable/disable)
2023-11-16 22:14:47 +08:00
hedyhli
b749ccb690 Auto generate vim docs 2023-11-16 13:51:40 +00:00
hedy
fdc7c6391f docs: Add new config options 2023-11-16 21:51:08 +08:00
hedy
24680f13f7 feat: Symbol filtering config structure
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.
2023-11-16 21:21:55 +08:00
hedy
5278eb5b2b feat: Better provider info and fix LSP deprecated warnings
- 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)
2023-11-16 15:41:37 +08:00
hedy
22051b6555 chore: More remants of rename 2023-11-16 14:30:04 +08:00
hedy
4d871ec64b refactor: Better messages 2023-11-16 14:28:29 +08:00
hedyhli
9f4cfa9417 Auto generate vim docs 2023-11-16 06:06:35 +00:00
hedy
fa44423c16 docs: Better formatting for commands 2023-11-16 14:06:00 +08:00
hedyhli
1d571e4292 Auto generate vim docs 2023-11-16 01:26:52 +00:00
hedy
67ac007692 Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-16 09:26:28 +08:00
hedy
2238002462 docs: Add script to convert symbols-outline setup opts 2023-11-16 09:22:51 +08:00
hedyhli
38c4263aac Auto generate vim docs 2023-11-15 14:36:36 +00:00
hedy
43f7f7d158 docs: Collapse default opts to not take up screen space 2023-11-15 22:36:12 +08:00
hedyhli
9b843321d9 Auto generate vim docs 2023-11-15 14:33:47 +00:00
hedy
7c703361e9 feat: Support command modifiers on open commands 2023-11-15 22:32:33 +08:00
hedy
81ebdc5714 chore: Fix remants of rename 2023-11-15 11:28:09 +08:00
hedy
d78d0a0b50 docs: Fix typo on issue reference 2023-11-15 11:23:06 +08:00
hedyhli
f5365560be Auto generate vim docs 2023-11-15 03:21:54 +00:00
hedy
f356c29578 feat: Allow disabling icons 2023-11-15 11:21:20 +08:00
hedy
ddd4fe4359 fix(guides): Respect config.guides.enabled = false
oopsie
2023-11-13 21:31:19 +08:00
hedy
78ad5cb583 Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-13 21:15:40 +08:00
hedy
9c70b96b36 fix(highlight-hover): Set cursor in parent if child is folded
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).
2023-11-13 21:07:30 +08:00
hedyhli
35a27c6820 Auto generate vim docs 2023-11-13 10:27:46 +00:00
hedy
3f0025af3d docs: Use one screenshot only for hide_cursor 2023-11-13 18:27:13 +08:00
hedy
aba398af54 docs: Fix typo
OMG
2023-11-13 18:26:34 +08:00
hedyhli
b04f3b55f8 Auto generate vim docs 2023-11-13 10:26:30 +00:00
hedy
bb006be6f6 docs: Fix image placement 2023-11-13 18:25:56 +08:00
hedyhli
df850949af Auto generate vim docs 2023-11-13 10:24:56 +00:00
hedy
40a41b7d18 docs: Add another screenshot 2023-11-13 18:24:22 +08:00
hedyhli
c210f8d5ea Auto generate vim docs 2023-11-13 10:15:38 +00:00
hedy
1446bdd135 fix: Lineno alignment, hl_mode, config options
- 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)
2023-11-13 18:07:52 +08:00
hedy
fd22263c32 fix: Guide and fold highlight offsets
Was a silly mistake due to copying code from previous implementation.
2023-11-13 16:48:06 +08:00
hedy
7713536d28 refactor: make_outline function and left padding of lineno 2023-11-13 15:41:54 +08:00
hedy
60e8cadb46 fix: lineno left prefix padding 2023-11-13 15:20:54 +08:00
hedyhli
df8f24a52a Auto generate vim docs 2023-11-13 06:46:38 +00:00
hedy
91b027cb91 Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-13 14:46:10 +08:00
hedy
c6438a21e1 docs: Update readme on new highlight groups 2023-11-13 14:46:01 +08:00