@@ -157,56 +157,66 @@ def get_script(source=None, column=None):
157157@catch_and_print_exceptions
158158def completions ():
159159 row , column = vim .current .window .cursor
160- # Clear call signatures in the buffer so they aren't seen by the completer.
161- # Call signatures in the command line can stay.
162- if int (vim_eval ("g:jedi#show_call_signatures" )) == 1 :
163- clear_call_signatures ()
164160 if vim .eval ('a:findstart' ) == '1' :
165161 count = 0
166162 for char in reversed (vim .current .line [:column ]):
167163 if not re .match ('[\w\d]' , char ):
168164 break
169165 count += 1
170166 vim .command ('return %i' % (column - count ))
171- else :
172- base = vim .eval ('a:base' )
173- source = ''
174- for i , line in enumerate (vim .current .buffer ):
175- # enter this path again, otherwise source would be incomplete
176- if i == row - 1 :
177- source += line [:column ] + base + line [column :]
178- else :
179- source += line
180- source += '\n '
181- # here again hacks, because jedi has a different interface than vim
182- column += len (base )
183- try :
184- script = get_script (source = source , column = column )
185- completions = script .completions ()
186- signatures = script .call_signatures ()
187-
188- out = []
189- for c in completions :
190- d = dict (word = PythonToVimStr (c .name [:len (base )] + c .complete ),
191- abbr = PythonToVimStr (c .name_with_symbols ),
192- # stuff directly behind the completion
193- menu = PythonToVimStr (c .description ),
194- info = PythonToVimStr (c .docstring ()), # docstr
195- icase = 1 , # case insensitive
196- dup = 1 # allow duplicates (maybe later remove this)
197- )
198- out .append (d )
199-
200- strout = str (out )
201- except Exception :
202- # print to stdout, will be in :messages
203- print (traceback .format_exc ())
204- strout = ''
205- completions = []
206- signatures = []
167+ return
207168
208- show_call_signatures (signatures )
209- vim .command ('return ' + strout )
169+ # Clear call signatures in the buffer so they aren't seen by the completer.
170+ # Call signatures in the command line can stay.
171+ if int (vim_eval ("g:jedi#show_call_signatures" )) == 1 :
172+ restore_signatures = False
173+ for linenr , line in vim_eval ('get(b:, "_jedi_callsig_orig", {})' ).items ():
174+ # Check that the line would be reset, helps with keeping a single
175+ # undochain.
176+ if line != vim .current .buffer [int (linenr )- 1 ]:
177+ vim_command ('silent! undojoin' )
178+ vim .current .buffer [int (linenr )- 1 ] = line
179+ restore_signatures = True
180+
181+ base = vim .eval ('a:base' )
182+ source = ''
183+ for i , line in enumerate (vim .current .buffer ):
184+ # enter this path again, otherwise source would be incomplete
185+ if i == row - 1 :
186+ source += line [:column ] + base + line [column :]
187+ else :
188+ source += line
189+ source += '\n '
190+ # here again hacks, because jedi has a different interface than vim
191+ column += len (base )
192+ try :
193+ script = get_script (source = source , column = column )
194+ completions = script .completions ()
195+
196+ out = []
197+ for c in completions :
198+ d = dict (word = PythonToVimStr (c .name [:len (base )] + c .complete ),
199+ abbr = PythonToVimStr (c .name_with_symbols ),
200+ # stuff directly behind the completion
201+ menu = PythonToVimStr (c .description ),
202+ info = PythonToVimStr (c .docstring ()), # docstr
203+ icase = 1 , # case insensitive
204+ dup = 1 # allow duplicates (maybe later remove this)
205+ )
206+ out .append (d )
207+
208+ strout = str (out )
209+ except Exception :
210+ # print to stdout, will be in :messages
211+ print (traceback .format_exc ())
212+ strout = ''
213+ completions = []
214+
215+ if restore_signatures :
216+ cursor = vim .current .window .cursor
217+ vim_command ('undo' )
218+ vim .current .window .cursor = cursor
219+ vim .command ('return ' + strout )
210220
211221
212222@contextmanager
0 commit comments