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

Feature: Truncate inlay hint label #2514

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

bivashy
Copy link

@bivashy bivashy commented Sep 15, 2024

Description

This pull request allows inlay hints to be truncated, which could be useful if inlay hints are too large. For example: TypeScript has absurdly long inlay hints (see screenshot 1).
The default truncate limit is 1000.
Truncated content reveal is not implemented, which means you cannot see the full content of the inlay hint if it is truncated.

Tested with:
LSP-typescript
LSP-gopls
LSP-rust-analyzer


1. Long inlay hint

long-inlay-hint

2. `LSP-typescript` (limit 30)

lsp-typescript-inlay-hint

3. `LSP-gopls` (limit 30)

lsp-gopls

4. `LSP-rust-analyzer` (limit 30)

lsp-rust-analyzer

plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
LSP.sublime-settings Outdated Show resolved Hide resolved
@jwortmann
Copy link
Member

jwortmann commented Sep 17, 2024

Could you use instead of ...? I think that would look nicer.

I wonder whether this really needs a setting, maybe long labels could instead always be truncated if we pick a reasonable cutoff length? And if the label gets truncated, it could be added to the tooltip, so you can easily see the full inlay hint on mouse hover. So in that case the html.escape of the full label and probably also a \n (or <br>?) should be prepended to the title attribute at

result += f'<span title="{(tooltip + instruction_text).strip()}">{html.escape(label)}</span>'

and
result += f"<span title=\"{(tooltip + instruction_text).strip()}\">{value}</span>"

Could be useful to try whether that works and how it would look like.

@bivashy
Copy link
Author

bivashy commented Sep 19, 2024

Could you use instead of ...? I think that would look nicer.

Maybe we should make this configurable from the preferences? Or is this redundant?


And if the label gets truncated, it could be added to the tooltip, so you can easily see the full inlay hint on mouse hover. So in that case the html.escape of the full label and probably also a \n (or &lt;br&gt;?) should be prepended to the title attribute at

result += f'<span title="{(tooltip + instruction_text).strip()}">{html.escape(label)}</span>'

and

result += f"<span title=\"{(tooltip + instruction_text).strip()}\">{value}</span>"

Could be useful to try whether that works and how it would look like.

I'll try to implement that.

I am not sure how we would choose a reasonable length, because it might vary by language and user preference, someone might be fine with big inlay hints, but other people would want to have very short inlay hints.

@rchl
Copy link
Member

rchl commented Sep 19, 2024

Could you use instead of ...? I think that would look nicer.

Maybe we should make this configurable from the preferences? Or is this redundant?

We strive to limit the number of exposed options so no. But also is the correct one to use semantically. Three separate dots don't mean much semantically. And also it's slightly shorter.

@bivashy
Copy link
Author

bivashy commented Sep 19, 2024

I've used suggested characters instead of plain ..., I think it looks nice.

more-compact-dots


truncation-tooltip

plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
Copy link

netlify bot commented Sep 22, 2024

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit 1ba72a6
🔍 Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/66f045ef1176bd0008be3e70
😎 Deploy Preview https://deploy-preview-2514--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Sep 22, 2024

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit 1c313b5
🔍 Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/66f04600868a650008791ad6
😎 Deploy Preview https://deploy-preview-2514--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Sep 22, 2024

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit 25be2dd
🔍 Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/66f0464747dac400084a3b23
😎 Deploy Preview https://deploy-preview-2514--sublime-lsp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
@bivashy
Copy link
Author

bivashy commented Sep 26, 2024

Note: We need to hover three dots to see the tooltip, hovering text will not work. Should I be concerned about this? Should I wrap result in span with title if input is truncated, but that might break other tooltips.

@rchl
Copy link
Member

rchl commented Sep 26, 2024

Note: We need to hover three dots to see the tooltip, hovering text will not work. Should I be concerned about this? Should I wrap result in span with title if input is truncated, but that might break other tooltips.

It doesn't sound like a common behavior that people would be familiar with so it would make the title hard to discover.

I haven't tried the changes yet, does this feel like an ST bug to you?

@bivashy
Copy link
Author

bivashy commented Sep 26, 2024

Note: We need to hover three dots to see the tooltip, hovering text will not work. Should I be concerned about this? Should I wrap result in span with title if input is truncated, but that might break other tooltips.

It doesn't sound like a common behavior that people would be familiar with so it would make the title hard to discover.

I haven't tried the changes yet, does this feel like an ST bug to you?

Nope, I don't know how to implement that properly.
I mean, if I wrap result in span, will it break something?
I can send commit with such implementation so you can take a look at it.

Like that:

if truncated:
  result = f"<span title={tooltip + truncation_label}>{result}</span>"

@rchl
Copy link
Member

rchl commented Sep 26, 2024

I would have to look exactly what content is possible in this case but I would think that the inlay hints are plain text (they are in the spec) so adding an inline wrapper shouldn't change anything. It would only be an issue if it would be possible for there to be a child block element but I don't think it is in this case.

@bivashy
Copy link
Author

bivashy commented Sep 27, 2024

I would have to look exactly what content is possible in this case but I would think that the inlay hints are plain text (they are in the spec) so adding an inline wrapper shouldn't change anything. It would only be an issue if it would be possible for there to be a child block element but I don't think it is in this case.

Tested, span inside of span works as expected:

<span title="test">Some text is <span title="this is subspan?">subunder</span></span>

Results:
hover-out-span
hover-inner-span

@bivashy
Copy link
Author

bivashy commented Sep 28, 2024

Note: We need to hover three dots to see the tooltip, hovering text will not work. Should I be concerned about this? Should I wrap result in span with title if input is truncated, but that might break other tooltips.

Now it works as expected, and doesn't conflict with other tooltips

LSP.sublime-settings Outdated Show resolved Hide resolved
LSP.sublime-settings Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
Comment on lines +151 to +156
result += f'<span title="{result_tooltip}">{html.escape(truncated_label)}</span>'
if is_clickable:
result += "</a>"
if truncated:
truncation_tooltip = html.escape(label)
result = f"<span title=\"{truncation_tooltip}\">{result}</span>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it but this looks like it would result in something like

<span title="Truncation tooltip"><span title="Regular tooltip">Label</span></span>

I don't think this would work, i.e. it would only show Truncation tooltip on hover, instead of both of them, or does it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but it works as expected. See comment: #2514 (comment)

Copy link
Member

@jwortmann jwortmann Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's first clarify what is expected. In your example "test" would be the full label of the InlayHint, and "this is subspan?" would be the (optional) tooltip. I would expect that the tooltip is always visible when hovering (if it exists), and the full label is additionally visible if it is truncated. Your screenshot suggests that tooltip would be hidden if the label gets truncated.

What was wrong with only having a single title attribute and appending/prepending the truncation_tooltip content plus linebreak? Is it because ST doesn't support linebreaks in tooltips?

(Besides that, it seems the tooltip can be MarkupContent, so I'm not sure whether the assumption from #2514 (comment) is correct. But in this case we're probably processing it not quite correctly anyways, which is a different issue.)

Copy link
Author

@bivashy bivashy Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed your point earlier. Now I understand. The label for truncated content won't be shown if a label_part has a tooltip, but it will be displayed in areas where the tooltip is missing. I didn't see it as an issue, but I get your concern now.

For appending/prepending the tooltip, I'm not sure yet. One idea is to append the tooltip on a new line with the full label. Does that sound good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was my initial idea. I'm not aware of any server which uses the optional tooltip, so perhaps we cannot test it directly. But it looks like you already had implemented it in this way before 0fcdf79. Didn't it work correctly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it but this looks like it would result in something like

<span title="Truncation tooltip"><span title="Regular tooltip">Label</span></span>

I don't think this would work, i.e. it would only show Truncation tooltip on hover, instead of both of them, or does it?

As far as I remember, this will show the "Regular tooltip" when hovering Label.

Whatever we do, it won't be very apparent to the user where each tooltip starts and ends unless we maybe add some additional styling.

@jwortmann
Copy link
Member

I think a better default length would be something like 30 or 40, and I would probably name the setting "inlay_hints_truncate_length" or "inlay_hints_max_length" (just a suggestion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants