28 Commits

Author SHA1 Message Date
wsdjeg
684b3cf5eb Format with stylua 2025-04-13 03:17:27 +00:00
emmanueltouzery
30d2593272 fix: handle winborder in neovim-0.11 (#2150) 2025-04-13 11:17:15 +08:00
Epheien
be7bd4c5f8 fix: scrollbar thumb ui issue (#2068)
Co-authored-by: eph <eph@MacBook-Pro.local>
2024-11-21 17:51:29 +09:00
Greg Hurrell
5d0651c9d6 fix: don't blow up when nvim_buf_get_lines() returns Blobs (#2050)
* fix: don't blow up when `nvim_buf_get_lines()` returns Blobs

Some LSP servers may return binary garbage and `nvim_buf_get_lines()`
will return a `Blob` instead of a `String` in those cases.

I added some `print(vim.inspect())` debugging in
`entry.get_documentation()` to prove that by the time the text passes
through there, it's already garbage.

Here's an excerpt from a sample line returned by `nvim_buf_get_lines()`,
as rendered by `vim.inspect()`:

    default\0\0\0!      vim.opt.background = 'dark'\0\0\0000

(etc)

Now, this looks like an LSP bug to me, but I think we shouldn't allow
buggy LSP output to crash nvim-cmp. "Be conservative in what you send,
be liberal in what you accept" and all that.

So, degrade by coercing any `Blob` we see into a `String` before passing
it to `strdisplaywidth()`.

Closes: https://github.com/hrsh7th/nvim-cmp/issues/820

* add comment

---------

Co-authored-by: hrsh7th <629908+hrsh7th@users.noreply.github.com>
2024-10-21 20:38:46 +09:00
hankertrix
53d80d4d0c fix: small windows no longer constantly throw errors (#1824)
The entries_win:open function will fail when either the width or
the height of the window is less than 1, which will result in the
nvim_win_set_cursor being passed a nil value for self.entries_win.win
instead of a number, which causes an error to constantly appear when
the window is small. Hence, a guard clause to check for whether
self.entries_win.win is nil is added to stop the error from occurring.

Also fixed the rarer 'height' must be a positive Integer error caused
by the window.update function, within the clause to draw the scrollbar
background. This error happens on small windows when pressing and
holding down the backspace key to delete a lot of characters at once.
The nvim_open_win function call to create the scrollbar
background throws the error when self.style.height is 0. Hence, an
additional check is added alongside the info.scrollable check which also
skips drawing the scrollbar thumb as it is not needed when the height is
0 and will result in a weird scrollbar thumb floating some distance
away from the text when holding down backspace to delete a lot of
characters.
2024-03-22 03:02:15 +09:00
tummetott
cfafe0a1ca Improved: ALL option settings do not fire the OptionSet event (#1417) 2023-02-04 01:09:00 +09:00
tummetott
e7e2ef7031 Setting local window options does not trigger the "OptionSet" event (#1415) 2023-01-26 20:10:50 +09:00
Lyude
a9c701fa7e Round up width/height for windows (#1373)
Ever since neovim introduced the nvim_ui_pum_set_bounds() call, GUI clients
have gained the ability to inform neovim of the current bounds of an
external popup menu provided by ext_popupmenu.

Since external popup menus are allowed to be any size in pixels which may
or may not line up cleanly on the grid, nvim allows for fractional
coordinates to be reported. This also will mean that in the event of this,
we'll end up with a cmp.WindowStyle with a float value for width/height -
which is incompatible with vim.api.nvim_open_win() and will cause us to hit
errors with GUI clients using this API call.

So, fix this by simply rounding up the width/height.
2022-12-27 13:11:42 +09:00
pure-bliss
8a9e8a89ee feat: added scrollbar option to window.completition ( #1087) (#1308)
* #1087 added hide_scrollbar option to window.completition

* Renamed hide_scrollbar to scrollbar, changed default value (#1087)

* doc description update (#1087)

* determining info.scrollbar value considering config scrollbar (#1087)

* window.bordered scrollbar default value fix (#1087)
2022-11-18 17:31:06 +09:00
hrsh7th
e1f31778a8 Optimize performance 2022-09-25 21:24:27 +09:00
hrsh7th
bf5593df8e Improve typings 2022-07-24 12:44:53 +09:00
hrsh7th
fae808a2bc dev (#813)
* feat: completion menu borders (#472)

* feat(custom_entries_view): pass custom border option

* feat(window): calculate offset needed for borders

* fix(window): adjust window height w/ too many results

* fix(window): center scrollbar with borders

* ref(custom_entries_view): use `FloatBorder` for borders

* fix(window): offset at bottom of window

* ref(window): move height adjustment to more logical place

* fix(window): improve popup placement

* fix(window): `border_offset` always `0` first time

* feat(window): support compact scrollbar with border

* fix(window): completion popup on cursorline

* perf(window): simplify offset calculation

String indexing will result in the same thing as if I gated it behind
`type()` calls here.

* docs(window): add `border` to `cmp.WindowStyle`

* docs(window): correct `border_offset_scrollbar`

* perf(window): calulated row -> `screenrow`

This will also be more accurate since it accounts for wrapped lines, as
well as buffers.

* fix(window): edge case with multiple splits

* ref(winhighlight): don't specify defaults by default

`NormalFloat:NormalFloat` isn't needed, since `NormalFloat` defaults to
`NormalFloat`. As for `FloatBorder`, that should be set to `Floatborder`
rather than `NormalFloat` or else you get unintended artifacts on the
edges of borders.

* fix(window): popup covers cursor when scrollbar disappears

* ref(window): calc `border_offset_col` on `set_style`

* perf(window): remove unecessary `col` calculation

Taking it out didn't change anything about the popup behavior.

* feat: add `CmpItemMenuThumb` group

* feat(window): improve scrollbar appearance

* chore(window): remove references to unused property

* docs: document new option `thin_scrollbar`

* ref(plugin): remove background from `thin_scrollbar`

* feat(view): pass `thin_scrollbar` option to window

* feat(window): gate new `thin_scrollbar` behind option

* fix(window): cmdline bugging out

* fix(cmp): docs_view pops up overlapped when using borders

This is related to 1cfe2f7dfd. The
calculation for how the popup position is calculated was changed, and
so it needed to be reworked to include borders in order to be able to
work.

* ref: `thin_scrollbar` flag -> `scrollbar` option

This change allows users to define which character they will use for
their scrollbar.

* fix(window): use `scrollbar` setting for scrollbar character

Thanks @Astrantia for pointing this one out.

* docs(README): add completion appearance options to FAQ

* fix(): account for `border_offset_row` with `has_bottom_space`

* style(custom_entries_view): group offset with `row`/`col`

* fix(window): scrollbar at full view height

Because the `bar_height` variable must be whole number, and must be rounded up
from a percent, there is a change that we will end up with the maximum
height as a number.

For example, `info.height` = 24 and `total` = 25.

* feat(window): allow scrollbar to be disabled

* fix(window): scrollbar size < 1

* ref(cmp): move border logic to `window.info`

* ref!: window highlighting based on borders

BREAKING CHANGE: `documentation.winhighlight` does not determine the
                 highlighting of the `documentation` view— `CmpWindow`
		 or `CmpBorderedWindow` depending on whether it has a
		 border.

* ref!: float appearance opts -> `cmp.setup.window`

`cmp.setup.completion.border` and `.scrollbar` were both moved to
`cmp.setup.window.completion.border` and `.scrollbar`

BREAKING CHANGE: `cmp.setup.documentation` has been moved to
                 `cmp.window.documentation`, as all of the pertaining
		 options were cosmetic.

TODO: document the change

* fix(window): attempt to get scrollbar's border

* fix(cmp): restore `view.menu.hl_group`

* fix(window): wrong scrollbar position

* ref: get default `CmpItemMenu` from border existence

* chore(cmp): remove old PR comments

* fix(window): scrollbar sometimes too big

* fix(window): docs far away with complete menu scrollbar

* perf(docs_view): reuse `border_width` value

* rev(cmp): restore `CmpItemMenu`

* ref(cmp): distinguish between `ScrollBar` and `ScrollThumb`

* fix(plugin): consistently refer to `Thumb` as `Thumb`

* rev(window): `Pmenu`-style scrollbar when no border

* fix(window): docs_view size wrong when first shown

* fix(window): docs_view scrollbar not responding to size

* fix(window): scrollbar sometimes to small, take 2

* fix(window): scrollbar bg not hiding

* ref(docs_view): put docs closer to completion menu

* fix(window): scrollbar position wrong with right border

* ref(config): add default border to documentation

* fix(window): scrollbar too close without border

* ref(plugin): link `CmpWindow` to `Pmenu`

I set `CmpWindow` to `NormalFloat`, because that is what you would
expect a floating window to use for a highlight group. However at
request I changed it to `Pmenu`.

* ref(plugin): link `CmpWindowBorder` to `CmpWindow`

* fix(window): scrollbar following thumb while scrolling

* ref: add more highlight groups

There just weren't enough highlight groups to satisfy the demands of the
project. If you change `CmpWindow` to `Pmenu`, then the `docs_view`
becomes `Pmenu` as well when on `main` it is `NormalFloat`.

* fix(window): scrollbar overlapping `docs_view` by default

* ref: remove `Bordered` highlight variants

* ref(utils): extract whitespace check to func

* feat: `window.completion.zindex` setting

* ref: `maxwidth|height` -> `max_`

* ref: simplify highlight groups

* feat: `window.*.winhighlight` setting

* ref(utils): `is_whitespace_char` -> `is_visible`

As hrsh7th noted, `''` is not a whitespace character. Yet, it is
necessary to group `''` and `' '` together for certain border behaviors
that are based on visibility. Thus I have renamed the function

* feat: specify `window.*.winhighlight` for un/bordered

* fix(custom_entries_view): set `winhighlight` on `open`

* ref: remove `Cmp*Scroll*` variants

There's no way for `window` to know which kind of window it is drawing a
scrollbar on. Simpler to just have one kind of scrollbar

* feat: distinguish between bordered and unbordered

* ref(cmp): `is_visible` -> `is_invisible`

That's what the function was checking for.

* fix(default): mislabeling of `default` and `bordered`

* chore: rebase fixup

* Change default highlight

* Add misc.rep

* Fix left-side docs_view with scrollbar

* Fix scrollbar

* Fix sbar/thumb win
Improve highlights

* Remove scrollbar cutomization for now

* Remove scrollbar option

* Simplify implementation

* Fix doc width

* Fix outdated docs

* Add comments

* Fix configuration schema

* fmt

* Fix for lint

Co-authored-by: Iron-E <36409591+Iron-E@users.noreply.github.com>
Co-authored-by: hrsh7th <>
2022-04-13 23:51:55 +09:00
hrsh7th
796f925915 Fix #703 2022-01-07 00:38:42 +09:00
Dmytro Meleshko
727ddee59e Fix rendering of wide characters in the custom completion window (#641) 2021-12-13 13:05:55 +09:00
hrsh7th
cae2e8f48b RFC: cmdline completion (#362)
* manual support dot-repeat

* cmdwin and terminal

* cmdline only

* Fix

* fix

* Improve

* Fix test

* Support macro

* disable cmdline for now

* Simplify

* fmt

* consume once

* Ignore = type

* cmdline

* fmt

* Improve

* update

* fmt

* Support incsearch

* fix

* Add api

* Avoid cmdline completion if the native_menu enabled

* fix for macro

* Improve

* fmt

* Insert-mode only by default

* Update

* avoid conflict

* Improve default mapping

* Fix

* fix

* similar to native

* Update

* Fix README.md

* Improve

* Use <afile>
2021-10-27 12:38:46 +09:00
Alex Tylor
b546f50f09 Expose get_selected_entry() from view module to main cmp module fixes #385 (#386)
* Expose get_selected_entry() from view module to main cmp module fixes #385

* add get_active_entry() also

* fix linting

* remove unused vars

Co-authored-by: alex.tylor <atylor@gmail.com>
2021-10-22 17:47:55 +09:00
hrsh7th
1e913aefd9 Fix #345 2021-10-18 11:47:17 +09:00
hrsh7th
0f28030aef Improve macro & dot-repeat support (#363)
* manual support dot-repeat

* cmdwin and terminal

* cmdline only

* Fix

* fix

* Improve

* Fix test

* Support macro

* disable cmdline for now

* Simplify

* fmt

* consume once

* Ignore = type

* cmdline

* Remove cmdline features
2021-10-16 23:37:32 +09:00
hrsh7th
ebe040b1a9 Fix #279 2021-10-16 13:27:36 +09:00
hrsh7th
0a31d67219 Lazy buffer creation 2021-10-10 13:57:37 +09:00
hrsh7th
d901dae302 Fix #296 2021-10-10 13:13:25 +09:00
hrsh7th
b16663f780 Improve 2021-10-10 12:50:35 +09:00
hrsh7th
370e6ff076 Use nvim_win_hide instead o nvim_win_close for supporting custom menu on cmdwin 2021-10-10 12:23:39 +09:00
hrsh7th
babb8023c6 Add cmp.visible 2021-10-10 12:13:57 +09:00
hrsh7th
2ebdccf61a Fix #306
Fix #296
Fix #293
Fix #291
2021-10-10 11:54:30 +09:00
hrsh7th
883eee5bbc Use <C-h> and support cmdwin 2021-10-10 00:01:15 +09:00
Hexin
12a24c0eb3 Check whether option exists (#301) 2021-10-09 15:18:18 +09:00
hrsh7th
ada9ddeff7 Use floating window for completion menus (#224)
* WIP

* WIP

* Fix #226

* Insert text

* Emulate vim native

* テキトウ

* Tekito

* Move scrollbar impl

* aaa

* Ignore unexpected event

* fix

* fix scroll

* Refactor (conflict...)

* Fix bug

* Positive integer

* Refactor a bit

* Fix for pumheight=0

* fx

* Improve matching highlight

* Improve colorscheme handling

* fmt

* Add cmp.visible

* Fix pum pos

* ABBR_MARGIN

* Fix cel calculation

* up

* refactor

* fix

* a

* a

* compat

* Remove current completion state

* Fix ghost text

* Add feature toggle

* highlight customization

* Update

* Add breaking change announcement

* Add README.md

* Remove unused function

* extmark ephemeral ghost text

* Support native comp

* Fix docs  pos

* a

* Remove if native menu visible

* theme async

* Improvement idea: option to disables insert on select item (#240)

* use ghost text instead of insertion on prev/next item

* add disables_insert_on_selection option

* move disable_insert_on_select option as argumet on

* update README

* use an enum behavior to disable insert on select

* Adopt contribution

* Preselect

* Improve

* Change configuration option

* a

* Improve

* Improve

* Implement proper <C-e> behavior to native/custom

* Support <C-c> maybe

* Improve docs view

* Improve

* Avoid syntax leak

* TODO: refactor

* Fix

* Revert win pos

* fmt

* ghost text remaining

* Don't use italic by default

* bottom

* dedup by label

* Ignore events

* up

* Hacky native view partial support

* up

* perf

* improve

* more cache

* fmt

* Fix format option

* fmt

* recheck

* Fix

* Improve

* Improve

* compat

* implement redraw

* improve

* up

* fmt/lint

* immediate ghost text

* source timeout

* up

* Support multibyte

* disable highlight

* up

* improve

* fmt

* fmt

* fix

* fix

* up

* up

* Use screenpos

* Add undojoin check

* Fix height

* matcher bug

* Fix dot-repeat

* Remove undojoin

* macro

* Support dot-repeat

* MacroSafe

* Default item count is 200

* fmt

Co-authored-by: Eric Puentes <eric.puentes@mercadolibre.com.co>
2021-10-08 18:27:33 +09:00