1+ import sublime
2+
13from ..libs .view_helpers import *
24from ..libs .text_helpers import escape_html
35from .base_command import TypeScriptBaseTextCommand
@@ -40,10 +42,11 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
4042 def handle_quick_info (self , quick_info_resp_dict , display_point ):
4143 info_str = ""
4244 doc_str = ""
45+ info_text = ""
4346
4447 if quick_info_resp_dict ["success" ]:
4548 info_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["displayParts" ])
46- status_info_str = self .format_display_parts_plain (quick_info_resp_dict ["body" ]["displayParts" ])
49+ info_text = self .format_display_parts_plain (quick_info_resp_dict ["body" ]["displayParts" ])
4750
4851 if "documentation" in quick_info_resp_dict ["body" ]:
4952 doc_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["documentation" ])
@@ -58,26 +61,27 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
5861 )
5962 doc_panel .settings ().set ('color_scheme' , "Packages/Color Scheme - Default/Blackboard.tmTheme" )
6063 sublime .active_window ().run_command ('show_panel' , {'panel' : 'output.doc' })
61- status_info_str = info_str + " (^T^Q for more)"
62- self .view .set_status ("typescript_info" , status_info_str )
64+ info_text = info_str + " (^T^Q for more)"
65+ self .view .set_status ("typescript_info" , info_text )
6366
6467 else :
6568 self .view .erase_status ("typescript_info" )
6669
6770 # Fetch any errors and show tooltips if available
71+ errors = self .get_errors (sublime .Region (display_point , display_point ))
6872 error_html = self .get_error_text_html (sublime .Region (display_point , display_point ))
6973 if info_str != "" or doc_str != "" or error_html != "" :
70- self .show_tooltip_popup (display_point , error_html , info_str , doc_str )
74+ self .show_tooltip_popup (display_point , errors , error_html , info_text , info_str , doc_str )
7175
72- def show_tooltip_popup (self , display_point , error , info , doc ):
76+ def show_tooltip_popup (self , display_point , errors , error_html : str , info_text : str , info_html : str , doc ):
7377 if not TOOLTIP_SUPPORT :
7478 return
7579
7680 theme_styles = get_theme_styles (self .view )
7781
7882 parameters = {
79- "error" : error or '' ,
80- "info_str" : info or '' ,
83+ "error" : error_html or '' ,
84+ "info_str" : info_html or '' ,
8185 "doc_str" : doc or '' ,
8286 "typeStyles" : theme_styles ["type" ],
8387 "keywordStyles" : theme_styles ["keyword" ],
@@ -97,25 +101,39 @@ def show_tooltip_popup(self, display_point, error, info, doc):
97101 self .template = Template (load_quickinfo_and_error_popup_template ())
98102 html = self .template .substitute (parameters )
99103
104+ def on_navigate (href : str ) -> None :
105+ if href == "copy" :
106+ copy_text = "\n \n " .join (s for s in errors if s )
107+ if info_text :
108+ copy_text = copy_text + "\n \n " + info_text
109+ sublime .set_clipboard (copy_text )
110+ sublime .active_window ().status_message ("TypeScript: info copied to clipboard" )
111+ self .view .hide_popup ()
112+
100113 settings = sublime .load_settings ("TypeScript.sublime-settings" )
101114 self .view .show_popup (
102- html ,
115+ html + "<a href= \" copy \" >Copy</a>" ,
103116 flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY ,
104117 location = display_point ,
105118 max_height = 300 ,
106- max_width = settings .get ("quick_info_popup_max_width" ) or self .view .viewport_extent ()[0 ]
119+ max_width = settings .get ("quick_info_popup_max_width" ) or self .view .viewport_extent ()[0 ],
120+ on_navigate = on_navigate ,
107121 )
108122
109- def get_error_text_html (self , span ):
123+ def get_errors (self , span ):
110124 client_info = cli .get_or_add_file (self .view .file_name ())
111125 all_errors = client_info .errors ['syntacticDiag' ] + client_info .errors ['semanticDiag' ]
112126
113127 errors = []
114128 for (region , text ) in all_errors :
115129 if region .intersects (span ):
116- errors .append (escape_html ( text ) )
130+ errors .append (text )
117131
118- return '<br/>' .join (errors )
132+ return errors
133+
134+ def get_error_text_html (self , span ):
135+ errors = self .get_errors (span )
136+ return '<br/>' .join (escape_html (error ) for error in errors )
119137
120138 def run (self , text , hover_point = None , hover_zone = None ):
121139 check_update_view (self .view )
0 commit comments