LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Feature: Truncate inlay hint label

Open bivashy opened this issue 1 year ago • 14 comments

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

bivashy avatar Sep 15 '24 19:09 bivashy

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 https://github.com/sublimelsp/LSP/blob/f4223d6d13eb941370c0ac40b47a185befa3a852/plugin/inlay_hint.py#L145 and https://github.com/sublimelsp/LSP/blob/f4223d6d13eb941370c0ac40b47a185befa3a852/plugin/inlay_hint.py#L170

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

jwortmann avatar Sep 17 '24 16:09 jwortmann

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 <br>?) should be prepended to the title attribute at

https://github.com/sublimelsp/LSP/blob/f4223d6d13eb941370c0ac40b47a185befa3a852/plugin/inlay_hint.py#L145

and

https://github.com/sublimelsp/LSP/blob/f4223d6d13eb941370c0ac40b47a185befa3a852/plugin/inlay_hint.py#L170

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.

bivashy avatar Sep 19 '24 15:09 bivashy

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.

rchl avatar Sep 19 '24 15:09 rchl

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

more-compact-dots


truncation-tooltip

bivashy avatar Sep 19 '24 19:09 bivashy

Deploy Preview for sublime-lsp ready!

Name Link
Latest commit 1ba72a66d41777c5b0f4ad237b149efba63b16ad
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.

netlify[bot] avatar Sep 22 '24 16:09 netlify[bot]

Deploy Preview for sublime-lsp ready!

Name Link
Latest commit 1c313b55eb4f3b13eb7f1922df409c6163a0c3ae
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.

netlify[bot] avatar Sep 22 '24 16:09 netlify[bot]

Deploy Preview for sublime-lsp ready!

Name Link
Latest commit 8e86dc31b33a5d734130a1c922b7f28888e54d6a
Latest deploy log https://app.netlify.com/sites/sublime-lsp/deploys/6730d04c54b4ae0008299b68
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.

netlify[bot] avatar Sep 22 '24 16:09 netlify[bot]

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.

bivashy avatar Sep 26 '24 06:09 bivashy

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?

rchl avatar Sep 26 '24 06:09 rchl

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>"

bivashy avatar Sep 26 '24 06:09 bivashy

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.

rchl avatar Sep 26 '24 07:09 rchl

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 avatar Sep 27 '24 14:09 bivashy

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

bivashy avatar Sep 28 '24 15:09 bivashy

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).

jwortmann avatar Oct 03 '24 12:10 jwortmann