Problem: popupmenu logic is a bit convoluted
Solution: slightly refactor logic and use MIN/MAX() macros to simplify
(glepnir)
Define the MAX/MIN macros. Since we support some older platforms, C
compilers may not be as smart. This helps reduce unnecessary if
statements and redundant ternary expressions. Pre-calculate some
expressions by defining variables. Remove unnecessary parentheses.
Adjust certain lines to avoid exceeding 80 columns.
closes: vim/vim#16205c942f84aad
Co-authored-by: glepnir <glephunter@gmail.com>
Problem: Float preview window still exist when back at original.
Or no info item is selected.
Solution: if selected is -1 or no info is selected, if float preview
window exist close it first.
Design goals/requirements:
- Default configuration of a server can be distributed across multiple sources.
- And via RTP discovery.
- Default configuration can be specified for all servers.
- Configuration _can_ be project specific.
Solution:
- Two new API's:
- `vim.lsp.config(name, cfg)`:
- Used to define default configurations for servers of name.
- Can be used like a table or called as a function.
- Use `vim.lsp.confg('*', cfg)` to specify default config for all
servers.
- `vim.lsp.enable(name)`
- Used to enable servers of name. Uses configuration defined
via `vim.lsp.config()`.
- Problem: cannot replace the initial bufwrite message (from `filemess`) by the final one (`"test.lua" [New] 0L, 0B written`), when using `vim.ui_attach`.
- Solution: add kind to both messages.
Problem: various vartabstop and shiftround bugs when shifting lines
Solution: Fix the bugs, add new tests for shifting lines in various ways
(Gary Johnson)
fixes: vim/vim#14891closes: vim/vim#16193eed63f96d2
Co-authored-by: Gary Johnson <garyjohn@spocom.com>
Problem: INT overflow logic can be simplified
Solution: introduce trim_to_int() function
closes: vim/vim#135562b0882fa65
vim-patch:9.0.2138: Overflow logic requires long long
Problem: Overflow logic requires long long
Solution: Define vimlong_T data type to make life easier
for porters
closes: vim/vim#13598fda700cb04
Cherry-pick ops.c change from patch 9.1.0608.
Co-authored-by: Ernie Rael <errael@raelity.com>
Problem: [security]: prevent overflow in indenting
Solution: use long long and remove cast to (int)
The shiftwidth option values are defined as being long. However, when
calculating the actual amount of indent, we cast down to (int), which
may cause the shiftwidth value to become negative and later it may even
cause Vim to try to allocate a huge amount of memory.
We already use long and long long variable types to calculate the indent
(and detect possible overflows), so the cast to (int) seems superfluous
and can be safely removed. So let's just remove the (int) cast and
calculate the indent using longs.
Additionally, the 'shiftwidth' option value is also used when determining
the actual 'cino' options. There it can again cause another overflow, so
make sure it is safe in parse_cino() as well.
fixes: vim/vim#13554closes: vim/vim#135553770574e4a
Co-authored-by: Christian Brabandt <cb@256bit.org>
Problem: Coverity warns for another overflow in shift_line()
Solution: Test for INT_MAX after the if condition, cast integer values
to (long long) before multiplying.
22a97fc241
Co-authored-by: Christian Brabandt <cb@256bit.org>
Problem: [security]: overflow in shift_line
Solution: allow a max indent of INT_MAX
[security]: overflow in shift_line
When shifting lines in operator pending mode and using a very large
value, we may overflow the size of integer. Fix this by using a long
variable, testing if the result would be larger than INT_MAX and if so,
indent by INT_MAX value.
Special case: We cannot use long here, since on 32bit architectures (or
on Windows?), it typically cannot take larger values than a plain int,
so we have to use long long count, decide whether the resulting
multiplication of the shiftwidth value * amount is larger than INT_MAX
and if so, we will store INT_MAX as possible larges value in the long
long count variable.
Then we can safely cast it back to int when calling the functions to set
the indent (set_indent() or change_indent()). So this should be safe.
Add a test that when using a huge value in operator pending mode for
shifting, we will shift by INT_MAX
closes: vim/vim#135356bf131888a
Skip the test for now, as it takes too long and requires other fixes.
Co-authored-by: Christian Brabandt <cb@256bit.org>
Problem: no error check for neg values for 'messagesopt'
(after v9.1.0908)
Solution: add additional error checks and tests (h-east)
closes: vim/vim#1618765be834c30
Nvim's getdigits() checks for overflow, so the code change isn't needed.
Co-authored-by: h-east <h.east.727@gmail.com>
Problem: Variable name for 'messagesopt' doesn't match short name
(after v9.1.0908)
Solution: Change p_meo to p_mopt. Add more details to docs.
closes: vim/vim#161828cc43daee1
Problem: 'messagesopt' does not check max wait time
(after v9.1.0908)
Solution: Check for max wait value
(Shougo Matsushita)
closes: vim/vim#16183d9e9f89e0f
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Problem: :sleep! not hiding the cursor is an arbitrary difference from
Vim without obvious justification, and Vim's behavior isn't
easily achievable in Nvim.
Solution: Make :sleep! hide the cursor while sleeping.
Ref:
6a01b3fcc3b5c0ade437
Problem:
vim.json.encode escapes every slash in string values (for example in
file paths), and is not optional. Use-case is for preventing HTML
injections (eg. injecting `</script>` closing tag); in the context of
Nvim this is rarely useful.
Solution:
- Add a `escape_slash` flag to `vim.json.encode`.
- Defaults to `false`. (This is a "breaking" change, but more like
a bug fix.)
Problem: When completion leader changes, text that might be reinserted
immediately after is deleted. This unnecessarily affects
extmarks. #31387 restored the original extmarks but that
prevents end_right_gravity marks from growing.
Solution: Avoid deleting leader text that will be reinserted.
Problem: In an autocommand Lua callback whether `args.file` is expanded
depends on whether `expand('<afile>')` has been called.
Solution: Always use the unexpanded file name for `args.file`.
Related to #31306 and vim/vim#16106. This doesn't provide `sfname`, but
at least makes `args.file` have a consistent value.
Problem: Marks that are properly restored by the splice associated with
an undo edit, are unnecessarily pushed to the undo header. This
results in incorrect mark tracking in the "copy_only"
save/restore completion path.
Solution: Avoid pushing left gravity marks at the beginning of the range,
and right gravity marks at the end of the range to the undo
header.
Problem: potential overflow in spell_soundfold_wsal()
Solution: Protect wres from buffer overflow, by checking the
length (Zdenek Dohnal)
Error: OVERRUN (CWE-119):
vim91/src/spell.c:3819: cond_const: Checking "reslen < 254" implies that
"reslen" is 254 on the false branch.
vim91/src/spell.c:3833: incr: Incrementing "reslen". The value of "reslen"
is now 255.
vim91/src/spell.c:3792: overrun-local: Overrunning array "wres" of 254
4-byte elements at element index 254 (byte offset 1019) using index
"reslen - 1" (which evaluates to 254).
3789| {
3790| // rule with '<' is used
3791|-> if (reslen > 0 && ws != NULL && *ws != NUL
3792| && (wres[reslen - 1] == c
3793| || wres[reslen - 1] == *ws))
Error: OVERRUN (CWE-119):
vim91/src/spell.c:3819: cond_const: Checking "reslen < 254" implies that
"reslen" is 254 on the false branch.
vim91/src/spell.c:3833: overrun-local: Overrunning array "wres" of 254
4-byte elements at element index 254 (byte offset 1019) using index
"reslen++" (which evaluates to 254).
3831| {
3832| if (c != NUL)
3833|-> wres[reslen++] = c;
3834| mch_memmove(word, word + i + 1,
3835| sizeof(int) * (wordlen -
(i + 1) + 1));
related: vim/vim#1616339a94d2048
Co-authored-by: Zdenek Dohnal <zdohnal@redhat.com>
Problem: Missing information in CompleteDone event
Solution: add complete_word and complete_type to v:event dict
(glepnir)
closes: vim/vim#161531c5a120a70
In order to run the marktree unit test in release mode, the test functions need to be available even when NDEBUG is defined.
Keep the body of marktree_check a nop during release builds, which limits the usefulness of the testing, but at least lets the tests run.
In order to run unittests with a release build, we need the test
functions to be accessible when NDEBUG is defined. Moving the functions
into the test fixture ensures they are available and only available for
use by the unit tests.
Problem:
- nvim_subscribe, nvim_unsubscribe were deprecated in
aec4938a21 but this wasn't set in the
API metadata.
- The function annotations
```
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY FUNC_API_DEPRECATED_SINCE(13)
```
cause this test to fail:
```
RUN T3 api metadata functions are compatible with old metadata or have new level: 3.00 ms ERR
test/functional/api/version_spec.lua:135: function vim_subscribe was removed but exists in level 0 which nvim should be compatible with
stack traceback:
test/functional/api/version_spec.lua:135: in function <test/functional/api/version_spec.lua:128>
```
Solution:
- Set the API metadata.
- Rearrange the annotations so that FUNC_API_DEPRECATED_SINCE is 2nd:
```
FUNC_API_SINCE(1) FUNC_API_DEPRECATED_SINCE(13) FUNC_API_REMOTE_ONLY
```
In particular, make the distinction and interaction between "noinsert"
and "noselect" clearer as it was very confusing before.
closes: vim/vim#16148768728b487
Co-authored-by: dundargoc <gocdundar@gmail.com>
Problem: completion list wrong after v9.1.0891
Solution: update compl_mach_array after leader change
(glepnir)
compl_shown_match update not correct after refactoring in v9.1.0891
Unfortunately, this regressed what item is selected after leader change.
So generate compl_match_array before updating compl_shown_match range,
and split generate compl_match_array into range match_head
fixes: https://github.com/vim/vim/issues/16128
closes: https://github.com/vim/vim/pull/16129a49c077a88
Problem: building the completion list array is inefficient
Solution: refactor and improve ins_compl_build_pum() func
(glepnir)
current time complexity is O(n^2). I guess garray is not used here to save memory and avoid efficiency
is caused by heap memory allocation. A simple way is to add an extra pointer as a single linked list
to store the matching compl_T, and traverse this single linked list to generate compl_match_array.
The time complexity is O(n x m). The worst case is m=n, but we can still get a little improvement.
Because the if condition does not need to be run at one time. This should be a good solution for now.
Later we may be able to complete it in O(lgn) time. But this requires more reconstruction. So this is
the first step.
closes: #1612580b662009c
Problem:
gen_declarations.lua is complex and has duplicate logic with
c_grammar.lua
Solution:
Move all lpeg logic to c_grammar.lua and refactor gen_declarations.lua.
Problem: the max value of 'cmdheight' is limited by other tabpages
Solution: Limit the maximum value of 'cmdheight' to the current tabpage only.
(Milly)
The Help says that cmdheight is local to the tab page, but says nothing
about the maximum value depending on the state of all tab pages. Users
may wonder why they can't increase cmdheight when there are still rows
available on the current tab page. This PR changes the behavior of
cmdheight so that its maximum value depends only on the state of the
current tab page.
Also, since magic numbers were embedded in various places with the
minimum value of cmdheight being 1, we defined a constant to make it
easier to understand.
closes: vim/vim#161312cddf0e85a
Cherry-pick Test_cmdheight_not_changed() from patch 9.0.0187.
Co-authored-by: Milly <milly.ca@gmail.com>