* 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>
* 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>
* 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
* 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 7569056388Closes#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>
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.
Problem: `cmp.WindowConfig` was defined twice.
Solution: Introduce
`cmp.CompletionWindowOptions` and `cmp.DocumentationWindowOptions`.
Make fields of these two class consistent with |cmp-config.window.*|
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.
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.
* 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