Skip to content

Commit

Permalink
Deduplicate kernel completions including * prefix from pylance (#16286
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DonJayamanne authored Dec 11, 2024
1 parent 1706ffd commit f80bf70
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/standalone/intellisense/kernelCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,24 @@ class NotebookCellSpecificKernelCompletionProvider implements CompletionItemProv

const existingCompletionItems = new Set(
(otherCompletions || [])
.map((item) => (typeof item.label === 'string' ? item.label : item.label.label))
// Jupyter kernel might return items prefixed with the `.` character.
.map((item) => [item, `.${item}`])
.map((item) => {
const label = typeof item.label === 'string' ? item.label : item.label.label;
const insertText = item.insertText;
// Jupyter kernel might return items prefixed with the `.` character.
const items = [label, `.${label}`];
if (typeof insertText === 'string') {
// Sometimes the labels returned by pylance can contain text like `* abspath`.
// I.e. containing a prefix `*` followed by a space and then the text.
items.push(insertText);
}
return items;
})
.flat()
);
return completions.filter(
(item) => !existingCompletionItems.has(typeof item.label === 'string' ? item.label : item.label.label)
);
return completions.filter((item) => {
const label = typeof item.label === 'string' ? item.label : item.label.label;
return !existingCompletionItems.has(label) && !existingCompletionItems.has(`* ${label}`);
});
} catch (ex) {
if (ex instanceof RequestTimedoutError) {
return [];
Expand Down

0 comments on commit f80bf70

Please sign in to comment.