Skip to content
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

Allow per-character autocompletion window movement #344

Closed
mcauley-penney opened this issue Nov 18, 2024 · 9 comments
Closed

Allow per-character autocompletion window movement #344

mcauley-penney opened this issue Nov 18, 2024 · 9 comments
Labels
backlog Likely not getting to it anytime soon feature New feature or request windows Module which displays UI

Comments

@mcauley-penney
Copy link

mcauley-penney commented Nov 18, 2024

Feature Description

Desired behavior

VSCode allows for the autocompletion window to move per-character. This means that, for each character typed, the autocompletion window will update to the position of the cursor in the buffer. This GIF from VSCode's IntelliSense documentation displays this.

intellisense_packagejson

Current behavior

As of now, blink does not allow for this. It only updates per-word; the autocompletion window will not move until the current word is completed.

Related

This was a feature I and another user implemented in nvim-cmp (hrsh7th/nvim-cmp#1727), so there is a precedent not only from another editor but also from the existing nvim ecosystem.

@mcauley-penney mcauley-penney added the feature New feature or request label Nov 18, 2024
@Saghen
Copy link
Owner

Saghen commented Nov 18, 2024

Blink originally worked this way but that was phased out for aligning the window to the word being typed. Why do you prefer this behavior?

@mcauley-penney
Copy link
Author

mcauley-penney commented Nov 18, 2024

That's a good question. I think that the window not moving with the cursor makes something about typing feel disjointed. This feels more natural, even if there is an argument to be made for the movement making things feel more jittery or unreadable. I think the motion feels comfortable.

Edit: also, to be explicit, I don't think that this should be the only option or the default. It would just be nice to have this as a setting that can be toggled.

@s-cerevisiae

This comment was marked as outdated.

@mcauley-penney
Copy link
Author

@s-cerevisiae If I understand correctly, that's already the default behavior. I'm interested in a second option that is similar to VSCode.

@Saghen
Copy link
Owner

Saghen commented Nov 18, 2024

Yeah that's the default behavior on main, but not on the latest release, just to clarify

@Saghen Saghen added windows Module which displays UI backlog Likely not getting to it anytime soon labels Nov 18, 2024
@mcauley-penney
Copy link
Author

Attached is a patch that allows users to experiment with this. It doesn't include any configuration options to modify column offset or to turn the feature on and off (although I'd be happy to create that if there was interest). This is just a tiny POC.

diff --git a/lua/blink/cmp/completion/windows/menu.lua b/lua/blink/cmp/completion/windows/menu.lua
index 969f99e..81b469a 100644
--- a/lua/blink/cmp/completion/windows/menu.lua
+++ b/lua/blink/cmp/completion/windows/menu.lua
@@ -120,9 +120,8 @@ function menu.update_position()
       col = math.max(cmdline_position[2] + context.bounds.start_col - start_col, 0),
     })
   else
-    local cursor_col = context.get_cursor()[2]
-    local col = context.bounds.start_col - cursor_col - (context.bounds.length == 0 and 0 or 1) - border_size.left
-    win:set_win_config({ relative = 'cursor', row = row, col = col - start_col })
+    local col = 0
+    win:set_win_config({ relative = 'cursor', row = row, col = col })
   end
 
   win:set_height(pos.height)

@Saghen
Copy link
Owner

Saghen commented Dec 24, 2024

Looks good! I'daccept a PR for it. Let's rename completion.menu.draw.align_to_component to align_to and add a 'cursor' option for it

@Saghen Saghen closed this as completed in 9387c75 Dec 24, 2024
@mcauley-penney
Copy link
Author

I just forked to work on this! Thank you for implementing this. I spent the day working on research yesterday and planned on doing this today.

@Saghen
Copy link
Owner

Saghen commented Dec 24, 2024

Np! Thanks for the diff, made it super easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Likely not getting to it anytime soon feature New feature or request windows Module which displays UI
Projects
None yet
Development

No branches or pull requests

3 participants