Improves detection of whether tab-completion is in a string and suppresses Jedi#12128
Conversation
…sses Jedi. Refs #10926 and #11530 Jedi results swamp file_matches and dict_key_matches in tab-completion, which is a real nuisance. The logic in the jedi completor tried to catch cases where it was "in a string", but that logic only looked at the previous character, and was a little fragile, breaking in lots of cases such as: './<tab> "mypath/<tab> etc. This seems a bit more robust in that it searchs for the first token in the current parser tree and checks if its value starts with ' or ". This detection of "in a string" then turns of jedi and returns some sanity to the set of matches.
|
That would be nice ! Could it even be something that could be upstreamed in Jedi, so we coudl teach jedi to say "I'm in a string" ? or even complete strings ? I want o merge a PR that touch many files first and then I'm likely to get that merge. Likely tomorrow. Thanks for your patience and contributions ! |
|
Side note your commit is attached to your Oak Ridge mail, but github is not aware that you have an Oak Ridge email, sothe contribution will not appear to your profile. Do you ant to :
|
|
Thanks, I updated my github profile. |
I believe so. The code checking "I'm in a string" is entirely based on jedi's parsing. I'm not sure what is there in jedi to complete strings -- most of the time useful string completions would be either filenames or keys in a container, so I'm not sure what is/could be added to jedi with regard to that. Also, if I get time, I'll look at the implementation for "keys in a dict." Ideally this would be anything that implements keys(), or maybe even anything that implements contains, not just dict -- I've noticed that other file objects such as hdf5/netcdf4 files, which implement the keys() method and mimic a dictionary to work within their file structure don't work with tab completion. |
I'm mostly wondering if we could add completions plugin to jedi instead of hacking around jedi. For single-line string I agree, but if we are in a docstring, jedi might be able to help by completing also to the parameter of given functions or similar. |
…on is in a string and suppresses Jedi
Good, merging. |
…128-on-7.x Backport PR #12128 on branch 7.x (Improves detection of whether tab-completion is in a string and suppresses Jedi)
Refs #10926 and #11530
Jedi results swamp file_matches and dict_key_matches in
tab-completion, which is a real nuisance. The logic in the jedi
completor tried to catch cases where it was "in a string", but that
logic only looked at the last child in the current token, which was a little fragile,
breaking in lots of cases such as:
etc.
This seems a bit more robust in that it searchs for the first character in
the current parser tree and checks if its value starts with ' or ".
This detection of "in a string" then turns off jedi and returns some
sanity to the set of matches.
Note I have developed this with jedi 0.13.2 -- not sure if it is different logic in older versions.