* 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
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.
feedkeys_spec.lua:
In the "backspace test spec, the backspace
setting is given an integer, but only accepts
strings. Here, I assume that 0 was intended to
set backspace to a nil value, which can be done
with the empty string. I also corrected the name
of the test spec.
core_spec.lua:
In the "textedit" test spec, the actual and
expected outputs as well as the actual and
expected end characters did not match.
'listen' has some code in it to try to not re-set a map for an existing mapping, by checking the 'desc' of the table returned from 'get_map'. Since 'desc' was never included in the table returned from 'get_map', I'm assuming my changes here were always the intention.
This change seems to fix an issue I was seeing (with cmp-nvim-ultisnips at least) where every time I'd enter and leave Insert mode, seemingly another <Tab> handler was getting registered, overtime causing <Tab> in Insert mode to get slower and slower.
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.
* fix(api): consider multibyte characters in get_screen_cursor (cmdline)
* style: format with stylua
* test: tell luacheck that it is intended unreachable code
* Revert "make completion popup windows have bufhidden=wipe (#886)"
This reverts commit f573479528.
* Remove redundant nvim_buf_set_option
`buftype=nofile` and `bufhidden=hide` are already set by
`nvim_create_buf(false, true)`.