-
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?
Conversation
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.
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.
…RATE_WITH_AUTO_COMPLETE
and get_copy_text_from_markup to markup_to_string
Yes, it is the later. |
… the browser
when we copy the documentation, _on_navigate will be called and "url" will have the value "subl:lsp_copy_text {"text":"..."}" which is not a valid url
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The functionality is implemented and it should work fine. I have problems fixing the signature help tests. I did update 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.replace(' ', ' ')
})}'>{html_content}</a>"""to: (to remove new lines) 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.replace(' ', ' ')
})}'>{html_content}</a>"""and I have updated the regex to be: r'''
+ <a [^>]+>
<div class="highlight"><pre>
<span style="color: #\w{6}">RUN </span>
<span style="color: #\w{6}">\[</span>
<span style="color: #\w{6}"> </span>
<span style="color: #\w{6}">"command"</span>
<span style="color: #\w{6}"> </span>
<span style="color: #\w{6}; font-weight: bold; text-decoration: underline">"parameters"</span>
<span style="color: #\w{6}">, </span>
<span style="color: #\w{6}">\.\.\.</span>
<span style="color: #\w{6}"> </span>
<span style="color: #\w{6}">\]</span>
- </pre></div>
+ </pre></div></a>
'''But this does not work as I still get this error: I will try to fix the failing tests on another day. |
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
|
I probably closed the PR by accident (probably pressed the keyboard shortcut) |
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
8f76525 to
18b26db
Compare
|
I pushed 18b26db because the generated HTML looked wrong -> " ... " (a seemed to be closed before the div)... but it was my lack of concentration. The generated html was OK.
Because I wanted to support signature as well, Now, I consider this PR read for review. |
plugin/core/views.py
Outdated
| return " ".join(content) # pyright: ignore[reportCallIssue, reportUnknownVariableType, reportArgumentType] | ||
|
|
||
|
|
||
| def copy_text_html(html_content: str, copy_text: str | MarkupContent | MarkedString | list[MarkedString]) -> str: |
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_link with arguments link_text and text_to_copy?
And maybe the _markup_to_string should also be done separately so that this function is more specialized and less do-it-all.
Co-authored-by: Rafał Chłodnicki <[email protected]>
…content on why I've added it... For now I will remove it, if there is a need it can easily be brought back
plugin/core/views.py
Outdated
| 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>""" |
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.
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.
Seems to be a
When I hover:
const foo = "bar"the html content with this branch is:
mdpopups: =====HTML OUTPUT=====
mdpopups:
<body><a title="Click to Copy"
style='text-decoration: none; display: block; color: inherit'
href='subl:lsp_copy_text {"text":"\n```typescript\nconst foo: \"bar\"\n```\n"}'><div class="highlight"><pre><span style="color: #fcb6b6;">const</span><span style="color: #ffffff;"> </span><span style="color: #ffffff;">foo</span><span style="color: #ffffff;">:</span><span style="color: #ffffff;"> </span><span style="color: #fcd49e;">"</span><span style="color: #fcd49e;">bar</span><span style="color: #fcd49e;">"</span><br></pre></div></a><div class="lsp_popup--spacer"></div></body>
while the html with the main branch still contains a br
mdpopups: =====HTML OUTPUT=====
mdpopups:
<body><div class="highlight"><pre><span style="color: #fcb6b6;">const</span><span style="color: #ffffff;"> </span><span style="color: #ffffff;">foo</span><span style="color: #ffffff;">:</span><span style="color: #ffffff;"> </span><span style="color: #fcd49e;">"</span><span style="color: #fcd49e;">bar</span><span style="color: #fcd49e;">"</span><br></pre></div><div class="lsp_popup--spacer"></div></body>
but there is margin bottom on main.
I will see what is going on.
4b798e8 to
1ae508b
Compare
|
In my opinion the copying should be restricted to diagnostics messages and to the content of (fenced) code blocks. |
…from other hovers popups
Yes, I like it. Would it be possible to make the copy button aligned to the right side of the popup? Alternatively we could use icons instead of the "copy" button. For example: It is possible to include the images in minihtml via Line 98 in aec423a
The icons would probably also need a dark variant for light color schemes. But the "copy" button looks good too. I'm just throwing in some ideas. I think if we want a copy button for the fenced code blocks too in the future, we would need to parse the html from mdpopups after the conversion from Markdown and then inject additional html for the buttons. I think it's not impossible, but probably not very easy and there could be various edge cases. Also the minihtml is quite limited, so I don't know where the best placement for the copy buttons would be in that case. A better way might be if this could be handled directly by mdpopups. But probably this is out of scope for mdpopups, and an implementation there might also be complicated.
|





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:
closes #2600