Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word and snippet completions being shown when Pylance does not have any completions #604

Closed
prrao87 opened this issue Nov 12, 2020 · 16 comments
Labels
bug Something isn't working needs investigation Could be an issue - needs investigation

Comments

@prrao87
Copy link

prrao87 commented Nov 12, 2020

Environment data

  • Language Server version: 2020.11.1
  • OS and version: Linux Mint 19.3
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.9

Expected behaviour

When typing in import statements with aliases (e.g., import pandas as pd or import numpy as np), the autocomplete suggestion should provide the currently entered alias (pd or np) as the top choice. Then, simply pressing Enter would allow the user to continue typing in the next line.

Actual behaviour

The currently typed alias (pd or np) is not shown at all, so pressing Enter at the end of the import statement selects the library name (pandas or numpy), which is really annoying. The only way to retain this is to press space and then enter, which results in redundant spaces at the end of each import statement.

Code Snippet / Additional information

import pandas as pd
import numpy as np

pylance

@jakebailey
Copy link
Member

So, this is due to the fact that we're no longer offering completions in contexts we can't actually know the name for (#163). But it seems that since we now return empty, VS Code's word suggestion is taking over and suggesting things.

If you set this, I believe it should work around the issue:

"[python]": {
    "editor.wordBasedSuggestions": false
}

The real fix may be to always give back something in the completion list, e.g. here offer up the thing the user already typed. I think TS does this.

@jakebailey jakebailey added the bug Something isn't working label Nov 12, 2020
@github-actions github-actions bot removed the triage label Nov 12, 2020
@jakebailey
Copy link
Member

@heejaechang FYI

@prrao87
Copy link
Author

prrao87 commented Nov 12, 2020

Thanks, the workaround makes sense! I can imagine offering the user-typed input as the first choice may have some edge cases that are not desirable. I wonder if it's possible to treat aliasing, specifically, differently from other situations where the user may not want the completion's first choice as what they just typed.

@jakebailey
Copy link
Member

We already know the context you're typing in (to know to explicitly return nothing), so adding this special case is likely to be okay. Just needs some investigation and testing.

@jakebailey jakebailey added the needs investigation Could be an issue - needs investigation label Nov 12, 2020
@heejaechang
Copy link
Contributor

heejaechang commented Nov 12, 2020

@prrao87 thank you for reporting.

so, I tried to see old experiences, typescript experiences and etc.

this is old
defname

as you can see, we used to add what the user has written so far into the list. I don't believe it was by design, but it happens to add those since it basically showed any symbols defined in the current scope which includes what the user has written so far.

due to that, it won't work if there is a syntax error such as
defname2

I tried typescript to see how they behave
defname3

it looks like typescript also behaves the same as us.

that being said, we can improve behavior around this if we want to (@savannahostrowski @judej)

options I can think on top of my head will be

  1. tell users to use wordBasedSuggestions or we explicitly turn it off under python.
  2. tell users to turn off acceptSuggestionOnEnter
  3. ask to enable SuggestionItemOptions support in vscode (VS LSP client supports it. see here) and we support it in the server
  4. we just manually add what the user has written so far explicitly (similar experience as we used to have)
  5. and more? (welcome any suggestion)
  • doing (1), we explicitly turn wordBasedSuggestions off under python is cheapest. then (4). (2) and (3) either don't require changes on our side or require changes in other components than us.

@prrao87
Copy link
Author

prrao87 commented Nov 13, 2020

Option 1 (turning off wordBasedSuggestions) is doing the trick quite well for me right now - but it's not at all obvious to new users to know that this is the option they need to turn off to get the right behaviour. In the end, it would be nice to have an easy, intuitive system for beginners within Pylance that doesn't require users to disable VS Code editor settings!

@prrao87 prrao87 changed the title Autocomplete not showing currently typed alias as the top choice during imports Code completion not showing currently typed alias as the top choice during imports Nov 13, 2020
@heejaechang
Copy link
Contributor

@prrao87 I agree. so (1), what I meant was we change default for wordBasedSuggestions for python to off. so there is nothing user need to do. it will be automatically off for python file. but users who really want wordBasedSuggestion can explicitly turn it on. and only those people need to know the option. not the other way around.

@jakebailey
Copy link
Member

jakebailey commented Nov 19, 2020

Also relevant is #629, as VSC will also try and offer up snippets. Since we don't send anything, they're highly ranked. (4) would fix that too, but we'd have to test and see how we feel about it. Maybe we only do (4) in the contexts where it's a "new name".

@heejaechang
Copy link
Contributor

my opinion is just doing simplest thing first (1) and see whether we get any feedback from users.

@jakebailey
Copy link
Member

jakebailey commented Dec 3, 2020

Pylance 2020.12.0 now includes (1). I don't want to close this quite yet to see how this works out, or if we need to try another method. Please let us know!

@jakebailey jakebailey added waiting for user response Requires more information from user and removed needs investigation Could be an issue - needs investigation labels Dec 3, 2020
@jakebailey jakebailey changed the title Code completion not showing currently typed alias as the top choice during imports Word and snippet completions being shown when Pylance does not have any completions Dec 15, 2020
@jakebailey
Copy link
Member

Updating the title of this to better reflect; we did the word completion thing, but snippets remain a problem. We may need to attempt the method where we add a fake completion for the prefix.

@prrao87
Copy link
Author

prrao87 commented Dec 16, 2020

@jakebailey I'm really conflicted about snippets - on the one hand it's annoying to keep on because it does things like suggest pdb.set_trace() when I just want to import pandas as pd

1

On the other hand, I really like the convenience of the __main__ boilerplate using snippets, so I don't want to disable it.

2

Do you know whether there's a workaround to get the second behaviour but not the first? Is it possible to disable snippets but still be able to generate boilerplate like in the second case using just Pylance?

I know you're doing your best to track all these issues in various places, so thanks a lot for your efforts!

@jakebailey
Copy link
Member

jakebailey commented Dec 16, 2020

It's a VS Code quirk. We answer the completion request with "there are no completions", but then it also offers up word and snippets. This means that those are the only choices, and then they get picked and do the wrong thing.

There isn't a way to selectively choose snippets that as far as I remember, maybe there's a way to disable specific snippets but I haven't tried.

@jakebailey
Copy link
Member

The most recent version of the core extension dropped snippets altogether. With our word completion default set to false, I'm not entirely certain this is a problem anymore, but the idea to always offer "what was typed" as a completion may be a useful idea if we want to ensure we don't break if word completion is enabled.

@prrao87
Copy link
Author

prrao87 commented Feb 5, 2021

I agree, the "what was typed" is definitely something I see as being useful in the long term.

@judej
Copy link
Contributor

judej commented Mar 23, 2022

Thanks for the report. This has been fixed. Please reopen if this is still an issue.

@judej judej closed this as completed Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation Could be an issue - needs investigation
Projects
None yet
Development

No branches or pull requests

4 participants