Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve item width size estimation heuristic support #1025

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/completion-theme/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ body[data-lsp-completer-layout] .jp-Completer-docpanel {
flex-shrink: 0;
}

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

body[data-lsp-completer-layout] .jp-Completer-match {
max-width: var(--lsp-completer-max-label-width);
max-width: calc(
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
);
overflow-x: hidden;
white-space: nowrap;
display: block;
Expand Down Expand Up @@ -80,7 +84,7 @@ body[data-lsp-completer-layout='detail-below'] .jp-Completer-match {
height: var(--lsp-completer-label-height);
}

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

body[data-lsp-completer-layout] .lsp-elide-wrapper {
Expand All @@ -118,16 +124,12 @@ body[data-lsp-completer-layout='detail-below'] .jp-Completer-typeExtended {
position: relative;
top: -2px;
overflow: hidden;
max-width: calc(
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
);
max-width: var(--lsp-completer-max-label-width);
}

body[data-lsp-completer-layout='detail-below'] .jp-Completer-match {
overflow: hidden;
max-width: calc(
var(--lsp-completer-max-label-width) + var(--lsp-completer-max-detail-width)
);
max-width: var(--lsp-completer-max-label-width);
}

body[data-lsp-completer-layout='detail-below']
Expand Down
12 changes: 11 additions & 1 deletion packages/jupyterlab-lsp/src/features/completion/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,18 @@ export class LSPCompletionRenderer
}

itemWidthHeuristic(item: CompletionItem): number {
const labelSize = item.label.replace(/<(\/)?mark>/g, '').length;
let labelSize = item.label.replace(/<(\/)?mark>/g, '').length;
const extraTextSize = this.getExtraInfo(item).length;
const type = item.type.toLowerCase();
if (type === 'file' || type === 'path') {
// account for elision
const parts = item.label.split(/<\/mark>/g);
const lastPart = parts[parts.length - 1];
const proposedElipsed = lastPart.length + 3;
if (proposedElipsed < labelSize) {
labelSize = proposedElipsed;
}
}
if (this.options.settings.composite.layout === 'side-by-side') {
// in 'side-by-side' take the sum
return labelSize + extraTextSize;
Expand Down