-
Notifications
You must be signed in to change notification settings - Fork 187
Copy hover response content and diagnostics text from the hover popup #2618
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
base: main
Are you sure you want to change the base?
Changes from 25 commits
94d7b66
17f0c5e
a57a692
6e524fb
7d4ade4
c0ba0a1
75b3549
1d8a53a
03c6702
9765365
5a77bf4
51417da
0a25dab
bc2a060
ce73520
ab65e90
95d0512
18b26db
8c5a999
a6655ae
8198c66
6f52d0d
0e4ce02
baed32c
1eea3a8
1ae508b
08ae8cb
7b327aa
aa4be0f
f05e74a
d128f6d
5b6088e
3b3839c
e02f3db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -820,9 +820,9 @@ def _html_element(name: str, text: str, class_name: str | None = None, escape: b | |
|
|
||
|
|
||
| def format_diagnostic_for_html(config: ClientConfig, diagnostic: Diagnostic, base_dir: str | None = None) -> str: | ||
| html = _html_element('span', diagnostic["message"]) | ||
| code = diagnostic.get("code") | ||
| source = diagnostic.get("source") | ||
| source = diagnostic.get("source") or "" | ||
| html = _html_element('span', diagnostic["message"]) | ||
| if source or code is not None: | ||
| meta_info = "" | ||
| if source: | ||
|
|
@@ -832,14 +832,38 @@ def format_diagnostic_for_html(config: ClientConfig, diagnostic: Diagnostic, bas | |
| 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_text_html(html, copy_text=f"{source} {diagnostic['message']}") | ||
| related_infos = diagnostic.get("relatedInformation") | ||
| if related_infos: | ||
| info = "<br>".join(_format_diagnostic_related_info(config, info, base_dir) for info in related_infos) | ||
| info = "<br>".join(copy_text_html( | ||
| _format_diagnostic_related_info(config, info, base_dir), | ||
| copy_text=info['message'] | ||
| ) for info in related_infos) | ||
| html += '<br>' + _html_element("pre", info, class_name="related_info", escape=False) | ||
| severity_class = DIAGNOSTIC_SEVERITY[diagnostic_severity(diagnostic) - 1][1] | ||
| return _html_element("pre", html, class_name=severity_class, escape=False) | ||
|
|
||
|
|
||
| def copy_text_html(html_content: str, copy_text: str | MarkupContent | MarkedString | list[MarkedString]) -> str: | ||
| copy_text = _markup_to_string(copy_text) | ||
| if not len(copy_text): | ||
| return html_content | ||
| return f"""<a title="Click to Copy" | ||
| style='text-decoration: none; display: block; color: inherit' | ||
| href='{sublime.command_url('lsp_copy_text', { | ||
| 'text': copy_text | ||
| })}'>{html_content}</a>""" | ||
|
||
|
|
||
|
|
||
| def _markup_to_string(content: MarkupContent | MarkedString | list[MarkedString]) -> str: | ||
| if isinstance(content, str): | ||
| return content | ||
| if isinstance(content, dict): | ||
| return content.get('value', '') | ||
| if isinstance(content, list): | ||
| return " ".join([_markup_to_string(text) for text in content]) | ||
|
|
||
|
|
||
| def format_code_actions_for_quick_panel( | ||
| session_actions: Iterable[tuple[str, CodeAction | Command]] | ||
| ) -> tuple[list[sublime.QuickPanelItem], int]: | ||
|
|
||

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.
This naming makes it hard to understand the purpose IMO.
Perhaps
wrap_in_copy_to_clipboard_linkwith argumentslink_textandtext_to_copy?And maybe the
_markup_to_stringshould also be done separately so that this function is more specialized and less do-it-all.