Commit Graph

69 Commits

Author SHA1 Message Date
hedy
39668e5061 feat: Go to corresponding code window after closing outline 2023-11-26 15:23:53 +08:00
hedy
b90174c6c2 refactor: Provider symbol actions
It makes sense to store the provider each sidebar is using with own
self.provider fields, no way that did not occur to me before this.

The old `_G._outline_current_provider` ironically, can now be replaced
by `require('outline').current.provider`.
2023-11-26 15:14:42 +08:00
hedy
1743ee7c66 chore(fmt): stylua 2023-11-26 13:29:47 +08:00
hedy
137e76fdca chore(fmt): Consistent function doc style 2023-11-26 13:27:29 +08:00
hedy
9f69f12161 refactor: Reorganize modules
Primarily:
- Utils
- Sidebar (removed the need of writer.lua)
- Resolve keymaps shortcut in config eraly
- Put highlight functions into highlight.lua
- Put functions that do stuff on outline window into view.lua
2023-11-26 13:17:18 +08:00
hedy
b83e84a15f Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-25 16:24:24 +08:00
hedy
bdeff23390 refactor(writer): Move make_outline to sidebar
Was passing self fields a lot, decided to just do all that in Sidebar
in the first place.

Also resolved guides.enabled=false early to setting markers to ' '.

Everything should work the same.
2023-11-25 16:21:44 +08:00
hedy
6d85399550 feat: Use more concise API names
No breaking change.
2023-11-25 15:43:36 +08:00
hedy
6cea72f2b5 feat(api): Get symbol and breadcrumb at location
Currently the implementation is very limited.

Ref: #24

- Outline must be open and have been loaded for it to work (requires
  lazy loading or headless loading of Sidebar)
- Empty string returned if cursor is not in any symbol ('closest' symbol
  not yet supported)
- Line column not used
- Returning concatenated symbol names rather than a list of tables with
  node info (requires a refactor of outline.SymbolNode type)
- Subject to config.symbols.filter and folds (requires finding hover
  list somewhere outside of writer.make_outline)
2023-11-25 15:41:55 +08:00
hedy
c7a033e85d chore: Remove debug message 2023-11-25 11:25:26 +08:00
hedy
44fdeac29a fix(writer): Ensure all buffer namespaces are cleared
...before setting highlights

Closes #38
2023-11-25 11:18:16 +08:00
hedy
842f2c4a86 refactor(status,help): Rename module and make naming more descriptive 2023-11-24 17:16:44 +08:00
hedy
ecc814f846 fix(api): Add back is_focus_in_outline 2023-11-24 17:13:59 +08:00
hedy
a7fe7baf5f fix(markdown): Revert a change from a previous commit 2023-11-24 17:13:44 +08:00
hedy
fab3e8ce7c feat(status): Use custom highlight with default links 2023-11-24 16:47:36 +08:00
hedy
896fd2ae63 feat(status): Better information and highlights 2023-11-24 16:31:16 +08:00
hedy
f4d5eb2dad fix(status): Show code window active when no outline opened yet 2023-11-24 16:17:52 +08:00
hedy
b475574fc0 fix(jsx): Label JSX fragment with Fragment kind 2023-11-24 16:11:25 +08:00
hedy
a2410faba9 refactor: Rename module ui -> highlight 2023-11-24 16:10:21 +08:00
hedy
23958f8731 chore(fmt): stylua 2023-11-24 15:04:28 +08:00
hedy
ebf90dc9ee fix(markdown): Don't include next heading in previous heading's range
Somehow marksman also does this?

As for treesitter (norg) it may be because treesitter includes the
newline and the next line indent until the next heading, so the line of
the next heading is included in the range of the previous heading. We
manually -1 on the range end line to fix it.
2023-11-24 15:04:18 +08:00
hedy
e705330e40 feat: Per-tabpage outlines
Closes #37

Almost completely refactored the UI parts outline.nvim to use a Sidebar
object that implements an outline window. In init.lua, we can then store
a table of the outline for each tabpage ID.

When tabs are closed the outline is closed and sidebar reset
responsibly.

This simplifies `init.lua` quite a lot, making it the highest level
control center for the outline elements.

All lua APIs and commands should work as before.
2023-11-24 14:50:24 +08:00
hedy
0c6d97d34a fix(jsx): Show shorthand fragments as "Fragment"
Closes #35

Previously the treesitter javascript parser would treat `<></>`
specially and emit a `jsx_fragment`. We were checking for this type here
(from symbols-outline.nvim), though we did not include `jsx_fragment` in
the parse_ts function to even look for it.

jsx_fragment was recently removed from treesitter parser to reduce
complexity, so we will treat all jsx_element's without a `name` field in
`jsx_opening_element` as the shorthand fragment.

Using "Fragment" as the name in this case makes it look exactly the same
as if the user used `<Fragment></Fragment>` instead.

The check for `jsx_fragment` is still kept in case an older version of
the parser is still used, it can probably be removed next year.

Ref:
- tree-sitter/tree-sitter-javascript#227
2023-11-23 18:39:35 +08:00
hedy
d35187ef37 feat: Norg provider and support of external providers
- Closes #3
- Ref: simrat39/symbols-outline.nvim#190

Norg contains indents and different types of verbatim tags, I was rather
lazy to read the spec properly and parse norg using regex line-by-line
like markdown, so used treesitter instead. The only requirement is the
`norg` parser for treesitter to be installed. Tested on nvim 0.7.2.

This should lead the way for supporting vimdoc files in a similar
manner.

Documentation for how external providers could look like as of now has
been added.

In the future we could let the provider determine what to do for each
keymap, such as `goto_location` and `toggle_preview`. This would allow
the zk extension[1] to work properly without having to override existing
functions (bad practice).

[1]: https://github.com/mickael-menu/zk-nvim/discussions/134
2023-11-22 22:16:19 +08:00
hedy
8c5c69feb2 chore(fmt): stylua 2023-11-22 21:17:40 +08:00
hedy
ec4f727631 refactor: Reorganize provider API 2023-11-22 20:55:10 +08:00
hedy
8551dd01d3 fix(highlights): Only inherit fg for FoldMarker and Guides highlights 2023-11-22 18:10:36 +08:00
hedy
31ef50e08e Merge branch 'main' of github.com:hedyhli/outline.nvim 2023-11-21 09:24:20 +08:00
~hedy
a21a17cc08 Merge pull request #32 from silvercircle/mine
use neovim core treesitter API instead of nvim-treesitter plugin
2023-11-21 09:24:07 +08:00
hedy
e2838c1e06 feat(preview): Use vim.treesitter API for highlight 2023-11-21 09:18:08 +08:00
hedy
699bc85cc5 feat: Properly support nvim-0.7, and fix highlights 2023-11-21 08:39:05 +08:00
Alex
c5ca61177a use neovim core treesitter API instead of nvim-treesitter plugin 2023-11-19 16:07:14 +01:00
hedy
ad6b15ee08 refactor: Rename of most recent option 2023-11-19 22:35:07 +08:00
hedy
3762402dd3 refactor(providers): Let get_status() return a list of strings instead 2023-11-19 19:02:00 +08:00
hedy
9b90379c7a Refactor 2023-11-19 17:45:41 +08:00
hedy
fa219c33af feat: More auto-unfold options
Option to auto unfold when there is only N root nodes in outline.

Defaults to 1, meaning if there is only one 'root' parent, it should
always be unfolded.

This is useful if the entire file is a single function or a single
'return'.

The old auto_unfold_hover option **still works as expected**.
2023-11-19 17:43:15 +08:00
hedy
3b27272319 feat(Status): Better provider info and show filter info 2023-11-19 16:59:49 +08:00
hedy
f8c212bcd2 docs: Document new options, commands, API functions 2023-11-18 22:24:34 +08:00
hedy
c06039da1e feat: Add refresh_outline function 2023-11-18 22:09:19 +08:00
hedy
6ea44bff68 fix(show_help): Indicate when keymap is disabled 2023-11-18 22:08:52 +08:00
hedy
87a72f88fa fix: Delete autocmds when wiping state 2023-11-18 21:08:13 +08:00
hedy
e56145f8dd feat: Proper floating window for keymap help and OutlineStatus
No more obnoxious '}' on the cmdline when pressing `?`!

scope:
- More type hints
- Added class Float for creating floating windows with size that fit the
  content and position centered on the screen
- show_help action for outline window (key `?`) now uses a floating
  window
- :OutlineStatus now provides better information, and shows content in a
  floating window.

future:
- Floating window option configuration
2023-11-18 20:52:50 +08:00
hedy
090da7633b fix: Preview window position based on outline split position
- preview window can adapt based on position of outline window, and not
  based on config value of `position` left/right
- it can also properly vertically center-align, even when there are
  horizontal splits below the outline
- fixed a few bugs associated with previous rewrite commits in init.lua

config:
- Added min_height for preview window
2023-11-18 15:04:26 +08:00
hedy
62183f9d51 fix: Ensure autocmds IDs are removed when deleted 2023-11-18 13:16:42 +08:00
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
hedy
a1aa652fb2 feat: Center view on jump/goto 2023-11-17 12:34:14 +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