Skip to content

Conversation

EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented May 11, 2025

Problem:

Some LSPs cause the following completion error (reformatted slightly):

Error executing vim.schedule lua callback: .../runtime/lua/vim/lsp/completion.lua:373
attempt to index field 'range' (a nil value)

This is because an internal function assumes edits are either missing or of type TextEdit, but there's a third possibility that's not handled: the InsertReplaceEdit.

This was previously reported in at least two issues:

Solution:

Don't assume the edit is a TextEdit. This implicitly handles InsertReplaceEdits.

Also, add a test case for this, which previously caused an error.

(I recommend reviewing this with whitespace changes disabled.)

@github-actions github-actions bot added the lsp label May 11, 2025
**Problem:**

Some LSPs cause the following completion error (reformatted slightly):

    Error executing vim.schedule lua callback:
    .../runtime/lua/vim/lsp/completion.lua:373
    attempt to index field 'range' (a nil value)

This is because an internal function assumes edits are either missing
or of type `TextEdit`, but there's a third [possibility][0] that's not
handled: the `InsertReplaceEdit`.

This was previously reported in at least two issues:

- <neovim#33142>
- <neovim#33224>

**Solution:**

Don't assume the edit is a `TextEdit`. This implicitly handles
`InsertReplaceEdit`s.

Also, add a test case for this, which previously caused an error.

(I recommend reviewing this with whitespace changes disabled.)

[0]: https://github.com/neovim/neovim/blob/2c07428966a74c76003e00e2a37bf98eb8802c93/runtime/lua/vim/lsp/_meta/protocol.lua#L1099
@EvanHahn EvanHahn force-pushed the fix-lsp-with-insert-replace-edits branch from 3cc6340 to d43da2b Compare May 11, 2025 19:42
@EvanHahn EvanHahn marked this pull request as ready for review May 12, 2025 01:19
@github-actions github-actions bot requested a review from MariaSolOs May 12, 2025 01:19
@justinmk
Copy link
Member

looks great, thanks for the clear explanation.

This was previously reported in at least two issues:

does this close those issues?

@EvanHahn
Copy link
Contributor Author

I believe it solves #33142.

@justinmk justinmk merged commit 927927e into neovim:master May 22, 2025
40 checks passed
@github-actions github-actions bot removed the request for review from MariaSolOs May 22, 2025 13:22
github-actions bot pushed a commit that referenced this pull request May 22, 2025
Problem:
Some LSPs cause the following completion error (reformatted slightly):

    Error executing vim.schedule lua callback:
    .../runtime/lua/vim/lsp/completion.lua:373
    attempt to index field 'range' (a nil value)

This is because an internal function assumes edits are either missing
or of type `TextEdit`, but there's a third [possibility][0] that's not
handled: the `InsertReplaceEdit`.

This was previously reported in at least two issues:

- #33142
- #33224

Solution:
Don't assume the edit is a `TextEdit`. This implicitly handles
`InsertReplaceEdit`s.

Also, add a test case for this, which previously caused an error.

[0]: https://github.com/neovim/neovim/blob/2c07428966a74c76003e00e2a37bf98eb8802c93/runtime/lua/vim/lsp/_meta/protocol.lua#L1099

(cherry picked from commit 927927e)
@neovim-backports
Copy link

Successfully created backport PR for release-0.11:

github-actions bot pushed a commit that referenced this pull request May 22, 2025
Problem:
Some LSPs cause the following completion error (reformatted slightly):

    Error executing vim.schedule lua callback:
    .../runtime/lua/vim/lsp/completion.lua:373
    attempt to index field 'range' (a nil value)

This is because an internal function assumes edits are either missing
or of type `TextEdit`, but there's a third [possibility][0] that's not
handled: the `InsertReplaceEdit`.

This was previously reported in at least two issues:

- #33142
- #33224

Solution:
Don't assume the edit is a `TextEdit`. This implicitly handles
`InsertReplaceEdit`s.

Also, add a test case for this, which previously caused an error.

[0]: https://github.com/neovim/neovim/blob/2c07428966a74c76003e00e2a37bf98eb8802c93/runtime/lua/vim/lsp/_meta/protocol.lua#L1099

(cherry picked from commit 927927e)
@EvanHahn EvanHahn deleted the fix-lsp-with-insert-replace-edits branch May 22, 2025 13:55
@EvanHahn
Copy link
Contributor Author

Thank you! Excited to see my small change make it into software I use every day.

clason pushed a commit to clason/neovim that referenced this pull request May 23, 2025
Problem:
Some LSPs cause the following completion error (reformatted slightly):

    Error executing vim.schedule lua callback:
    .../runtime/lua/vim/lsp/completion.lua:373
    attempt to index field 'range' (a nil value)

This is because an internal function assumes edits are either missing
or of type `TextEdit`, but there's a third [possibility][0] that's not
handled: the `InsertReplaceEdit`.

This was previously reported in at least two issues:

- neovim#33142
- neovim#33224

Solution:
Don't assume the edit is a `TextEdit`. This implicitly handles
`InsertReplaceEdit`s.

Also, add a test case for this, which previously caused an error.

[0]: https://github.com/neovim/neovim/blob/2c07428966a74c76003e00e2a37bf98eb8802c93/runtime/lua/vim/lsp/_meta/protocol.lua#L1099
bfredl added a commit that referenced this pull request May 30, 2025
This is a maintenance release, focusing on bug fixes. Some enhancements related
to vim.lsp.enable are also included.

