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

fix: respect user-preferred flags when canceling completions #2541

Merged
merged 2 commits into from
Nov 2, 2024

Conversation

rchl
Copy link
Member

@rchl rchl commented Oct 30, 2024

I haven't noticed this issue in practice (or if I did then it's subtle enough to not raise suspicion) but when looking at this code I've realized that the case when completions are canceled is not quite right since in that case we'd tell ST that we got empty completions and we'd pass the sublime.AutoCompleteFlags.NONE flag. The flag is the issue since we don't consider user's settings like inhibit_snippet_completions and inhibit_word_completions so in the case when completions would get canceled, we'd let ST show buffer and snippet completions which is not what the user expects.

It's kinda hard to test. I think this is only a potential issue for servers that return dynamic completions (like pyright) since then it's more likely that the completion request will get canceled on typing. But since pyright is very fast (at least in my small projects), it's hard to trigger that case (the new completions will come very fast after previous were canceled). I did a change like this to verify that what I said happens (user prefs are not respected):

diff --git a/plugin/completion.py b/plugin/completion.py
index 6e429290..68d83f45 100644
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -197,6 +197,7 @@ class QueryCompletionsTask:
         promise, request_id = session.send_request_task_2(request)
         weak_session = weakref.ref(session)
         self._pending_completion_requests[request_id] = weak_session
+        self.cancel_async()
         return promise.then(lambda response: self._on_completion_response_async(response, request_id, weak_session))
 
     def _on_completion_response_async(

@rchl rchl changed the title fix: use user-preferred flags when canceling completions fix: respect user-preferred flags when canceling completions Oct 30, 2024
@rchl rchl merged commit 2b3a48c into main Nov 2, 2024
8 checks passed
@rchl rchl deleted the fix/cancel-completions-flags branch November 2, 2024 10:44
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.

2 participants