-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect cursor position for multi-line completion items #1123
Comments
Should use the text edit end line in /~https://github.com/Saghen/blink.cmp/blob/main/lua/blink/cmp/completion/accept/init.lua#L89 |
After reading the file suggested in your file, I realized that currently Below is a simple patch that can partially work (should be better than now), but there must be a lot of scenarios that are not considered, like how we should properly compute the cursor column position in a multi-line scenario. For single line completion item, it is the same as what it is now, and for multi-line completion item, it will likely set the cursor to the end of last line. In general, for multi-line completion (typically AI source), it typically ends up in the end of last lime. That's why I said it should be better than now. Let me know if this simple approach would work for you. I can submit a PR for this if you want. diff --git a/lua/blink/cmp/completion/accept/init.lua b/lua/blink/cmp/completion/accept/init.lua
index db8e288..9263196 100644
--- a/lua/blink/cmp/completion/accept/init.lua
+++ b/lua/blink/cmp/completion/accept/init.lua
@@ -86,7 +86,8 @@ local function accept(ctx, item, callback)
table.insert(all_text_edits, item.textEdit)
text_edits_lib.apply(all_text_edits)
-- TODO: should move the cursor only by the offset since text edit handles everything else?
- ctx.set_cursor({ ctx.get_cursor()[1], item.textEdit.range.start.character + #item.textEdit.newText + offset })
+ local _, n_newlines = string.gsub(item.textEdit.newText, "\n", "")
+ ctx.set_cursor({ ctx.get_cursor()[1] + n_newlines, item.textEdit.range.start.character + #item.textEdit.newText + offset })
end
-- Let the source execute the item itself |
Replace snippet-based insertion with plain text insertion for completion items generated by LLMs. Since LLM responses already contain appropriate indentation, using VSCode's snippet-style insertion mechanism would cause unwanted double-indentation, as the editor attempts to apply indentation rules on top of the pre-formatted text. Note: Currently, plain text insertion has a known upstream issue where the cursor position is incorrectly set to the end of the first suggested line instead of the last line. See Saghen/blink.cmp#1123 for progress.
Replace snippet-based insertion with plain text insertion for completion items generated by LLMs. Since LLM responses already contain appropriate indentation, using VSCode's snippet-style insertion mechanism would cause unwanted double-indentation, as the editor attempts to apply indentation rules on top of the pre-formatted text. Note: Currently, plain text insertion has a known upstream issue where the cursor position is incorrectly set to the end of the first suggested line instead of the last line. See Saghen/blink.cmp#1123 for progress.
Thanks for the patch! That helped me realize I should've been looking at the |
Make sure you have done the following
blink.cmp
<C-k>
on https://cmp.saghen.dev)Bug Description
For a completion item with multi-line
insertText
, when accept the completion, the cursor will put at the end of first line not the end of the last line.Below is two screenshots of the behavior:
Cursor should be at the end of last line, not the first line.
Relevant configuration
And this is my neovim config:
neovim
version0.10.3
blink.cmp
version0.11
The text was updated successfully, but these errors were encountered: