Commit Graph

221 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Josef Litoš
a1b4ef08c2 feat: avoid global variable use (#1813) 2024-03-22 02:56:07 +09:00
Maria José Solano
51260c02a8 fix: remove usages from vim.lsp.util.parse_snippet (#1734) 2023-10-25 10:54:30 +09:00
jmp
d3a3056204 ci: fix broken tests (#1729)
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.
2023-10-18 15:37:12 +09:00
Folke Lemaitre
6f118169af fix(async): properly trigger callbacks when canceling and fix delays in throttle.sync (#1611) 2023-06-09 19:08:28 +09:00
Folke Lemaitre
abb5c7519d feat: cmp async (#1583) 2023-05-26 02:46:53 +09:00
hrsh7th
935b4069ce Improve misc.merge 2023-05-08 11:41:15 +09:00
hrsh7th
5a80cd4eca Fix #897 2023-05-07 15:00:04 +09:00
hrsh7th
11102d3db1 Squashed commit of the following:
commit 6e81cce2cf9b9487e92c15cdfb145647de7c2db5
Author: hrsh7th <629908+hrsh7th@users.noreply.github.com>
Date:   Thu Apr 27 01:11:41 2023 +0900

    Improve key identity check
2023-04-27 11:02:23 +09:00
hrsh7th
0c6a89af9a Improve perf 2023-02-18 16:46:02 +09:00
hrsh7th
ea9eaff573 Maybe improve cmdline redraw 2023-02-16 22:53:08 +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
MovEaxEsp
c49ad26e89 keymap.lua: Fix duplicate keymap detection (#1379)
'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.
2022-12-31 02:58:28 +09:00
hrsh7th
e55033fce4 Fix #1322 2022-12-27 15:53:05 +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
NAKAI Tsuyoshi
8bbaeda725 fix(api): consider multibyte characters in get_screen_cursor (cmdline) (#1352)
* fix(api): consider multibyte characters in get_screen_cursor (cmdline)

* style: format with stylua

* test: tell luacheck that it is intended unreachable code
2022-12-15 20:27:02 +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
e820335208 LSP 3.17 (#1306)
* 3.17

* PositionEncodingKind

* Implement PositionEncodingKind

* Remove luarc.json
2022-11-16 01:27:15 +09:00
hrsh7th
3347dd3c59 Fix #1217 2022-10-15 15:20:35 +09:00
hrsh7th
69476c9e06 ci 2022-10-15 15:16:27 +09:00
figsoda
714ccb7483 fix compatibility with nvim < 0.8 (#1227) 2022-10-12 00:35:19 +09:00
hrsh7th
53bd574901 Fix #1213 2022-10-11 11:44:23 +09:00
hrsh7th
203aa26fc2 Fix for cmdheight=0
Fixes #1196
Fixes hrsh7th/cmp-cmdline#64
2022-10-02 20:22:13 +09:00
yuys13
2427d06b65 Format by stylua (#1195) 2022-09-27 12:27:31 +09:00
hrsh7th
e1f31778a8 Optimize performance 2022-09-25 21:24:27 +09:00
Lewis Russell
6b3dbc8377 fix(timer): close timers before Neovim exits (#1166) 2022-09-02 11:29:13 +09:00
yuki yano
b5885696b1 Add incsearch_redraw_keys settings (#1162) 2022-08-31 12:42:43 +09:00
hrsh7th
7e67df513a Fix #1135 2022-08-20 20:42:43 +09:00
hrsh7th
49c4050e24 Refactor a bit 2022-08-20 19:23:05 +09:00
hrsh7th
76ba56ce96 Decrease waits 2022-07-24 13:14:01 +09:00
hrsh7th
bf5593df8e Improve typings 2022-07-24 12:44:53 +09:00
Jaehwang Jung
160405250e Reuse scratch buffer for keymap normalization (#991) 2022-05-15 18:44:21 +09:00
hrsh7th
0318a3cbc1 Improve the codes for sumneko friendly 2022-05-13 19:25:00 +09:00
zeertzjq
6527e5f31b fix: use scratch buffer and lhs for keymap.normalize() (#986)
Fix https://github.com/neovim/neovim/issues/18303

This can be slower, I don't know how frequently this function is called as I don't use this plugin.
2022-05-13 19:18:29 +09:00
hrsh7th
f81bfee109 Fix #964
Fix #963
Fix #966
2022-05-04 23:51:59 +09:00
hrsh7th
c6126cca36 Fix #962 2022-05-04 12:18:09 +09:00
hrsh7th
5054c14490 dev (#956)
* Adjust empty line count

* Implement vim.api.nvim_create_autocmd (#844)

* Implement vim.api.nvim_create_autocmd

* Only use vim.api.nvim_create_autocmd on nighly

* Cleanup

* cleanup

* Rename autos.lua to autocmds.lua

* Fix forgot to rename autos to autocmds

* Remove legacy autocmd

* Add descriptions on autocmds

* Update descriptions on autocmds

* Update CmpStatus command to lua API (#922)

Signed-off-by: Micah Halter <micah@balena.io>

* Move highlights to nvim_set_hl lua API (#925)

Signed-off-by: Micah Halter <micah@balena.io>

* Add default to highlight

* Refactor autocmds

* fmt

* Improve performance

* Fix bug

* Improve matching logic
Fixes https://github.com/hrsh7th/nvim-cmp/discussions/954

* Fix format

* Improve performance
Fix #825

* Fix cmdline redraw bug

* Fix event

Co-authored-by: hrsh7th <>
Co-authored-by: zer09 <zer09@users.noreply.github.com>
Co-authored-by: Micah Halter <micah@mehalter.com>
2022-05-04 01:47:01 +09:00
Jongwook Choi
f51dc68e1b fix: Fix stylua errors and install_stylua script (#923)
- Fix code style issues, suggested by stylua
- Update install_stylua.lua script so that it can run in macOS as well.
2022-04-20 13:21:37 +09:00
hrsh7th
77d88ba056 Revert #873 fixes for Fix #899 2022-04-14 16:26:14 +09:00
Jaehwang Jung
ec8e87ce5c Revert #886 and refactor (#900)
* 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)`.
2022-04-14 14:38:52 +09:00