22from ..libs .text_helpers import escape_html
33from .base_command import TypeScriptBaseTextCommand
44from ..libs .popup_manager import load_html_template
5+ from ..libs .popup_formatter import get_theme_styles
56from string import Template
67
78def load_quickinfo_and_error_popup_template ():
@@ -39,10 +40,14 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
3940 def handle_quick_info (self , quick_info_resp_dict , display_point ):
4041 info_str = ""
4142 doc_str = ""
43+
4244 if quick_info_resp_dict ["success" ]:
43- info_str = quick_info_resp_dict ["body" ]["displayString" ]
44- status_info_str = info_str
45- doc_str = quick_info_resp_dict ["body" ]["documentation" ]
45+ 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" ])
47+
48+ if "documentation" in quick_info_resp_dict ["body" ]:
49+ doc_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["documentation" ])
50+
4651 # process documentation
4752 if len (doc_str ) > 0 :
4853 if not TOOLTIP_SUPPORT :
@@ -64,10 +69,33 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
6469 if TOOLTIP_SUPPORT and (info_str != "" or doc_str != "" or error_html != "" ):
6570 if self .template is None :
6671 self .template = Template (load_quickinfo_and_error_popup_template ())
67- text_parts = { "error" : error_html , "info_str" : escape_html ( info_str ), "doc_str" : escape_html ( doc_str ) }
68- html = self .template . substitute ( text_parts )
72+
73+ html = self .get_popup_html ( error_html , info_str , doc_str )
6974 self .view .show_popup (html , flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY , location = display_point , max_height = 300 , max_width = 1500 )
7075
76+ def get_popup_html (self , error , info , doc ):
77+ theme_styles = get_theme_styles (self .view )
78+
79+ parameters = {
80+ "error" : error ,
81+ "info_str" : info ,
82+ "doc_str" : doc ,
83+ "typeStyles" : theme_styles ["type" ],
84+ "keywordStyles" : theme_styles ["keyword" ],
85+ "nameStyles" : theme_styles ["name" ],
86+ "paramStyles" : theme_styles ["param" ],
87+ "propertyStyles" : theme_styles ["property" ],
88+ "punctuationStyles" : theme_styles ["punctuation" ],
89+ "variableStyles" : theme_styles ["variable" ],
90+ "functionStyles" : theme_styles ["function" ],
91+ "interfaceStyles" : theme_styles ["interface" ],
92+ "stringStyles" : theme_styles ["string" ],
93+ "numberStyles" : theme_styles ["number" ],
94+ "textStyles" : theme_styles ["text" ]
95+ }
96+
97+ return self .template .substitute (parameters )
98+
7199 def get_error_text_html (self , pt ):
72100 client_info = cli .get_or_add_file (self .view .file_name ())
73101 error_text = ""
@@ -86,6 +114,28 @@ def run(self, text, hover_point=None):
86114 display_point = self .view .sel ()[0 ].begin () if hover_point is None else hover_point
87115 word_at_sel = self .view .classify (display_point )
88116 if word_at_sel & SUBLIME_WORD_MASK :
89- cli .service .quick_info (self .view .file_name (), get_location_from_position (self .view , display_point ), lambda response : self .handle_quick_info (response , display_point ))
117+ cli .service .quick_info_full (self .view .file_name (), get_location_from_position (self .view , display_point ), lambda response : self .handle_quick_info (response , display_point ))
90118 else :
91119 self .view .erase_status ("typescript_info" )
120+
121+ def map_kind_to_html_class (self , kind ):
122+ return kind
123+
124+ def format_display_parts_html (self , display_parts ):
125+ def html_escape (str ):
126+ return str .replace ('&' , '&' ).replace ('<' , '<' ).replace ('>' , ">" ).replace ('\n ' , '<br>' ).replace (' ' , ' ' )
127+
128+ result = ""
129+ template = '<span class="{0}">{1}</span>'
130+
131+ for part in display_parts :
132+ result += template .format (self .map_kind_to_html_class (part ["kind" ]), html_escape (part ["text" ]))
133+
134+ return result
135+
136+ def format_display_parts_plain (self , display_parts ):
137+ result = ""
138+ for part in display_parts :
139+ result += part ["text" ]
140+
141+ return result
0 commit comments