@@ -28,6 +28,9 @@ def __init__(self, proxy):
28
28
self .signature_index = 0
29
29
self .current_parameter = 0
30
30
31
+ # Used to avoid looping
32
+ self .suppress_onhidden = 0
33
+
31
34
def queue_signature_popup (self , view ):
32
35
cursor = view .rowcol (view .sel ()[0 ].begin ())
33
36
point = Location (cursor [0 ] + 1 , cursor [1 ] + 1 )
@@ -64,6 +67,7 @@ def on_response(self, responseJson, view):
64
67
span_end = view .text_point (
65
68
arg_span ["end" ]["line" ] - 1 ,
66
69
arg_span ["end" ]["offset" ] - 1 )
70
+
67
71
arg_region = sublime .Region (span_start , span_end )
68
72
view .add_regions ('argSpan' , [arg_region ],
69
73
flags = sublime .HIDDEN )
@@ -76,15 +80,37 @@ def display(self):
76
80
popup_text = PopupManager .html_template .substitute (popup_parts )
77
81
78
82
log .debug ('Displaying signature popup' )
79
- if not self .current_view .is_popup_visible ():
80
- self .current_view .show_popup (
81
- popup_text ,
82
- sublime .COOPERATE_WITH_AUTO_COMPLETE ,
83
- on_navigate = self .on_navigate ,
84
- on_hide = self .on_hidden ,
85
- max_width = 800 )
86
- else :
87
- self .current_view .update_popup (popup_text )
83
+
84
+ arg_region = self .current_view .get_regions ('argSpan' )[0 ]
85
+ location = arg_region .begin () # Default to start of arg list
86
+
87
+ # If the cursor is not in the first line of the arg list, set the popup
88
+ # location to first non-whitespace, or EOL, of the current line
89
+ cursor_point = self .current_view .sel ()[0 ].begin ()
90
+ opening_line = self .current_view .line (arg_region .begin ())
91
+ if (not opening_line .contains (cursor_point )):
92
+ cursor_line_start = self .current_view .line (cursor_point ).begin ()
93
+ location = self .current_view .find (
94
+ r'\s*?(?=[\S\n\r]|$)' ,
95
+ cursor_line_start
96
+ ).end ()
97
+
98
+ # Need to hide/redisplay in case location moved, but this triggers an
99
+ # on_hidden loop if we don't ignore the event (which occurs later)
100
+ # from the hide message
101
+ if self .current_view .is_popup_visible ():
102
+ self .suppress_onhidden += 1
103
+ log .debug ('+suppress_onhidden: {0}' .format (self .suppress_onhidden ))
104
+ self .current_view .hide_popup ()
105
+
106
+ self .current_view .show_popup (
107
+ popup_text ,
108
+ sublime .COOPERATE_WITH_AUTO_COMPLETE ,
109
+ on_navigate = self .on_navigate ,
110
+ on_hide = self .on_hidden ,
111
+ location = location ,
112
+ max_width = 800 )
113
+
88
114
89
115
def move_next (self ):
90
116
if not self .signature_help :
@@ -111,6 +137,13 @@ def on_navigate(self, loc):
111
137
def on_hidden (self ):
112
138
log .debug ('In popup on_hidden handler' )
113
139
if not self .current_view :
140
+ log .debug ('No current view for popup session. Hiding popup' )
141
+ return
142
+
143
+ # Did we hide the popup ourselves in order to redisplay it?
144
+ if self .suppress_onhidden > 0 :
145
+ self .suppress_onhidden -= 1
146
+ log .debug ('-suppress_onhidden: {0}' .format (self .suppress_onhidden ))
114
147
return
115
148
116
149
cursor_region = self .current_view .sel ()[0 ]
@@ -119,7 +152,7 @@ def on_hidden(self):
119
152
argSpan = self .current_view .get_regions ('argSpan' )[0 ]
120
153
if argSpan .contains (cursor_region ):
121
154
log .debug ('Was hidden while in region. Redisplaying' )
122
- # Occurs on left/right movement. Rerun to redisplay popup.
155
+ # Occurs on cursor movement. Rerun to redisplay popup.
123
156
self .display ()
124
157
else :
125
158
# Cleanup
@@ -200,7 +233,8 @@ def get_current_signature_parts(self):
200
233
param = item ["parameters" ][self .current_parameter ]
201
234
activeParam = '<span class="param">{0}:</span> <i>{1}</i>' .format (
202
235
param ["name" ],
203
- param ["documentation" ][0 ]["text" ] if param ["documentation" ] else "" )
236
+ param ["documentation" ][0 ]["text" ]
237
+ if param ["documentation" ] else "" )
204
238
else :
205
239
activeParam = ''
206
240
0 commit comments