Don't list all of the keywords of Python and suggest them when I type a left square bracket #2599
Replies: 11 comments
-
In addition, previously suggested items are also included in the suggestion list. |
Beta Was this translation helpful? Give feedback.
-
Pylance doesn't have contextual completions for keywords; we offer them up most everywhere, but with a very low priority compared to other items in the completion list. Are you seeing otherwise? What do you mean by "previously suggested items are also included in the suggestion list"? |
Beta Was this translation helpful? Give feedback.
-
(See also #1557, which should be retitled to be more clear.) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
This is what I'd expect to see in this case — at least given the current implementation. The names Perhaps as a simple short-term improvement we could omit all keyword suggestions if you haven't started to type an identifier. Once one an alphabetical character has been typed, we can suggest only the keywords that match that filter. For example, if you were to place the insertion point between the square brackets, no keywords would be suggested until you type a character, say an In the future, we could add further smarts to offer only the keywords that are syntactically appropriate at the current location, but that's a much larger change. |
Beta Was this translation helpful? Give feedback.
-
Tracing this out, I was surprised to learn that we actually place keywords above "normal" completions when making the sort text: https://github.com/microsoft/pyright/blob/fa4194fd8b0e6d9fb970468e50a974e0d4eeee5c/packages/pyright-internal/src/languageService/completionProvider.ts#L177-L181 Perhaps that could change? We already appear to place "likely keywords" at the top of the list, so this might work better than not offering up keywords until more than one character was typed. |
Beta Was this translation helpful? Give feedback.
-
I've also retitled #1557 to better reflect the idea of contextually offering up completions (but the above suggestion could happen sooner than a bigger change to how we do keywords). |
Beta Was this translation helpful? Give feedback.
-
When I wrote the original completion code in pyright, I took a stab at the best sort order, but it wasn't informed by any user feedback. Based on the feedback in this thread and others, I think it's reasonable to demote keywords below "normal" and perhaps even "private" symbols — at least until we add code to provide contextual keyword filtering. |
Beta Was this translation helpful? Give feedback.
-
This may even be something we could run an experiment on (to see what people actually like). |
Beta Was this translation helpful? Give feedback.
-
Related is #1136, where @DanielRosenwasser suggested giving keywords and variables the same precedence. (I forgot that issue was there; found it while pruning old issues.) |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
Environment data
Expected behaviour
Don't list all of the keywords of Python and suggest them when I type a left square bracket
Actual behaviour
Lists all of the keywords of Python and suggests them when I type a left square bracket.
Logs
Code Snippet / Additional information
XXX
Beta Was this translation helpful? Give feedback.
All reactions