Commit Graph

97 Commits

Author SHA1 Message Date
Logan Walls
a110e12d0b enable ghost_text for multi-line completions (#1886) 2024-06-08 15:59:43 +09:00
hrsh7th
5260e5e8ec use nvim_get_option_value instead of nvim{,_buf,_win}_get_option 2024-05-17 22:56:28 +09:00
hrsh7th
ce16de5665 support snippet item in ghost_text 2024-04-02 16:05:54 +09:00
hrsh7th
7240362105 support snippet item in ghost_text 2024-04-02 16:04:51 +09:00
mcauley-penney
7aa3f71932 feat: add option for view to follow cursor (#1727)
* feat: add option for custom entry view to follow cursor

Creates an option to allow the custom entries
view to follow the user's cursor as they type.

To enable, set
```lua
require("cmp").setup({
  view = {
    entries = {
      follow_cursor = true
    }
  }
})
```

Original source at 7569056388

Closes #1660

Co-authored-by: lvimuser <109605931+lvimuser@users.noreply.github.com>

* doc: add view.follow_cursor option to docs

---------

Co-authored-by: lvimuser <109605931+lvimuser@users.noreply.github.com>
2024-03-31 15:46:16 +09:00
Yi Ming
97dc716fc9 feat: make winblend configurable (#1861) 2024-03-24 20:44:34 +09:00
Lyude
b356f2c80c Allow window.documentation.max_{width, height} to be set to 0 (#1394)
To allow for using all available screen space, as we can omit a
max_height/max_width when creating a documentation popup). I've found this
to be useful with neovim-gtk's native GUI completion menus.
2024-03-22 16:38:43 +09:00
Jongwook Choi
13451e7ee4 docs: fix invalid WindowConfig schema, should match to the docs (#1779)
Problem: `cmp.WindowConfig` was defined twice.

Solution: Introduce
  `cmp.CompletionWindowOptions` and `cmp.DocumentationWindowOptions`.
Make fields of these two class consistent with |cmp-config.window.*|
2024-03-22 03:05:55 +09:00
Sam
763c720d51 fix(ghost_text): make sure to the delete the mark for the same buffer (#1826) 2024-03-22 03:03:11 +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
GyouzaRu
5e1fa02553 Fix: Buffer is not 'modifiable' (#1677) 2023-12-10 20:22:00 +09:00
PlankCipher
0b751f6bee fix(ghost_text): ephemeral-like inline ghost-text workaround (#1688)
Refs:
  - https://github.com/hrsh7th/nvim-cmp/pull/1645
  - https://github.com/neovim/neovim/issues/24797
2023-11-06 17:58:22 +09:00
Maria José Solano
51260c02a8 fix: remove usages from vim.lsp.util.parse_snippet (#1734) 2023-10-25 10:54:30 +09:00
PlankCipher
51f1e11a89 fix(ghost_text): ephemeral causes a false positive of no inline support (#1645) 2023-08-12 11:55:52 +09:00
hrsh7th
3874e09e80 fix(entry): remove offset + 1 for tailwindcss 2023-05-28 22:33:20 +09:00
hrsh7th
1088b3743b Add extmark inline feature detection 2023-05-27 23:06:46 +09:00
Anshuman Medhi
950d0e3a93 ghost text inline (#1588) 2023-05-26 00:02:26 +09:00
François Fleur
d153771162 fix(ghost_text): safely apply virtual_text highlight (#1563) 2023-05-12 15:42:39 +09:00
Felipe Gomes
1cad30fcff Added a modified=false to documentation buffer, so it can be removed without E89 errors (#1557) 2023-05-05 15:54:16 +09:00
hrsh7th
0f47dcaf7e Add buftype=nofile for entries_win and docs_win
- reddit user mention this...
2023-05-04 19:35:24 +09:00
hrsh7th
8d2f190506 Fix #1550 2023-05-04 03:09:56 +09:00
Daniil Shvalov
524cc0ba61 fix(cmdline): properly compute string length (#1544) 2023-05-01 23:18:17 +09:00
hrsh7th
5dcbc91d9a Try to fix #1458 (#1548) 2023-05-01 23:15:54 +09:00
Joey Buiteweg
01f697a689 fix: in lua if(0) evaluates to true, so check vim.fn.has == 1 (#1465) 2023-02-27 15:39:37 +09:00
Joey Buiteweg
ba7a53478d fix: better check for if setcmdline() is available (#1456) 2023-02-22 16:23:58 +09:00
NAKAI Tsuyoshi
8202df9561 fix: prevent autocmd outbursts by using setcmdline instead of feedkey (#1446) 2023-02-19 00:58:05 +09:00
hrsh7th
0c6a89af9a Improve perf 2023-02-18 16:46:02 +09:00
Zahid
c53dd36adc Fix parantheses bug and use string.rep (#1297) 2022-11-12 11:16:12 +09:00
gegoune
c37ea78941 Update docs_view.lua (#1292)
Although I have `showbreak` set for normal editing I would rather not see that in documentation. RFC.

Setting to `NONE` as per `:h showbreak`:

```
	A window-local value overrules a global value.  If the global value is
	set and you want no value in the current window use NONE:  
		:setlocal showbreak=NONE
```
2022-11-11 11:27:19 +09:00
NAKAI Tsuyoshi
16ec8c6b12 fix(custom_entries_view): offset is also the number of bytes (#1288) 2022-11-10 09:26:26 +09:00
ADoyle
bdfadc1238 feat: select_next_item and select_prev_item support "count" option. deafults to 1 (#1262)
User can increase count value to select item with pagedown/pageup.

- cmp.select_prev_item({ behavior = behavior, count = 8 })
- cmp.select_next_item({ behavior = behavior, count = 8 })
2022-11-09 19:26:20 +09:00
NAKAI Tsuyoshi
c8d4afdad6 fix(custom_entries_view): consider multibyte characters (#1287) 2022-11-09 19:25:26 +09:00
sanka047
9bb8ee6e2d fix(custom_entries_view): remove off-by-one error with bottom_up selection order (#1261)
Closes #1260
2022-10-29 10:04:41 +09:00
hrsh7th
beb1d14c5e Add scrolloff option for completion window. 2022-10-02 19:47:01 +09:00
hrsh7th
3cc0c182ec Fix #1142 2022-08-20 21:58:53 +09:00
hrsh7th
9417f48a99 Restore filetype setting 2022-08-20 19:22:50 +09:00
hrsh7th
bf5593df8e Improve typings 2022-07-24 12:44:53 +09:00
gravndal
89df2cb223 Fix native_entries_view.info width and col calculations (#1075)
The dictionary returned by `pum_getpos()` uses `scrollbar` not
`scrollable` to indicate whether the scrollbar is visible or not.

In addition, the padding on the left side of the popup menu isn't
included in the output of `pum_getpos()`, meaning that both `col` and
`width` (as understood by nvim-cmp) are off by one when the cursor isn't
at column `0`.

These two issues were causing the documentation window and popup menu to
overlap.
2022-07-24 12:19:21 +09:00
hrsh7th
c4dcb1244a Fix border width calculation 2022-07-21 00:37:40 +09:00
Cameron
df6734aa01 Add Completion Window Options (#901)
* Add window.completion.side_padding and window.completion.col_offset

* add col_offset and side_padding options to config/window
2022-06-15 11:49:16 +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
tzachar
1558d110d7 Bottom up mode for custom menu (#848)
* Try to fix col adjustment (#843)

* Try to fix col adjuastment

* Improve duplicated text handling

* Bottom up mode for custom entry menu

When in command line mode, the custom entry window opens up to an
unexpected height, depending on the current count of completion items.
The above makes it hard to anticipate where to look at, and makes life a bit
harder.

This patch adds an option to open the custom entries view in a bottom up
mode, and flips the regular behaviour of next/prev entry in this mode.
Setup is as easy as:

```
cmp.setup.cmdline(':', {
  view = {
    entries = {name = 'custom', direction = 'bottom_up' }
  }
}
```

* fix stylua complaints

* sylua barfs

* solve some corner cases

* properly reverse entries table

* make custom view follow cursor

* respect default as top_down

* stylua

* more stylua

Co-authored-by: hrsh7th <hrsh7th@gmail.com>
2022-04-08 22:33:09 +09:00
hrsh7th
4bc038f72d fmt 2022-02-13 18:53:30 +09:00
hrsh7th
bf78446d59 Refactor wildmenu_entries_view 2022-02-13 18:53:09 +09:00
hrsh7th
070c5572ad Implement shell like common string completion.
Fix #785
2022-02-13 14:34:28 +09:00
hrsh7th
de69c657eb Fix menu position for horizontal splitting 2022-02-02 19:25:25 +09:00
tzachar
124f1611f1 Statusline view in search mode or command line mode (#729)
* Search mode horizontal view

Enabled by setting `experimental.horizontal_search = true`

* use stylua

* move to a floating window instead of abusing status line

* pass all tests

* rework

1. rename entries view file and memeber to wildmenu_entries_view
2. move config to config.view.entries
3. support both in insert mode and cmdline
4. make separator configurable by config.view.separator

* rearange wildmenu config

Changed config to:
```lua
  view = {
    entries = {name = 'wildmenu', separator = '|' }
  },
```

* allow view.entries to be either a literal string or a table
2022-02-01 16:47:34 +09:00
hrsh7th
098182e2c2 Fix #734 2022-01-15 18:56:29 +09:00
hrsh7th
796f925915 Fix #703 2022-01-07 00:38:42 +09:00
Daniel Steinberg
4a19645374 Use a default zindex of 50 for documentation (#661)
This matches the default zindex for floating windows.
2021-12-21 10:52:43 +09:00