Provide completions for unicode names#11583
Conversation
|
I also realized that the API in /core/completer.py has some TODOs. Is there someone mainly responsible for this part? I'd like to give it a try with some improvements and it would be good to talk about first. |
No-one in particular it would be great to get some of that done, but let's focus on unicode so far. From your code I see where some of the misunderstanding and issue are. Currently in IPython, you can do This is done through If you look carefully you will see that this is already done in One thing we do not have though is if someone type only We need to build this possibility ahead of time. So now let's try to slightly modify you function fwd_unicode_matches: Let's try it: Good, nothing, we did not attempt to find greek letters so far. Let's try latin: Ok, sounds good. Let's try to add that into completer.py. Ok, good ! It seem to work. Now we need to be a tiny bit fancier, and allow upper and lower case to match, and instead of allowing only 65 to 90 we want to try from 0 to let me know if that is helpful, I'm going to stop here on the explanation and let you play along with it. |
I didn't understand really how are we supposed to look into the unicode symbol table to lookup for possible candidates. That really helped :) That was mainly because I noticed there wasn't an unicode table somewhere, similarly to latex symbols. At first, I wasn't confident enough to suggest to add it.
Ok, surely will do it! Is there a way we can share the author rights of these when there's a commit ready to merge? I feel like most of the work was done by you even if I'm commiting them.
Thanks, it really was :) |
Haha, don't worry I have plenty of commits already, there apparently is a way to ahve multiple authors but it's cumbersome, so feel free to take all the glory :-) |
|
Apologies for the delay reviewing. It seem the test are not passing due to a typo. I'll see if I can fix, it. |
|
Side question, are you familiar with travis CI and how to check if the rest are passing ? |
| names = [] | ||
| for c in range(0,0x10FFFF + 1): | ||
| try: | ||
| names.append(unicodedata.name(chr(c))) |
There was a problem hiding this comment.
You used char here instead of chr. I fixed it.
IPython/core/completer.py
Outdated
| return name_text, name_matches[:MATCHES_LIMIT], \ | ||
| [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), () | ||
| elif (completion_text): | ||
| return completion_text, completion_matches, () |
There was a problem hiding this comment.
those 3 things are not quite correct. Python have functions and methods as first class values, so you can do
- for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches)
+ for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches, self.fwd_unicode_match)And it will work better.
IPython/core/completer.py
Outdated
|
|
||
| # if text does not start with slash | ||
| else: | ||
| return u'', [] |
There was a problem hiding this comment.
There is one more issue if we run the test here.
We can see that if [x for x in names if x.startswith(s)] is empty, then we should not return s but an empty string.
This might be a bug somewhere else in IPython, but it breaks the test suite. I can fix it like so :
@ completer.py:2076 @ def fwd_unicode_match(self, text:str) -> Tuple[str, list]:
# if text starts with slash
if slashpos > -1:
s = text[slashpos+1:]
- return s, [x for x in names if x.startswith(s)]
+ candidates = [x for x in names if x.startswith(s)]
+ if candidates:
+ return s, [x for x in names if x.startswith(s)]
+ else:
+ return '', ()
# if text does not start with slash
else:
- return u'', []
+ return u'', ()There was a problem hiding this comment.
I find it confusing sometimes how python manages a few string/character related things.
If we don't do so, it will not try the next completers.
|
I've push relevant changes, please have a look, and let me know if that make sens. |
|
And now we are happy, out first test seem to be green ! Seem like this il likely to be merged soon. But first, we'll need to make sure all the test are passing ! |
|
All is green ! 🍰 Let me know once you have reviewed and agreed with my change and we can merge :-) |
|
Hey @Carreau ! Many thanks for the review! I think at the time I just committed a few changes based on what you said, but I left it incomplete to finish later and haven't had the time earlier. So sorry for the delay! I'm happy with the changes, but I would be much happier if we shared authorship as previously discussed :) Many thanks! |
|
If it's ok, I would like to work on the other TODOs of this class. |
No need to apologise, you are not officially working on the project, and you contributed a lot already.
I have two commits in the branch now so I'll have partial credit:-) I'l like for you to look at a few things: We're planning participating in outreachy again – you expressed interest in being in an internship, and I would love if we can do that. Woudl you mind reading /participating in the following discussion ? https://discourse.jupyter.org/t/thinking-about-reapplying-to-outreachy-in-may-2019/404
Again work on what you like. |
That's great! I'm so glad for it :) I'll join the discussion!
Yeap, sure! Just a quick question for future reference, when do we know when to write on this folder? What exactly does the PR has to achieve in order to do so? Many thanks! :) |
|
The files in docs/source/whatsnew/pr/ are just merged together at each release to create a final what's new /changelog which is published there, it is mostly to tell users what is new in the release, so can be a 1 line change, or a multi page explanation. Up to you and how much text you think it is worth. |
…pletions Add #11583 description on docs/source/whatsnew/pr

As discussed in #11449 , this is a WIP.
I'm having trouble in looking up for possible unicode completions (inserted comments int the code). The draft of the new function to be added is at the bottom of the file. I'm trying to do something similar with the completions for latex, but cannot figure how to look up for completion candidates.
This patch also include documentation modifications.