Skip to content

Commit 5f70fe1

Browse files
authored
Improve item width size estimation heuristic support (#1025)
The issue was that: - (a) heuristic did not account for eliding - (b) styles limiting the width were not applied when the widest item size was calculated after temporarily re-parenting to `<body>` - (c) there was no limit on ellipsis width (now its 50% of label) - (d) the label size limit maybe was too low, it got increased by 50px
1 parent 663f187 commit 5f70fe1

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

packages/completion-theme/style/index.css

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ body[data-lsp-completer-layout] .jp-Completer-docpanel {
2323
flex-shrink: 0;
2424
}
2525

26-
body[data-lsp-completer-layout] .jp-Completer {
27-
--lsp-completer-max-label-width: 350px;
26+
body[data-lsp-completer-layout] {
27+
/* Important to use selectors which work on body so that size estimation
28+
works when the list items get temporarily attached to the body */
29+
--lsp-completer-max-label-width: 400px;
2830
--lsp-completer-max-detail-width: 200px;
2931
}
3032

3133
body[data-lsp-completer-layout] .jp-Completer-match {
32-
max-width: var(--lsp-completer-max-label-width);
34+
max-width: calc(
35+
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
36+
);
3337
overflow-x: hidden;
3438
white-space: nowrap;
3539
display: block;
@@ -80,7 +84,7 @@ body[data-lsp-completer-layout='detail-below'] .jp-Completer-match {
8084
height: var(--lsp-completer-label-height);
8185
}
8286

83-
.lsp-completer .jp-Completer-item .jp-Completer-typeExtended {
87+
body[data-lsp-completer-layout] .jp-Completer-item .jp-Completer-typeExtended {
8488
max-width: var(--lsp-completer-max-detail-width);
8589
min-height: 50px;
8690
overflow-x: hidden;
@@ -102,6 +106,8 @@ body[data-lsp-completer-layout] mark.lsp-elide:first-child {
102106
flex-shrink: 1;
103107
/* always reserve small space to fit the ellipsis */
104108
min-width: 20px;
109+
/* a reasonably long limit on the space taken by the elipsis */
110+
max-width: calc(var(--lsp-completer-max-label-width) / 2);
105111
}
106112

107113
body[data-lsp-completer-layout] .lsp-elide-wrapper {
@@ -118,16 +124,12 @@ body[data-lsp-completer-layout='detail-below'] .jp-Completer-typeExtended {
118124
position: relative;
119125
top: -2px;
120126
overflow: hidden;
121-
max-width: calc(
122-
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
123-
);
127+
max-width: var(--lsp-completer-max-label-width);
124128
}
125129

126130
body[data-lsp-completer-layout='detail-below'] .jp-Completer-match {
127131
overflow: hidden;
128-
max-width: calc(
129-
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
130-
);
132+
max-width: var(--lsp-completer-max-label-width);
131133
}
132134

133135
body[data-lsp-completer-layout='detail-below']

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,18 @@ export class LSPCompletionRenderer
185185
}
186186

187187
itemWidthHeuristic(item: CompletionItem): number {
188-
const labelSize = item.label.replace(/<(\/)?mark>/g, '').length;
188+
let labelSize = item.label.replace(/<(\/)?mark>/g, '').length;
189189
const extraTextSize = this.getExtraInfo(item).length;
190+
const type = item.type.toLowerCase();
191+
if (type === 'file' || type === 'path') {
192+
// account for elision
193+
const parts = item.label.split(/<\/mark>/g);
194+
const lastPart = parts[parts.length - 1];
195+
const proposedElipsed = lastPart.length + 3;
196+
if (proposedElipsed < labelSize) {
197+
labelSize = proposedElipsed;
198+
}
199+
}
190200
if (this.options.settings.composite.layout === 'side-by-side') {
191201
// in 'side-by-side' take the sum
192202
return labelSize + extraTextSize;

0 commit comments

Comments
 (0)