@@ -39,10 +39,12 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
39
39
def handle_quick_info (self , quick_info_resp_dict , display_point ):
40
40
info_str = ""
41
41
doc_str = ""
42
+
42
43
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" ]
44
+ info_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["displayParts" ])
45
+ status_info_str = self .format_display_parts_plain (quick_info_resp_dict ["body" ]["displayParts" ])
46
+ doc_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["documentation" ])
47
+
46
48
# process documentation
47
49
if len (doc_str ) > 0 :
48
50
if not TOOLTIP_SUPPORT :
@@ -51,7 +53,7 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
51
53
'typescript_show_doc' ,
52
54
{'infoStr' : info_str , 'docStr' : doc_str }
53
55
)
54
- doc_panel .settings ().set ('color_scheme' , "Packages/Color Scheme - Default/Blackboard.tmTheme" )
56
+ # doc_panel.settings().set('color_scheme', "Packages/Color Scheme - Default/Blackboard.tmTheme")
55
57
sublime .active_window ().run_command ('show_panel' , {'panel' : 'output.doc' })
56
58
status_info_str = info_str + " (^T^Q for more)"
57
59
self .view .set_status ("typescript_info" , status_info_str )
@@ -64,10 +66,36 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
64
66
if TOOLTIP_SUPPORT and (info_str != "" or doc_str != "" or error_html != "" ):
65
67
if self .template is None :
66
68
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 )
69
+
70
+ html = self .get_popup_html (error_html , info_str , doc_str )
71
+
72
+ print (html )
73
+
69
74
self .view .show_popup (html , flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY , location = display_point , max_height = 300 , max_width = 1500 )
70
75
76
+ def get_popup_html (self , error , info , doc ):
77
+ theme_styles = self .get_theme_styles ()
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
+
71
99
def get_error_text_html (self , pt ):
72
100
client_info = cli .get_or_add_file (self .view .file_name ())
73
101
error_text = ""
@@ -86,6 +114,60 @@ def run(self, text, hover_point=None):
86
114
display_point = self .view .sel ()[0 ].begin () if hover_point is None else hover_point
87
115
word_at_sel = self .view .classify (display_point )
88
116
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 ))
90
118
else :
91
119
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
142
+
143
+ def format_css (self , style ):
144
+ result = ""
145
+
146
+ if (style ["foreground" ]):
147
+ result += "color: {0};" .format (style ["foreground" ])
148
+
149
+ if (style ["bold" ]):
150
+ result += "font-weight: bold;"
151
+
152
+ if (style ["italic" ]):
153
+ result += "font-style: italic;"
154
+
155
+ return result
156
+
157
+ def get_theme_styles (self ):
158
+ print (self .view .style_for_scope ("keyword.control.flow.ts" ))
159
+
160
+ return {
161
+ "type" : self .format_css (self .view .style_for_scope ("entity.name.type.class.ts" )),
162
+ "keyword" : self .format_css (self .view .style_for_scope ("keyword.control.flow.ts" )),
163
+ "name" : self .format_css (self .view .style_for_scope ("entity.name.function" )),
164
+ "param" : self .format_css (self .view .style_for_scope ("variable.language.arguments.ts" )),
165
+ "property" : self .format_css (self .view .style_for_scope ("variable.other.property.ts" )),
166
+ "punctuation" : self .format_css (self .view .style_for_scope ("punctuation.definition.block.ts" )),
167
+ "variable" : self .format_css (self .view .style_for_scope ("meta.var.expr.ts" )),
168
+ "function" : self .format_css (self .view .style_for_scope ("entity.name.function.ts" )),
169
+ "interface" : self .format_css (self .view .style_for_scope ("entity.name.type.interface.ts" )),
170
+ "string" : self .format_css (self .view .style_for_scope ("string.quoted.single.ts" )),
171
+ "number" : self .format_css (self .view .style_for_scope ("constant.numeric.decimal.ts" )),
172
+ "text" : self .format_css (self .view .style_for_scope ("source.ts" ))
173
+ }
0 commit comments