Skip to content

Commit a209d6f

Browse files
committed
Invalidate delayed completion if cell changed or lost focus
1 parent 7945858 commit a209d6f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

atest/05_Features/Completion.robot

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ Works When Kernel Is Idle
2929
${content} = Get Cell Editor Content 1
3030
Should Contain ${content} TabError
3131

32+
Invalidates On Cell Change
33+
Enter Cell Editor 1 line=2
34+
Press Keys None TAB
35+
Enter Cell Editor 2
36+
# just to increase chances of caching this on CI (which is slow)
37+
Sleep 5s
38+
Completer Should Not Suggest test
39+
40+
Invalidates On Focus Loss
41+
Enter Cell Editor 1 line=2
42+
Press Keys None TAB
43+
Enter Cell Editor 2
44+
# just to increase chances of caching this on CI (which is slow)
45+
Sleep 5s
46+
Completer Should Not Suggest test
47+
3248
Uses LSP Completions When Kernel Resoponse Times Out
3349
Configure JupyterLab Plugin {"kernelResponseTimeout": 1, "waitForBusyKernel": true} plugin id=${COMPLETION PLUGIN ID}
3450
Should Complete While Kernel Is Busy
@@ -87,7 +103,6 @@ Continious Hinting Works
87103
Autocompletes If Only One Option
88104
Enter Cell Editor 3 line=1
89105
Press Keys None cle
90-
Wait Until Fully Initialized
91106
# First tab brings up the completer
92107
Press Keys None TAB
93108
Completer Should Suggest clear
@@ -99,7 +114,6 @@ Autocompletes If Only One Option
99114
Does Not Autocomplete If Multiple Options
100115
Enter Cell Editor 3 line=1
101116
Press Keys None c
102-
Wait Until Fully Initialized
103117
# First tab brings up the completer
104118
Press Keys None TAB
105119
Completer Should Suggest copy

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,15 @@ export class LSPConnector
618618
token: CodeEditor.IToken,
619619
cursor_at_request: CodeEditor.IPosition
620620
) {
621+
if (!this._editor.hasFocus()) {
622+
this.console.debug('Ignoring completion response: the corresponding editor lost focus')
623+
return {
624+
start: reply.start,
625+
end: reply.end,
626+
items: []
627+
};
628+
}
629+
621630
const cursor_now = this._editor.getCursorPosition();
622631

623632
// if the cursor advanced in the same line, the previously retrieved completions may still be useful
@@ -626,6 +635,7 @@ export class LSPConnector
626635
cursor_at_request.line != cursor_now.line ||
627636
cursor_now.column < cursor_at_request.column
628637
) {
638+
this.console.debug('Ignoring completion response: cursor has receded or changed line')
629639
return {
630640
start: reply.start,
631641
end: reply.end,

0 commit comments

Comments
 (0)