Skip to content

Commit fb90252

Browse files
committed
Test the completer in FileEditor (& fix related setup issue)
1 parent 9aa8f76 commit fb90252

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

atest/05_Features/Completion.robot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Works When Kernel Is Shut Down
3939
# this comes from kernel:
4040
Completer Should Not Suggest %%timeit
4141

42+
Works In File Editor
43+
Prepare File for Editing Python completion completion.py
44+
Place Cursor In File Editor At 9 2
45+
Capture Page Screenshot 01-editor-ready.png
46+
Trigger Completer
47+
Completer Should Suggest add
48+
[Teardown] Clean Up After Working With File completion.py
49+
4250
Autocompletes If Only One Option
4351
Enter Cell Editor 3 line=1
4452
Press Keys None cle

atest/Keywords.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ Place Cursor In Cell Editor At
263263
Enter Cell Editor ${cell_nr} ${line}
264264
Execute JavaScript return document.querySelector('.jp-Cell:nth-child(${cell_nr}) .CodeMirror').CodeMirror.setCursor({line: ${line} - 1, ch: ${character}})
265265

266+
Enter File Editor
267+
Click Element css:.jp-FileEditor .CodeMirror
268+
Wait Until Page Contains Element css:.jp-FileEditor .CodeMirror-focused
269+
270+
Place Cursor In File Editor At
271+
[Arguments] ${line} ${character}
272+
Enter File Editor
273+
Execute JavaScript return document.querySelector('.jp-FileEditor .CodeMirror').CodeMirror.setCursor({line: ${line} - 1, ch: ${character}})
274+
266275
Wait Until Fully Initialized
267276
Wait Until Element Contains ${STATUSBAR} Fully initialized timeout=60s
268277

atest/examples/completion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
addition = ''
2+
3+
4+
def add(a: int, b: int):
5+
"""Adds a and b together"""
6+
return a, b
7+
8+
9+
ad

packages/jupyterlab-lsp/src/adapters/adapter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
8787
EditorAdapter<IVirtualEditor<IEditor>>
8888
>;
8989
public adapterConnected: Signal<WidgetAdapter<T>, IDocumentConnectionData>;
90+
public isConnected: boolean;
9091
public connection_manager: DocumentConnectionManager;
9192
public status_message: StatusMessage;
9293
protected isDisposed = false;
@@ -117,6 +118,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
117118
this.activeEditorChanged = new Signal(this);
118119
this.adapters = new Map();
119120
this.status_message = new StatusMessage();
121+
this.isConnected = false;
120122

121123
// set up signal connections
122124
this.widget.context.saveState.connect(this.on_save_state, this);
@@ -268,6 +270,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
268270

269271
this.connect_adapter(data.virtual_document, data.connection);
270272
this.adapterConnected.emit(data);
273+
this.isConnected = true;
271274

272275
await this.update_documents().then(() => {
273276
// refresh the document on the LSP server

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
8585
manager: ILSPAdapterManager,
8686
adapter: WidgetAdapter<IDocumentWidget>
8787
) {
88+
console.log('ADAPTER CHANGED TO ', adapter);
8889
if (this.current_adapter) {
8990
// disconnect signals from the old adapter
9091
this.current_adapter.activeEditorChanged.disconnect(
@@ -97,13 +98,17 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
9798
);
9899
}
99100
this.current_adapter = adapter;
101+
// connect the new adapter
102+
if (this.current_adapter.isConnected) {
103+
this.connect_completion(this.current_adapter);
104+
this.set_connector(adapter, { editor: adapter.activeEditor });
105+
}
100106
// connect signals to the new adapter
101107
this.current_adapter.activeEditorChanged.connect(this.set_connector, this);
102108
this.current_adapter.adapterConnected.connect(
103109
this.connect_completion,
104110
this
105111
);
106-
this.set_connector(adapter, { editor: adapter.activeEditor });
107112
}
108113

109114
connect_completion(

0 commit comments

Comments
 (0)