FEATURES
--------------------------------------------------------------------------------
- 4e43264 lsp: vim.lsp.is_enabled() #33703
- c4b9bdb lsp: start/stop LSPs as necessary during vim.lsp.enable() #33702
- 216c56b lsp: detach LSP clients when 'filetype' changes #33707
- 533ec6d lsp: `root_markers` can control priority
- ad7211a checkhealth: trigger FileType event after showing report
- f25f6c8 health: summary in section heading #33388

FIXES
--------------------------------------------------------------------------------
- 710d561 lsp: don't eagerly enable LSP configs during startup #33762
- 0ed06d7 lsp: check if client is stopping before reuse #33796
- f184c56 lsp: detect if Client:request resolved synchronously #33624
- b868257 lsp: fix error with InsertReplaceEdit events #33973
- 6b69b32 lsp: improper diagnostic end_col computation
- e512c95 lsp: improve error completion message #33812
- 47686a1 lsp: only auto-detach lsp.config clients #33834
- 901eeeb lsp: use `bufnr` when getting clients in `symbols_to_items` (#33760)
- a242902 :print: don't use schar_from_ascii() for illegal byte (#34046)
- 4b6caa9 cmdline: do not move UI cursor when entering cmdline #33729
- fd8e0ae decor: extmark highlight not applied (#33858)
- 81233a4 display: adjust setting winline info for concealed lines (#33717)
- 4cb2b19 folds: adjust filler text drawing for transparent folds
- bdd8498 folds: avoid unnecessary loop with horizontal scrolling (#33932)
- 32842b0 health: checkhealth float opens extra empty buffer #33648
- dc87a0d lua: vim.validate `message` param #33675
- 334d8f5 move: consume skipcol before revealing filler lines (#34143)
- 6a87b57 runtime: 'includeexpr' with non-Nvim-style Lua modules #33867
- 2b2a344 runtime: conceal paths in help, man ToC loclist #33764
- 3db39ed runtime: cpoptions is reset in Lua file #33671
- cefc91a system: don't treat NUL at start as no input (#34167)
- 8daffd0 terminal: check size when switching buffers
- 0db8946 termkey: out-of-bounds write in array #33868
- 6563c6b treesitter: close `:InspectTree` with `q`
- 5c6ee25 treesitter: eliminate flicker for single windows #33842
- 3b3cf1d treesitter: invalidate conceal_lines marks (#33832)
- 58460e2 treesitter: parser metadata annotations
- 034d3c8 treesitter: proper tree `contains()` logic with combined injections
- 560c6ca trust: support for trusting directories #33735
- 12ae7aa tui: clear primary device callback before invoking it (#34032)
- 4296511 tui: don't process UI events when suspending or stopping (#33710)
- cf73f21 tui: don't try to add unsupported modifiers (#33799)
- 465c181 tui: forward C0 control codes literally (#33759)
- 0c2bf55 tutor: l:lang is undefined
- 3a0d376 vim.system: improve error message when cwd does not exist
- 9b34266 window: skip unfocusable and hidden floats with "{count}<C-W>w" #33810

VIM PATCHES
--------------------------------------------------------------------------------
- 9965cfb 9.1.1361: [security]: possible use-after-free when closing a buffer (#33820)
- 3c10230 9.1.1375: [security]: possible heap UAF with quickfix dummy buffer
- 1921dda 3704b5b: runtime(tutor): improve tutor.vim plugin and filetype plugin
- 4e5af2f 5a8f995: runtime(doc): remove outdated Contribution section in pi_tutor (#34094)
- 3273c59 829eda7: runtime(new-tutor): update tutor and correct comandline completion
- 3e83a33 9.1.1297: Ctrl-D scrolling can get stuck #33453
- 6417ba0 9.1.1376: quickfix dummy buffer may remain as dummy buffer
- 30fa1c5 9.1.1380: 'eventignorewin' only checked for current buffer
- 6b140ae 9.1.1384: still some problem with the new tutors filetype plugin
- f623fad 9.1.1385: inefficient loop for 'nosmoothscroll' scrolling (#33992)
- d50f71d 9.1.1387: memory leak when buflist_new() fails to reuse curbuf
- 27abf5c 9.1.1388: Scrolling one line too far with 'nosmoothscroll' page scrolling (#34023)
- 917f496 9.1.1395: search_stat not reset when pattern differs in case (#34058)
- b07bffd 9.1.1402: multi-byte mappings not properly stored in session file (#34131)
- ff83c71 9.1.1405: tests: no test for mapping with special keys in session file (#34146)
- d1ca551 9.1.1407: Can't use getpos('v') in OptionSet when using setbufvar() (#34177)

DOCUMENTATION
--------------------------------------------------------------------------------
- e5e69f7 add missing change to getcharstr() signature (#33797)
- 95ee908 backport #33549 and #33524 to 0.11 (#33678)
- 472d41b default mappings #33706
- 3a4d393 fixups (#33815)
- fa292e6 lsp, emoji, startup #33683
- 714622f lsp, lua #33682
- d68d212 provide example_init.lua #33524
- 968947b lua: typing for vim.fn.winlayout #33817
- e304677 tutor: move lesson 7.2 below lesson 7.3 #33662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error using native nvim lsp completion in some language servers
2 participants