Skip to content

Copy diagnostic hover text#2618

Merged
predragnikolic merged 55 commits into
mainfrom
feature/copy_hover_content
Nov 20, 2025
Merged

Copy diagnostic hover text#2618
predragnikolic merged 55 commits into
mainfrom
feature/copy_hover_content

Conversation

@predragnikolic

@predragnikolic predragnikolic commented Aug 16, 2025

Copy link
Copy Markdown
Member

This is a POC that could address #2600

Sublime.Text.mp4

This enables coping hover responses from server,
and diagnostics text, at the moment.

TODO:

  • Error diagnostics look broken, need to fix that.()
Screenshot 2025-08-16 at 11 14 27 -[] Add logic to copy signature help as well.

closes #2600

@rchl rchl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about a case when the popup also shows other info like symbol documentation? Is the whole contents of the popup copied or each section is copied separately. If the latter then it would probably be hard to convey what is going to get copied.

Comment thread plugin/hover.py Outdated
@predragnikolic

This comment was marked as outdated.

Comment thread plugin/hover.py Outdated
Comment thread plugin/completion.py Outdated
@netlify

netlify Bot commented Sep 3, 2025

Copy link
Copy Markdown

Deploy Preview for sublime-lsp ready!

Name Link
🔨 Latest commit ab65e90
🔍 Latest deploy log https://app.netlify.com/projects/sublime-lsp/deploys/68b87f1df926670008c069f2
😎 Deploy Preview https://deploy-preview-2618--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 project configuration.

@predragnikolic

This comment was marked as outdated.

copy_text_html returns a block element,
before this commit, with the previous code, I moved the diagnostics source to be bellow the diagnostic message
now the diagnostic message and source will be on the same line and look as before
@predragnikolic

This comment was marked as outdated.

Seems like this code cause <a><div>...</a></div> to be rendered
and I suspect that the change to _render_label was the cause of it. F
For now I will revert it
@predragnikolic predragnikolic force-pushed the feature/copy_hover_content branch from 8f76525 to 18b26db Compare September 10, 2025 19:16
@predragnikolic predragnikolic marked this pull request as ready for review September 12, 2025 21:43
@predragnikolic

Copy link
Copy Markdown
Member Author

Latest update after c0957cb

Screenshot 2025-11-13 at 19 18 55 Screenshot 2025-11-13 at 19 18 42

@predragnikolic

Copy link
Copy Markdown
Member Author

FWIW, I do find the pngs approach nicer looking #2618 (comment)
then the utf-char #2618 (comment)

Comment thread popups.css Outdated
@predragnikolic

Copy link
Copy Markdown
Member Author

We are getting close with this, we just need to decide
png or utf-8

@predragnikolic

predragnikolic commented Nov 13, 2025

Copy link
Copy Markdown
Member Author

I do find the png approach nicer looking (because the icon is a bit bigger, a nicer looking, but it cannot be customized with css, and it does require more code)

Based on the above messages, Rafal and Janos are leaning towards utf-8.
1 person is for png, 2 are for utf, so I guess the utf-8 char approach wins. But please confirm.

(also no rush in the decision)

Comment thread plugin/core/views.py Outdated
@rchl

rchl commented Nov 13, 2025

Copy link
Copy Markdown
Member

I do find the png approach nicer looking (because the icon is a bit bigger, a nicer looking, but it cannot be customized with css, and it does require more code)

Based on the above messages, Rafal and Janos are leaning towards utf-8. 1 person is for png, 2 are for utf, so I guess the utf-8 char approach wins. But please confirm.

(also no rush in the decision)

I agree that utf-8 character looks a bit worse due to the fact that at least on Mac it looks a bit blurry at default 1rem. It looks good at 1.2rem but then it makes line height taller... I don't see a way to fix that with limited minihtml capabilities.
Then font rendering is also very OS/font specific so it might look better (or worse ;)) for others.

I would still take utf-8 version for its simplicity and versatility.

@jwortmann

Copy link
Copy Markdown
Member

If I click the copy icon in the popup when hovering the gutter icon, a webbrowser (which is not even my default browser) opens...

@predragnikolic

Copy link
Copy Markdown
Member Author

Nice catch. Found the reason ->

LSP/plugin/documents.py

    def _on_navigate(self, href: str, point: int) -> None:
        if href.startswith('code-actions:'):
            ...
            else:
                self.handle_code_action_select(config_name, actions, 0)
        else:
            open_in_browser(href)

@jwortmann

Copy link
Copy Markdown
Member

The icon is a bit blurry on Windows too (I assume Segoe UI Symbol font), but I'd say it looks okay.

U+29C9

I tried some alternatives:

U+2BBA (less blurry, but slightly smaller):

U+2BBA

U+2BBB (hm... too bright):

U+2BBB

@predragnikolic

predragnikolic commented Nov 13, 2025

Copy link
Copy Markdown
Member Author

I did try one other approach. but no success.
But for documentation purposes here it is:

To avoid the blur I did try to create the icon with css,
with a combination of borders/ padding/inline-boxes/border radius...

But minihtml doesn't behave as html and css, so I either break height of the outer box, or I break the look of the boxes itself.

Screenshot 2025-11-13 at 21 20 09 Screenshot 2025-11-13 at 21 19 54

Comment thread plugin/core/views.py Outdated
meta_info += "({})".format(
make_link(code_description["href"], str(code)) if code_description else text2html(str(code)))
html += " " + _html_element("span", meta_info, class_name="color-muted", escape=False)
html += copy_icon_html(f"{diagnostic['message']} {f'({source})' if source else ''}".strip())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function could be inlined, since it consists of only a single expression and is not used elsewhere:

copy_text = f"{diagnostic['message']} {f'({source})' if source else ''}".strip()
html += f"""<a class='copy-icon' title='Copy to clipboard' href='{sublime.command_url(
        'lsp_copy_text', {'text': copy_text}
    )}'>⧉</a>"""

@jwortmann jwortmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One thing I noticed is that the copied text can contain for example non-breaking space characters. But this happens because the server (in this case Pyright) already contains these characters as \n\xa0\xa0 in the JSON payload, assumingly to enforce indentation after a linebreak, which would otherwise not get through the HTML rendering in the popup. Perhaps we should filter out/replace such characters? On the other hand that would feel a bit arbitrary and ultimatively it's the responsibility of the server what it puts into the diagnostic message.

@predragnikolic

Copy link
Copy Markdown
Member Author

Perhaps we should filter out/replace such characters?

I had code for this, but I reverted it because later I could not find the exact example on why I added the code in the first place baed32c

I am in favor of replacing such chars, I think it benefits the user.

@predragnikolic

Copy link
Copy Markdown
Member Author

Hello, if there are no further comments, I will merge this PR tonight.

@predragnikolic predragnikolic merged commit 439422c into main Nov 20, 2025
8 checks passed
@predragnikolic predragnikolic deleted the feature/copy_hover_content branch November 20, 2025 16:03
@predragnikolic predragnikolic changed the title Copy hover response content and diagnostics text from the hover popup Copy diagnostic hover text Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable text selection and copying in LSP pop-up

3 participants