@@ -221,7 +221,7 @@ def tooltip_popup(view, snippets):
221221 })
222222
223223
224- def tooltip (view , calltips , original_pos , lang ):
224+ def tooltip (view , calltips , text_in_current_line , original_pos , lang ):
225225 codeintel_snippets = settings_manager .get ('codeintel_snippets' , default = True , language = lang )
226226 codeintel_tooltips = settings_manager .get ('codeintel_tooltips' , default = 'popup' , language = lang )
227227
@@ -230,22 +230,40 @@ def tooltip(view, calltips, original_pos, lang):
230230 tip_info = calltip .split ('\n ' )
231231 text = ' ' .join (tip_info [1 :])
232232 snippet = None
233+ # TODO: This snippets are based and work for Python language.
234+ # Other languages might need different treatment.
233235 # Insert parameters as snippet:
234236 m = re .search (r'([^\s]+)\(([^\[\(\)]*)' , tip_info [0 ])
237+ # Figure out how many arguments are there already:
238+ text_in_current_line = text_in_current_line [:- 1 ] # Remove next char after cursor
239+ arguments = text_in_current_line .rpartition ('(' )[2 ].replace (' ' , '' ).strip () or 0
240+ if arguments :
241+ initial_separator = ''
242+ if arguments [- 1 ] == ',' :
243+ arguments = arguments [:- 1 ]
244+ else :
245+ initial_separator += ','
246+ if not text_in_current_line .endswith (' ' ):
247+ initial_separator += ' '
248+ arguments = arguments .count (',' ) + 1 if arguments else 0
235249 if m :
236250 params = [p .strip () for p in m .group (2 ).split (',' )]
237251 if params :
252+ n = 1
238253 snippet = []
239254 for i , p in enumerate (params ):
240- if p :
255+ if p and i >= arguments :
241256 var , _ , _ = p .partition ('=' )
242257 var = var .strip ()
243258 if ' ' in var :
244259 var = var .split (' ' )[1 ]
245260 if var [0 ] == '$' :
246261 var = var [1 :]
247- snippet .append ('${%s:%s}' % (i + 1 , var ))
262+ snippet .append ('${%s:%s}' % (n , var ))
263+ n += 1
248264 snippet = ', ' .join (snippet )
265+ if arguments and snippet :
266+ snippet = initial_separator + snippet
249267 text += ' - ' + tip_info [0 ] # Add function to the end
250268 else :
251269 text = tip_info [0 ] + ' ' + text # No function match, just add the first line
@@ -536,7 +554,7 @@ def _trigger(trigger, citdl_expr, calltips, cplns=None):
536554 cplns_were_empty = cplns is None
537555
538556 if calltips :
539- tooltip (view , calltips , original_pos , lang )
557+ tooltip (view , calltips , text_in_current_line , original_pos , lang )
540558
541559 content = view .substr (sublime .Region (0 , view .size ()))
542560 codeintel (view , path , content , lang , pos , forms , _trigger , caller = caller )
0 commit comments