@@ -28,6 +28,9 @@ def __init__(self, proxy):
2828 self .signature_index = 0
2929 self .current_parameter = 0
3030
31+ # Used to avoid looping
32+ self .suppress_onhidden = 0
33+
3134 def queue_signature_popup (self , view ):
3235 cursor = view .rowcol (view .sel ()[0 ].begin ())
3336 point = Location (cursor [0 ] + 1 , cursor [1 ] + 1 )
@@ -64,6 +67,7 @@ def on_response(self, responseJson, view):
6467 span_end = view .text_point (
6568 arg_span ["end" ]["line" ] - 1 ,
6669 arg_span ["end" ]["offset" ] - 1 )
70+
6771 arg_region = sublime .Region (span_start , span_end )
6872 view .add_regions ('argSpan' , [arg_region ],
6973 flags = sublime .HIDDEN )
@@ -76,15 +80,37 @@ def display(self):
7680 popup_text = PopupManager .html_template .substitute (popup_parts )
7781
7882 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+
88114
89115 def move_next (self ):
90116 if not self .signature_help :
@@ -111,6 +137,13 @@ def on_navigate(self, loc):
111137 def on_hidden (self ):
112138 log .debug ('In popup on_hidden handler' )
113139 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 ))
114147 return
115148
116149 cursor_region = self .current_view .sel ()[0 ]
@@ -119,7 +152,7 @@ def on_hidden(self):
119152 argSpan = self .current_view .get_regions ('argSpan' )[0 ]
120153 if argSpan .contains (cursor_region ):
121154 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.
123156 self .display ()
124157 else :
125158 # Cleanup
@@ -200,7 +233,8 @@ def get_current_signature_parts(self):
200233 param = item ["parameters" ][self .current_parameter ]
201234 activeParam = '<span class="param">{0}:</span> <i>{1}</i>' .format (
202235 param ["name" ],
203- param ["documentation" ][0 ]["text" ] if param ["documentation" ] else "" )
236+ param ["documentation" ][0 ]["text" ]
237+ if param ["documentation" ] else "" )
204238 else :
205239 activeParam = ''
206240
0 commit comments