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

Improve messaging when an import could not be resolved #21456

Closed
cwebster-99 opened this issue Jun 20, 2023 · 13 comments
Closed

Improve messaging when an import could not be resolved #21456

cwebster-99 opened this issue Jun 20, 2023 · 13 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@cwebster-99
Copy link
Member

cwebster-99 commented Jun 20, 2023

Background

A common hurdle new users encounter when using Python in VS Code is package installation. Those new to Python programming and working with editors find it challenging to understand the concepts of installing and importing packages, using pip, and managing environments. This complexity can lead to frustration and some users may even abandon Python in VS Code, perceiving it as unfriendly and intimidating for beginners.

Audience

The target audience for the proposed mockup is beginners who may not be comfortable or familiar with the idea of environments or third-party packages.

Current Behavior

Unresolved import messaging from Pylance

image

Current Code Actions

image

Proposed Behavior

To address some of the confusion around environments and package installation, we should provide specific Code Actions and/or specific messaging tailored for users that are not using an environment with their specified packages or struggle to resolve import errors.

💡“Select another interpreter”

  • If a Quick Fix - Link to Python: Select Interpreter command
  • Could be a hint or tip on hover

💡 “Learn how to install packages” (microsoft/pylance-release#3297)

Option 1: Present options in the Quick Fix list

image

Option 2: Provide a link at the bottom of the Quick Fix list and provide more info on hover

image

image

Example from TS:

image

cc @luabud

@cwebster-99 cwebster-99 added the feature-request Request for new features or functionality label Jun 20, 2023
@cwebster-99 cwebster-99 changed the title Improve messaging when an import cannot be resolved Improve messaging when an import could not be resolved Jun 20, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 20, 2023
@cwebster-99 cwebster-99 removed the triage-needed Needs assignment to the proper sub-team label Jun 20, 2023
@cwebster-99 cwebster-99 self-assigned this Jun 26, 2023
@cwebster-99 cwebster-99 added the needs proposal Need to make some design decisions label Jun 27, 2023
@rchiodo
Copy link

rchiodo commented Jun 27, 2023

I think we should also add a better message to the message from Pylance. We have an issue for that here:
microsoft/pylance-release#4368

@cwebster-99
Copy link
Member Author

cwebster-99 commented Jun 27, 2023

@rchiodo Are you referencing this message (the tip added for the purpose of the spec)
image

Would the messaging you have in mind be to list the current environment the user is working in and then suggest switching or creating a new environment?

@rchiodo
Copy link

rchiodo commented Jun 27, 2023

I was thinking it would say something like so:

Import "flask" could not be found in the ".venv" environment. (reportMissingImports).

Then the tip you have would show up.
And the quick actions would have the options you mentioned above.

@rchiodo
Copy link

rchiodo commented Jun 27, 2023

I think the hard part here is adding that 'Tip' item. It would be relatively easy for us to add it on the Pylance side, but having the Python extension do so would be a lot harder.

@rchiodo
Copy link

rchiodo commented Jun 27, 2023

I also think the two options you have would be good combined as well. So the entire change would be:

Message:

Import "flask" could not be found in the ".venv" environment. (reportMissingImports). Tip: Ensure you are using the correct interpreter

Quick actions:

  • Select a different interpreter
  • Create a new venv with flask installed
  • Install flask into your .venv interprer
  • Learn more about interpreters

With maybe the middle two actions not in the MVP

@cwebster-99
Copy link
Member Author

I really like this idea for the MVP!

My only concern about the "Select another interpreter" as a Code Action is that it does not directly add code. Maybe it would be sufficient to just have the tip in the message? @luabud Do you have an opinion on this?

@rchiodo
Copy link

rchiodo commented Jun 29, 2023

I'm also thinking it makes the most sense for Pylance to make all of these changes. Otherwise, we're going to have to add something to diagnostics that allows the Python extension to figure out that it's an import error, and what package is missing.

@luabud
Copy link
Member

luabud commented Jun 29, 2023

Love the idea! Agreed with making this on the Pylance side. I wonder if it'd be possible to make the "select interpreter" command be triggered from a link in the tip? then it wouldn't need to be a code action?

@rchiodo
Copy link

rchiodo commented Jun 29, 2023

I believe that's possible, but I'm wondering why not use a code action?

Pylance can initiate a command from a code action, so it's certainly possible to 'Select interpreter' in a code action from Pylance.

@luabud
Copy link
Member

luabud commented Jun 29, 2023

I guess I was coming from the point of view that it's not really a code action as code isn't being touched/changed but I chatting with Brett he did bring up that it might make code no longer fail to execute, so a code action still makes sense. No objections against code actions anymore from me :p

@cwebster-99
Copy link
Member Author

cwebster-99 commented Jun 29, 2023

Awesome! I think the MVP should be as Rich outlined above contributed by Pylance:

Message:

Import "flask" could not be found in the ".venv" environment. (reportMissingImports). Tip: Ensure you are using the correct interpreter

Quick Actions:

  • Select a different interpreter
  • Learn more ....

For the "Learn more", I think it would be best to add a section to https://code.visualstudio.com/docs/python/environments#_working-with-python-interpreters or https://code.visualstudio.com/docs/python/editing#_troubleshooting-intellisense with information on how to troubleshoot the error message. Preferences on one or the other?

@rchiodo
Copy link

rchiodo commented Jun 29, 2023

Both :)

I mean if somebody is at either location, they should be able to learn the same information. Maybe both can point to another URL that describes the situation (or one points to the other).

@cwebster-99
Copy link
Member Author

Closing this in favor of the microsoft/pylance-release#4368 that tracked this work from the Pylance side.

@github-actions github-actions bot removed the needs proposal Need to make some design decisions label Dec 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants