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

Auto-import should suggest exact matches with higher priority #297

Closed
matangover opened this issue Aug 29, 2020 · 16 comments
Closed

Auto-import should suggest exact matches with higher priority #297

matangover opened this issue Aug 29, 2020 · 16 comments
Assignees
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@matangover
Copy link

When showing code actions for Path, I get:

image

The fourth item is clearly the one I'm after, as it's an exact match to what I've typed. Personally I'm inclined to think code actions should not suggest 'fuzzy' auto-imports at all (e.g. it's very improbably that I'm looking to import pathccompiler from numpy.distutils). That is, I don't naturally expect auto-complete in code actions, only auto-import of what I've already typed. But my main suggestion is to show the most relevant option (exact match) on top or at least have it initially selected.

@jakebailey
Copy link
Member

We're currently working on this (#97); by Path I'm assuming you are actually interested in pathlib.Path, correct? We don't offer values out of modules that we haven't already analyzed, so you'll only get the odd thing that has been analyzed, or mostly, module names.

I believe that this is going to be much, much improved in next week's release (though we're still tweaking things!).

@jakebailey jakebailey added enhancement New feature or request in backlog labels Aug 29, 2020
@github-actions github-actions bot removed the triage label Aug 29, 2020
@matangover
Copy link
Author

Oh, that's great! I see two separate issues:

  1. Values from unanalyzed modules do not show up. I was just about to report this: Add import Path from pathlib doesn't show up unless I type import pathlib manually first (causing the module to be analyzed). I understand I don't need to report this, as it's already being worked on.

  2. As I wrote above: When the module is already analyzed, the ordering of the items is not intuitive (exact match doesn't come first). Is this also being worked on / improved in the next release?

Thanks!

@jakebailey
Copy link
Member

jakebailey commented Aug 29, 2020

We're aware of both of these things. I know that the former is what we've been focusing on (getting values), and after that the latter (filtering them and ordering the values now that we have them).

@matangover
Copy link
Author

Great. Thanks.

@matangover
Copy link
Author

P.S. I believe most other IDEs don't offer 'fuzzy' matches for auto-import, and this is why I'm surprised to see so many options in the dropdown. But as long as the best option is selected first, it doesn't matter that much.

@heejaechang heejaechang self-assigned this Sep 2, 2020
@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Sep 4, 2020
@heejaechang
Copy link
Contributor

should be fixed in the next version.

@heejaechang
Copy link
Contributor

heejaechang commented Sep 11, 2020

until we improve the memory/CPU issue with auto-indexing, you need "python.analysis.indexing": true in .vscode/settings.json for "add import/auto import" feature for third party libraries to be enabled.

@matangover
Copy link
Author

matangover commented Aug 22, 2021

This is still not fixed, can it be re-opened? I can still reproduce both issues 1 and 2 described above.

Issue 1:

image

Here sys should be shown but since it hasn't been analyzed yet (hasn't been manually imported), the auto-import suggestion are only showing results from the os module (which has been manually imported).

Using latest version Pylance language server 2021.8.2 (pyright f462f5bb)

@matangover
Copy link
Author

matangover commented Aug 22, 2021

Issue 2:

image

The exact match shows up last instead of first.

@jakebailey
Copy link
Member

Set "python.analysis.indexing": true, and if it works, then it will work when we enable indexing for everyone.

@matangover
Copy link
Author

Thanks for the info. That's great! I confirm that adding this setting fixes issue 1 when having a workspace folder opened. However, it's still not fixed when only a single file is opened (i.e. having no workspace folder open).

Also, it doesn't fix issue 2:
image

@jakebailey
Copy link
Member

We'd appreciate new issues for each of these, if you could.

@matangover
Copy link
Author

I can open a new issue for "issue 1 not fixed when single file is opened". For "issue 2 not fixed" this current issue should be reopened, since it is exactly that.

@jakebailey
Copy link
Member

Yes, thanks. I didn't notice.

@jakebailey jakebailey reopened this Aug 23, 2021
@jakebailey jakebailey added needs investigation Could be an issue - needs investigation and removed enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version in backlog labels Aug 23, 2021
@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jan 11, 2022
@heejaechang heejaechang removed the needs investigation Could be an issue - needs investigation label Jan 11, 2022
@heejaechang
Copy link
Contributor

now, we always enable indexing on stdlib and fixed a bug on ranking that got broken when we did file path normalization.

@bschnurr
Copy link
Member

This issue has been fixed in version 2022.1.1, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants