-
Notifications
You must be signed in to change notification settings - Fork 182
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
base: main
Are you sure you want to change the base?
Conversation
Could you use 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 Line 145 in f4223d6
and Line 170 in f4223d6
Could be useful to try whether that works and how it would look like. |
Maybe we should make this configurable from the preferences? Or is this redundant?
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. |
We strive to limit the number of exposed options so no. But also |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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 |
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. Like that: if truncated:
result = f"<span title={tooltip + truncation_label}>{result}</span>" |
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 title="test">Some text is <span title="this is subspan?">subunder</span></span> |
Now it works as expected, and doesn't conflict with other tooltips |
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>" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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). |
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
2. `LSP-typescript` (limit 30)
3. `LSP-gopls` (limit 30)
4. `LSP-rust-analyzer` (limit 30)