Skip to content

Commit 139ca5e

Browse files
committed
Invalidate signature on cell blur, change and some cursor moves
1 parent a209d6f commit 139ca5e

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

atest/05_Features/Signature.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ Triggers Signature Help After A Keystroke
1616
Wait Until Keyword Succeeds 20x 0.5s Page Should Contain Element ${SIGNATURE_BOX}
1717
Element Should Contain ${SIGNATURE_BOX} Important docstring of abc()
1818
[Teardown] Clean Up After Working With File Signature.ipynb
19+
20+
Invalidates On Cell Change
21+
Setup Notebook Python Signature.ipynb
22+
Enter Cell Editor 1 line=6
23+
Press Keys None (
24+
Enter Cell Editor 2
25+
# just to increase chances of caching this on CI (which is slow)
26+
Sleep 5s
27+
Page Should Not Contain Element ${SIGNATURE_BOX}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ export class LSPConnector
619619
cursor_at_request: CodeEditor.IPosition
620620
) {
621621
if (!this._editor.hasFocus()) {
622-
this.console.debug('Ignoring completion response: the corresponding editor lost focus')
622+
this.console.debug(
623+
'Ignoring completion response: the corresponding editor lost focus'
624+
);
623625
return {
624626
start: reply.start,
625627
end: reply.end,
@@ -635,7 +637,9 @@ export class LSPConnector
635637
cursor_at_request.line != cursor_now.line ||
636638
cursor_now.column < cursor_at_request.column
637639
) {
638-
this.console.debug('Ignoring completion response: cursor has receded or changed line')
640+
this.console.debug(
641+
'Ignoring completion response: cursor has receded or changed line'
642+
);
639643
return {
640644
start: reply.start,
641645
end: reply.end,

packages/jupyterlab-lsp/src/features/signature.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,41 @@ export class SignatureCM extends CodeMirrorIntegration {
9292
return markdown;
9393
}
9494

95-
private handleSignature(response: lsProtocol.SignatureHelp) {
95+
private handleSignature(
96+
response: lsProtocol.SignatureHelp,
97+
position_at_request: IRootPosition
98+
) {
9699
this.lab_integration.tooltip.remove();
97100

98101
this.console.log('Signature received', response);
102+
99103
if (!this.signature_character || !response || !response.signatures.length) {
104+
this.console.debug(
105+
'Ignoring signature response: cursor lost or response empty'
106+
);
100107
return;
101108
}
102109

103-
let root_position = this.signature_character;
110+
let root_position = position_at_request;
111+
112+
// if the cursor advanced in the same line, the previously retrieved completions may still be useful
113+
// if the line changed or cursor moved backwards then no reason to keep the suggestions
114+
if (
115+
position_at_request.line != root_position.line ||
116+
root_position.ch < position_at_request.ch
117+
) {
118+
this.console.debug(
119+
'Ignoring signature response: cursor has receded or changed line'
120+
);
121+
}
122+
104123
let cm_editor = this.get_cm_editor(root_position);
124+
if (!cm_editor.hasFocus()) {
125+
this.console.debug(
126+
'Ignoring signature response: the corresponding editor lost focus'
127+
);
128+
return;
129+
}
105130
let editor_position = this.virtual_editor.root_position_to_editor(
106131
root_position
107132
);
@@ -152,7 +177,7 @@ export class SignatureCM extends CodeMirrorIntegration {
152177
this.virtual_document.document_info,
153178
false
154179
)
155-
.then(help => this.handleSignature(help))
180+
.then(help => this.handleSignature(help, root_position))
156181
.catch(this.console.warn);
157182
}
158183
}

0 commit comments

Comments
 (0)