Skip to content

Commit c6a0ac7

Browse files
committed
Fix loose ends in completer and its tests
1 parent 811d994 commit c6a0ac7

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

atest/05_Features/Completion.robot

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,27 @@ Autocompletes If Only One Option
4343
Enter Cell Editor 3 line=1
4444
Press Keys None cle
4545
Wait Until Fully Initialized
46+
# First tab brings up the completer
4647
Press Keys None TAB
48+
Completer Should Suggest clear
49+
# Second tab inserts the only suggestion
50+
Press Keys None TAB
51+
# depends on Python list type having only one method with prefix "cle"
4752
Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 3 list.clear
4853

54+
Does Not Autocomplete If Multiple Options
55+
Enter Cell Editor 3 line=1
56+
Press Keys None c
57+
Wait Until Fully Initialized
58+
# First tab brings up the completer
59+
Press Keys None TAB
60+
Completer Should Suggest copy
61+
# Second tab inserts should not insert the first of many choices.
62+
Press Keys None TAB
63+
# depends on Python list type having multiple methods with prefix "c"
64+
# in this case "Completer Should Suggest" means that the completer is still shown!
65+
Completer Should Suggest copy
66+
4967
User Can Select Lowercase After Starting Uppercase
5068
# `from time import Tim<tab>` → `from time import time`
5169
Enter Cell Editor 5 line=1
@@ -58,12 +76,16 @@ Mid Token Completions Do Not Overwrite
5876
# `disp<tab>data` → `display_table<cursor>data`
5977
Place Cursor In Cell Editor At 9 line=1 character=4
6078
Capture Page Screenshot 01-cursor-placed.png
61-
Press Keys None TAB
79+
Trigger Completer
80+
Completer Should Suggest display_table
81+
Select Completer Suggestion display_table
6282
Capture Page Screenshot 02-completed.png
6383
Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 9 display_tabledata
6484
# `disp<tab>lay` → `display_table<cursor>`
6585
Place Cursor In Cell Editor At 11 line=1 character=4
66-
Press Keys None TAB
86+
Trigger Completer
87+
Completer Should Suggest display_table
88+
Select Completer Suggestion display_table
6789
Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 11 display_table
6890

6991
Completion Works For Tokens Separated By Space

packages/jupyterlab-lsp/src/adapters/jupyterlab/components/completion.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class LSPConnector
198198
let connection = this._connections.get(document.id_path);
199199

200200
console.log('[LSP][Completer] Fetching and Transforming');
201-
console.log('[LSP][Completer] Token:', token);
201+
console.log('[LSP][Completer] Token:', token, start, end);
202202

203203
let lspCompletionItems = ((await connection.getCompletion(
204204
cursor,
@@ -278,7 +278,10 @@ export class LSPConnector
278278
label: item.text as string,
279279
insertText: item.text as string,
280280
type: item.type as string,
281-
icon: typeof item.type === 'undefined' ? kernelIcon : undefined
281+
icon:
282+
typeof item.type === 'undefined' || item.type == '<unknown>'
283+
? kernelIcon
284+
: undefined
282285
};
283286
});
284287
} else {
@@ -325,9 +328,6 @@ export class LSPConnector
325328
kernel.items.map(item => {
326329
return {
327330
...item,
328-
label: item.label.startsWith(prefix)
329-
? item.label.substr(prefix.length)
330-
: item.label,
331331
insertText: item.insertText.startsWith(prefix)
332332
? item.insertText.substr(prefix.length)
333333
: item.insertText
@@ -338,13 +338,7 @@ export class LSPConnector
338338
const processedItems = new Array<CompletionHandler.ICompletionItem>();
339339

340340
aggregatedItems.forEach(item => {
341-
if (
342-
// For some reason the _jupyter_types_experimental list has two entries
343-
// for each match, with one having a type of "<unknown>". Discard those
344-
// and use undefined to indicate an unknown type.
345-
insertTextSet.has(item.insertText) ||
346-
(item.type && item.type === '<unknown>')
347-
) {
341+
if (insertTextSet.has(item.insertText)) {
348342
return;
349343
}
350344
insertTextSet.add(item.insertText);

0 commit comments

Comments
 (0)