1
+ import sublime
2
+
1
3
from ..libs .view_helpers import *
2
4
from ..libs .text_helpers import escape_html
3
5
from .base_command import TypeScriptBaseTextCommand
@@ -40,10 +42,11 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
40
42
def handle_quick_info (self , quick_info_resp_dict , display_point ):
41
43
info_str = ""
42
44
doc_str = ""
45
+ info_text = ""
43
46
44
47
if quick_info_resp_dict ["success" ]:
45
48
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" ])
47
50
48
51
if "documentation" in quick_info_resp_dict ["body" ]:
49
52
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):
58
61
)
59
62
doc_panel .settings ().set ('color_scheme' , "Packages/Color Scheme - Default/Blackboard.tmTheme" )
60
63
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 )
63
66
64
67
else :
65
68
self .view .erase_status ("typescript_info" )
66
69
67
70
# Fetch any errors and show tooltips if available
71
+ errors = self .get_errors (sublime .Region (display_point , display_point ))
68
72
error_html = self .get_error_text_html (sublime .Region (display_point , display_point ))
69
73
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 )
71
75
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 ):
73
77
if not TOOLTIP_SUPPORT :
74
78
return
75
79
76
80
theme_styles = get_theme_styles (self .view )
77
81
78
82
parameters = {
79
- "error" : error or '' ,
80
- "info_str" : info or '' ,
83
+ "error" : error_html or '' ,
84
+ "info_str" : info_html or '' ,
81
85
"doc_str" : doc or '' ,
82
86
"typeStyles" : theme_styles ["type" ],
83
87
"keywordStyles" : theme_styles ["keyword" ],
@@ -97,25 +101,39 @@ def show_tooltip_popup(self, display_point, error, info, doc):
97
101
self .template = Template (load_quickinfo_and_error_popup_template ())
98
102
html = self .template .substitute (parameters )
99
103
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
+
100
113
settings = sublime .load_settings ("TypeScript.sublime-settings" )
101
114
self .view .show_popup (
102
- html ,
115
+ html + "<a href= \" copy \" >Copy</a>" ,
103
116
flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY ,
104
117
location = display_point ,
105
118
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 ,
107
121
)
108
122
109
- def get_error_text_html (self , span ):
123
+ def get_errors (self , span ):
110
124
client_info = cli .get_or_add_file (self .view .file_name ())
111
125
all_errors = client_info .errors ['syntacticDiag' ] + client_info .errors ['semanticDiag' ]
112
126
113
127
errors = []
114
128
for (region , text ) in all_errors :
115
129
if region .intersects (span ):
116
- errors .append (escape_html ( text ) )
130
+ errors .append (text )
117
131
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 )
119
137
120
138
def run (self , text , hover_point = None , hover_zone = None ):
121
139
check_update_view (self .view )
0 commit comments