Commit Graph

616 Commits

Author SHA1 Message Date
Francois Poizat
40a03dc225 fix: make <c-,> and <c-:> work again (#2092) 2024-11-19 21:37:27 +09:00
hrsh7th
f17d9b4394 support cpying self-referenced table (#2076) 2024-11-02 13:54:35 +09:00
phanium
7d4051064c fix: make <c-;> work again (#2073)
* fix: make <c-;> work again

* fix: also <c-_>
2024-11-02 13:39:41 +09:00
David van Munster
29fb485457 feat: allow more completion highlight control (#1972)
* feat(view): allow hl_group to be a table

* feat: improve table field naming
2024-10-21 23:10:07 +09:00
hrsh7th
88661b7cbf Format with stylua 2024-10-21 12:05:14 +00:00
zeertzjq
19bd8c7c9a fix: use \<* notation for keymap.normalize (#2069)
Fix https://github.com/hrsh7th/nvim-cmp/pull/1935#issuecomment-2426250159
2024-10-21 21:05:01 +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
Jaehwang Jung
2c93d5e7e2 perf: use builtin for key normalization (#1935) 2024-10-21 10:35:21 +09:00
Roey Darwish Dror
82bd4b5943 Avoid calling del_extmark on non existing buffer (#2053)
This fixes a problem with Neogit is discussed here:

https://github.com/NeogitOrg/neogit/discussions/1492
2024-10-20 14:04:43 +09:00
hrsh7th
cc683345c9 Format with stylua 2024-10-20 04:57:03 +00:00
hrsh7th
07f3f005c9 add performance.filtering_context_budget
fixes #2060
2024-10-20 13:56:45 +09:00
hrsh7th
c183f45fab Format with stylua 2024-10-20 04:28:33 +00:00
yioneko
1a1d7ecb73 perf: improve for source providing huge list of items (#1980)
* perf: avoid creating closure in cache.ensure and drop some cached getters

This mainly addresses the perf issue on large amount of calls to
`entry.new`. Previously every `cache.ensure` calls in the code path of
it creates an anonymous function, and it seems that luajit just could
not inline it. Function creation is not expensive in luajit, but that
overhead is noticeable if every `cache.ensure` call creates a function.
The first improvemnt is to solidate the cache callback and attach it to
the metatable of `entry`. This ensures that every created entry instance
share the same cache callback and no new functions will be frequently created,
reduces the ram usage and GC overhead.

To improve it further, some frequently accessed fields of entry like
`completion_item` and `offset` is refactored to use simple table access
instead of getter pattern. The current cached getter is implemented
using `cache.ensure`, which introduces two more levels of function calls
on each access: `cache.key` and `cache.get`. The overhead is okay if but
noticeable if entries amount is quite large: you need to call 4 functions on
a simple `completion_item` field access for each item.

All of the changes done in the commit is just constant time
optimization. But the different is huge if tested with LS providing
large amount of entries like tailwindcss.

* perf: delay fuzzy match on displayed vim item

`entry.get_vim_item` is a very heavy call, especially when user do
complex stuff on item formatting. Delay its call to window displaying to
let `performance.max_view_entries` applied to it.

* remove unneeded fill_defaults

* update gha

---------

Co-authored-by: hrsh7th <629908+hrsh7th@users.noreply.github.com>
2024-10-20 13:28:20 +09:00
pynappo
ae644feb7b Add newer fallback method for tree-sitter scopes (#2006) 2024-08-01 19:51:04 +09:00
NAKAI Tsuyoshi
d818fd0624 fix(view): check in get_selected_index (#1993) 2024-07-16 10:33:54 +09:00
NAKAI Tsuyoshi
e1757aea61 feat(view): add api get_selected_index (#1986) 2024-07-16 01:29:25 +09:00
Tristan Knight
7e348da6e5 fix(feedkeys): resolve issue with some copilot completions (#1981)
* fix(feedkeys): resolve issue with some copilot completions

* fix(feedkey): further adjustments

* fix: missed flag from testing

* fix(feedkeys): error handle and make tests pass
2024-07-14 15:04:40 +09:00
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
Augusto César Dias
abacd4cb7f Move to non deprecated function calls (#1930)
* Move to non deprecated function calls

* Keeping it compatible with older versions
2024-05-17 18:49:38 +09:00
Lewis Russell
31a2939e55 fix: remove deprecated use of vim.tbl_add_reverse_lookup (#1931) 2024-05-17 15:54:23 +09:00
kjuq
2412237181 fix: cmp.close() when autocompletion = false (#1921)
cf. https://github.com/hrsh7th/nvim-cmp/pull/1920
2024-05-12 18:45:22 +09:00
kjuq
1d88772dc6 fix: unexpected behavior when autocomplete = false (#1920)
- https://github.com/hrsh7th/nvim-cmp/issues/1251
- https://github.com/hrsh7th/nvim-cmp/issues/1919
2024-05-12 17:14:05 +09:00
Jaehwang Jung
8f3c541407 perf: don't eagerly load vim.snippet (#1896)
Evaluating `vim.snippet` loads many modules, which takes about 1ms.
2024-04-23 11:00:27 +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
hrsh7th
c34fa793ea re-improve resolve behavior 2024-03-24 17:45:24 +09:00
hrsh7th
6ed1c93465 follow VSCode resolve logic (#1857) 2024-03-23 00:07:35 +09:00
hrsh7th
630cdf7d54 fix #1858 2024-03-22 18:44:52 +09:00
hrsh7th
be50b23910 Format with stylua 2024-03-22 07:59:56 +00:00
hrsh7th
b7b2c12610 - fix ci
- fix #1780
2024-03-22 16:59:37 +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
Trildar
43b460a2bd Favor existing values in completion_item over resovled_completion_item (#1725) 2024-03-22 03:06:56 +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
Micah Halter
66f0a031d9 feat: default to vim.snippet for snippet expansion if available (#1820) 2024-03-22 03:04:54 +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
Kyle Butt
6460f979b9 Add option for symbol matching logic. (#1515)
The no_symbol_match makes command line completion a lot less useful. It
disables any matches for file names with symbols in them. This prevents
completing things like ":b foo/bar" to ":b foo/bar.txt" or ":b foo_" to
":b baz/foo_bar.txt". Add an option `disallow_symbol_nonprefix_matching`
that prevents a match if it contains a symbol and isn't a prefix match.
Make that option the default. Add the option to documentation and tests.
Add to the examples for command line setup disabling the option.
2024-03-22 03:00:36 +09:00
Josef Litoš
a1b4ef08c2 feat: avoid global variable use (#1813) 2024-03-22 02:56:07 +09:00
Yu Zhang
04e0ca376d fix: one more item than max_item_count is displayed (#1811) 2024-02-02 15:59:47 +09:00
Mehdi
41d7633e41 feat: sort source entries before slicing when using max_item_count (#1765)
* feat: sort source entries beforce slicing when using max_item_count

* feat: optimize filtering by max_item_count after sort

* fix: useless check if max_item_counts map is initialized

* fix: directly use entry source object when checking max_item_count
2023-12-10 20:37:02 +09:00
GyouzaRu
5e1fa02553 Fix: Buffer is not 'modifiable' (#1677) 2023-12-10 20:22:00 +09:00
Riley Bruins
55734c8b70 feat: match default border color to standard neovim float border hl (#1689) 2023-12-10 20:20:48 +09:00
Adam Price
c01a038469 Mark non-required setup fields as optional (#1723)
... to correct "Missing required fields" messages from lua_ls
2023-12-10 20:14:50 +09:00
hrsh7th
36eb3a6917 add test-case placeholders 2023-12-10 19:59:39 +09:00
Dan Salvato
82ba05c784 Fix fuzzy matcher adding invalid matches (#909) (#1420) 2023-12-10 19:57:59 +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