Skip to content

Conversation

@soifou
Copy link
Collaborator

@soifou soifou commented Mar 31, 2025

Correct the comparison logic in within_query_bounds by ensuring the
start column check uses > instead of >=. This resolves an off-by-one
error introduced in commit 60a571e when
converting the cursor column from 0-indexed to 1-indexed.

Fix #1500
Related #1548

Correct the comparison logic in `within_query_bounds` by ensuring the
start column check uses `>` instead of `>=`. This resolves an off-by-one
error introduced in commit 60a571e when
converting the cursor column from 0-indexed to 1-indexed.

Fix #1500
@saghen saghen merged commit b83ffad into main Apr 1, 2025
6 checks passed
@saghen
Copy link
Owner

saghen commented Apr 1, 2025

Thanks!

@soifou soifou deleted the fix/within-query-bound branch April 1, 2025 20:54
@saghen
Copy link
Owner

saghen commented Apr 1, 2025

After this change, deleting characters onto a trigger character no longer maintains the list, this should be special cased

a.b|
-- user types "<BS>"
a.

And it looks like the prefetched values are typically not used since the following causes the context to change. This seems to be the root cause of #1500, so perhaps we should show the prefetched values and asynchronously make a fresh request to all the sources

| -- <- Context id: 1
-- user types "a"
a| -- Context id: 2

This function is the bane of my existence

@soifou
Copy link
Collaborator Author

soifou commented Apr 2, 2025

Hey, it's been a busy day here! I knew this was going to be touchy to modify this part.

I'll see if I can come up with something to address both of these issues. Your proposal to keep the prefetched values while making an async fresh request seems fine to me as I don't see a better option right now.

@saghen
Copy link
Owner

saghen commented Apr 2, 2025

Hey, don't feel like you need to make the change! I'll take a look when I've got some time. I had to write it down because I'd forget :D

@soifou
Copy link
Collaborator Author

soifou commented Apr 2, 2025

deleting characters onto a trigger character no longer maintains the list, this should be special cased

this simple change actually fixes it

diff --git a/lua/blink/cmp/completion/trigger/init.lua b/lua/blink/cmp/completion/trigger/init.lua
index f9f205b..0165e30 100644
--- a/lua/blink/cmp/completion/trigger/init.lua
+++ b/lua/blink/cmp/completion/trigger/init.lua
@@ -89,19 +89,22 @@ local function on_cursor_moved(event, is_ignored)
     return
   end

+  local is_trigger_character = trigger.is_trigger_character(char_under_cursor, true)
+
   -- TODO: doesn't handle `a` where the cursor moves immediately after
   -- Reproducible with `example.|a` and pressing `a`, should not show the menu
   local insert_enter_on_trigger_character = config.show_on_trigger_character
     and config.show_on_insert_on_trigger_character
     and is_enter_event
-    and trigger.is_trigger_character(char_under_cursor, true)
+    and is_trigger_character

   -- check if we're still within the bounds of the query used for the context
   if trigger.context ~= nil and trigger.context:within_query_bounds(cursor) then
     trigger.show({ trigger_kind = 'keyword' })

   -- check if we've entered insert mode on a trigger character
-  elseif insert_enter_on_trigger_character then
+  -- or if we encounter a trigger character (eg. by removing a char)
+  elseif insert_enter_on_trigger_character or is_trigger_character then
     trigger.context = nil
     trigger.show({ trigger_kind = 'trigger_character', trigger_character = char_under_cursor })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocompletions only after re-entering insert mode with jsonls

3 participants