Skip to content

Commit d0027a3

Browse files
committed
All type and error info messages can be copied from popup
1 parent 0b82fc2 commit d0027a3

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

typescript/commands/quick_info.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sublime
2+
13
from ..libs.view_helpers import *
24
from ..libs.text_helpers import escape_html
35
from .base_command import TypeScriptBaseTextCommand
@@ -40,6 +42,7 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
4042
def handle_quick_info(self, quick_info_resp_dict, display_point):
4143
info_str = ""
4244
doc_str = ""
45+
status_info_str = ""
4346

4447
if quick_info_resp_dict["success"]:
4548
info_str = self.format_display_parts_html(quick_info_resp_dict["body"]["displayParts"])
@@ -65,14 +68,28 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
6568
self.view.erase_status("typescript_info")
6669

6770
# process tooltips
68-
error_html = self.get_error_text_html(display_point)
71+
error_str = self.get_error_text_html(display_point)
72+
error_html = escape_html(error_str)
6973
if TOOLTIP_SUPPORT and (info_str != "" or doc_str != "" or error_html != ""):
7074
if self.template is None:
7175
self.template = Template(load_quickinfo_and_error_popup_template())
7276
html = self.get_popup_html(error_html, info_str, doc_str)
7377

78+
def on_navigate(href: str) -> None:
79+
if href == "copy":
80+
sublime.set_clipboard("\n\n".join(s for s in [error_str, status_info_str] if s))
81+
sublime.active_window().status_message("TypeScript: info copied to clipboard")
82+
self.view.hide_popup()
83+
7484
settings = sublime.load_settings("TypeScript.sublime-settings")
75-
self.view.show_popup(html, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=display_point, max_height=300, max_width=settings.get("quick_info_popup_max_width") or self.view.viewport_extent()[0])
85+
self.view.show_popup(
86+
html + "<a href=\"copy\">Copy</a>",
87+
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
88+
location=display_point,
89+
max_height=300,
90+
max_width=settings.get("quick_info_popup_max_width") or self.view.viewport_extent()[0],
91+
on_navigate=on_navigate,
92+
)
7693

7794
def get_popup_html(self, error, info, doc):
7895
theme_styles = get_theme_styles(self.view)
@@ -108,7 +125,7 @@ def get_error_text_html(self, pt):
108125
if region.contains(pt):
109126
error_text = text
110127
break
111-
return escape_html(error_text)
128+
return error_text
112129

113130
def run(self, text, hover_point=None):
114131
check_update_view(self.view)

typescript/libs/popup_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get_signature_data(on_done):
6565
if last_command == "insert":
6666
if len(args['characters']) > 1 and '\n' in args['characters']:
6767
reload_buffer(view)
68-
68+
6969
# Send a signagure_help request to server
7070
self.proxy.async_signature_help(filename, point, '', on_done)
7171

@@ -240,7 +240,7 @@ def concat_display_parts(parts, underline_name=False):
240240
def get_current_signature_parts(self):
241241
def encode(str, kind):
242242
return '<br />' if kind == "lineBreak" else str
243-
243+
244244
if self.signature_index == -1:
245245
return ""
246246
if self.signature_index >= len(self.signature_help["items"]):
@@ -259,7 +259,7 @@ def encode(str, kind):
259259
param = item["parameters"][self.current_parameter]
260260
activeParam = '<span class="param">{0}:</span> <i>{1}</i>'.format(
261261
param["name"],
262-
''.join([encode(doc["text"], doc["kind"]) for doc in param["documentation"]])
262+
''.join([encode(doc["text"], doc["kind"]) for doc in param["documentation"]])
263263
if param["documentation"] else "")
264264
else:
265265
activeParam = ''

0 commit comments

Comments
 (0)