GNOME Bugzilla – Bug 578599
ipython_view completion feature has a bug
Last modified: 2021-05-17 15:43:35 UTC
Please describe the problem: Hi, The completion feature of the ipython_view.py source file is not working as expected in some cases. I'm using the ipython_view.py console in an application i'm developing. Steps to reproduce: 1. set two variables with a common prefix: x1 = 1 and x2 = 2 2. now write: type(x) 3. put the cursor between the x and the closing bracket 4. press tab Actual results: instead of having a list of variable starting with x, that is x1 and x2, lots of other variables are thrown out. Expected results: i would expect a list of the variables starting with x Does this happen every time? yes Other information:
I'm currently writing a patch to fix this... hope to be able to fix it.. :)
i think that this bug derives from two causes and i've managed to fix the first one , but i can't figure out how to fix the second one. 1) in the complete() method of the IterableIPShell class the string to pass to the IP.complete method is not split_line = self.complete_sep.split(line) but we want to pass it the string between the cursor and the first blank space at his left. This can be done for example with this code: split_line = self.complete_sep.split(line) # we pass to IP.complete the string to be completed. # this is the string between the cursor and the first blank space at his left cursor_iter = self.text_buffer.get_iter_at_mark( self.text_buffer.get_insert() ) end_iter = self.text_buffer.get_end_iter() #this is a "dirty hack" text_from_cursor_to_the_end = self.text_buffer.get_text(cursor_iter, end_iter) if text_from_cursor_to_the_end: string_to_complete = split_line[-1].split(text_from_cursor_to_the_end)[0] else: string_to_complete = split_line[-1] possibilities = self.IP.complete(string_to_complete) In this way the variable string_to_complete is the "true" prefix we would like to find matches for. Then the code goes into the onKeyPressExtend method of the ipythonview class and there is a call to showPrompt() and changeline.. but i cannot figure out how to fix the bad behaviour we have. Sorry, i'm quite new to python Hope that someone fixes this.. Cheers
Haven't looked at this code in a very long time. If you provide a fix, I would be happy to use it.
Bug confirmed.
Created attachment 191257 [details] [review] lasagna davide's solution for completion feature Bug #500900 was fixed and your code alone, lasagna davide, solves the whole problem. I tested it a lot in 3.1.2 and 3.1.3 accerciser's versions and it works! Since the patch I'm attaching is a simple copy of lasagna's work, a maintainer that wants to push it to accerciser's master should set the patch's authorship to him - not to me.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/accerciser/-/issues/30.