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

Autocomplete should be less aggressive about suggesting function definitions #629

Closed
tuchandra opened this issue Nov 19, 2020 · 3 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@tuchandra
Copy link

Environment data

  • Language Server version: 2020.11.2
  • OS and version: MacOS 10.15.3 Catalina
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.6, miniconda

Expected behaviour

Code completion should be less aggressive about suggesting function definitions.

Some examples:

  • typing from torch.utils.data import Data should suggest at the top the two items that begin with Data, DataLoader and DataSet
  • typing from torch.utils.data import DataLoad should suggest at the top the one item that begins with that, DataLoader
  • typing from datetime import d should suggest closer to the top the items that begin with d, date and datetime
  • typing from datetime import date should suggest at the top the items that begin with date, date and datetime

Actual behaviour

The suggestions from Pylance autocomplete place what I think is way too high of a priority on fuzzy matches. The first few options are usually some combination of def, def(class method), def(abstract class method) and def(static class method).

image

image

image

image

These suggestions in particular don't really make any sense in the context of imports—they'd all be syntax errors—but I am not sure if this problem is limited to imports.

Logs

There don't appear to be any here.

Code Snippet / Additional information

Code snippets are above. I don't know if this is a design decision or an actual bug, but it feels apparent to me that the exact matches should be listed at the top. I don't believe this has been filed before; I searched for 'autocomplete', 'completion', and 'suggestions' but didn't see a relevant issue. I apologize if it has.

Thank you for your great work on Pylance. It's incredible how well it works day-to-day. I really appreciate it.

@jakebailey
Copy link
Member

jakebailey commented Nov 19, 2020

This behavior changed once we stopped offering completions in these contexts (as we can't know what you want to name a new import alias). VS Code has taken over and started offering snippets and word suggestions.

These snippets come from the Python extension and are injected directly by VS Code itself. The snippet rules rely on regex matching (at best) to guess as to what context they should be offered in, and IMO don't work so well. Personally I recommend disabling them altogether:

"[python]": {
    "editor.snippetSuggestions": "none"
}

Or just for every language (what I do):

"editor.snippetSuggestions": "none"

Once these are disabled, you may get word suggestions too, and there's info in #604 for that.

I'm going to close this as a dupe of #604 as I believe the fix for that will also fix this issue (offering up a single completion that's what you typed so VS Code stops trying to be clever), but I plan to file a proposal on the Python extension about just not having the snippets anymore.

@jakebailey
Copy link
Member

Filed microsoft/vscode-python#14781.

@tuchandra
Copy link
Author

Thanks for the quick response. That all makes sense; I didn't realize it was upstream now. I appreciate the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants