Skip to content

Commit ef333ce

Browse files
authored
Fix completions when type is not defined (#1044)
* Fix completions when `type` is not defined * Fix linting
1 parent fdd3aff commit ef333ce

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,22 @@ export class LSPCompletionRenderer
4949
);
5050
}
5151

52-
protected getExtraInfo(item: CompletionItem): string {
52+
protected getExtraInfo(
53+
item: CompletionItem | IExtendedCompletionItem
54+
): string | undefined {
5355
const labelExtra = this.options.settings.composite.labelExtra;
56+
const detail = 'detail' in item ? item?.detail ?? '' : '';
5457
switch (labelExtra) {
5558
case 'detail':
56-
return item?.detail || '';
59+
return detail;
5760
case 'type':
5861
return item?.type?.toLowerCase?.();
5962
case 'source':
6063
return item?.source;
6164
case 'auto':
62-
return [
63-
item?.detail || '',
64-
item?.type?.toLowerCase?.(),
65-
item?.source
66-
].filter(x => !!x)[0];
65+
return [detail, item?.type?.toLowerCase?.(), item?.source].filter(
66+
x => !!x
67+
)[0];
6768
default:
6869
this.options.console.warn(
6970
'labelExtra does not match any of the expected values',
@@ -73,7 +74,10 @@ export class LSPCompletionRenderer
7374
}
7475
}
7576

76-
public updateExtraInfo(item: CompletionItem, li: HTMLLIElement) {
77+
public updateExtraInfo(
78+
item: CompletionItem | IExtendedCompletionItem,
79+
li: HTMLLIElement
80+
) {
7781
const extraText = this.getExtraInfo(item);
7882
if (extraText) {
7983
const extraElement = li.getElementsByClassName(this.EXTRA_INFO_CLASS)[0];
@@ -184,10 +188,11 @@ export class LSPCompletionRenderer
184188
}
185189
}
186190

187-
itemWidthHeuristic(item: CompletionItem): number {
191+
itemWidthHeuristic(item: CompletionItem | IExtendedCompletionItem): number {
188192
let labelSize = item.label.replace(/<(\/)?mark>/g, '').length;
189-
const extraTextSize = this.getExtraInfo(item).length;
190-
const type = item.type.toLowerCase();
193+
const extra = this.getExtraInfo(item);
194+
const extraTextSize = extra?.length ?? 0;
195+
const type = item.type?.toLowerCase();
191196
if (type === 'file' || type === 'path') {
192197
// account for elision
193198
const parts = item.label.split(/<\/mark>/g);

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ test = pytest
44
[flake8]
55
exclude = .git,__pycache__,envs,.ipynb_checkpoints,.mypy_cache
66
max-line-length = 88
7-
ignore = E203,W503
7+
# E704 conflicts with black (https://github.com/PyCQA/pycodestyle/issues/1036)
8+
ignore = E203,W503,E704
89

910
[isort]
1011
profile = black

0 commit comments

Comments
 (0)