Skip to content

Commit 748a24c

Browse files
committed
Do not show delayed responses if line changed or cursor retreated
1 parent 2e11906 commit 748a24c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/jupyterlab-lsp/src/features/completion/completion_handler.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class LSPConnector
401401

402402
this.console.debug('All promises set up and ready.');
403403
return promise.then(reply => {
404-
reply = this.suppress_if_needed(reply, token);
404+
reply = this.suppress_if_needed(reply, token, cursor);
405405
this.items = reply.items;
406406
this.trigger_kind = CompletionTriggerKind.Invoked;
407407
return reply;
@@ -610,8 +610,24 @@ export class LSPConnector
610610

611611
private suppress_if_needed(
612612
reply: CompletionHandler.ICompletionItemsReply,
613-
token: CodeEditor.IToken
613+
token: CodeEditor.IToken,
614+
cursor_at_request: CodeEditor.IPosition
614615
) {
616+
const cursor_now = this._editor.getCursorPosition();
617+
618+
// if the cursor advanced in the same line, the previously retrieved completions may still be useful
619+
// if the line changed or cursor moved backwards then no reason to keep the suggestions
620+
if (
621+
cursor_at_request.line != cursor_now.line ||
622+
cursor_now.column < cursor_at_request.column
623+
) {
624+
return {
625+
start: reply.start,
626+
end: reply.end,
627+
items: []
628+
};
629+
}
630+
615631
if (this.trigger_kind == AdditionalCompletionTriggerKinds.AutoInvoked) {
616632
if (
617633
// do not auto-invoke if no match found

0 commit comments

Comments
 (0)