Skip to content

If I have Python-related files in my workspace, automatically activate the extension #4765

Closed

Description

Goal - Lets not wait for the user to open a python file to activate the extension

If the user has some of the following files we could probably activate the extension without having to wait for the user to open a python file:

  • pip env files
  • poetry files
  • setup.py
  • setup.cfg?
  • tox.ini
  • pyproject.toml
  • pytest.ini
  • requirements.txt
  • test_requirements.txt
  • .pylintrc
  • .flake8
  • __init__.py
  • manage.py
  • src/__init__.py
  • tests/__init__.py
  • meta.yml
  • environment.yml
  • anaconda-project.yml
  • .pep8
  • .pycodestyle

Activity

  1. ghost added
    triage-needed
    on Mar 14, 2019
  2. ghost removed
    triage-needed
    on Mar 14, 2019
  3. znd4 commented on May 15, 2019

    @znd4

    I know you included etc., but I'd like to explicitly call out meta.yml, environment.yml, and maybe even anaconda-project.yml. :)

  4. added
    experimenting
    and removed on May 21, 2019
  5. wis commented on Jun 17, 2019

    @wis

    also .pep8 and I think .pycodestyle

  6. changed the title [-]Auto activate extension based on files in the workspace[/-] on Sep 26, 2019
  7. changed the title [-]If I have Python-related files in my workspace, automatically activate the extension [/-] on Sep 26, 2019
  8. DonJayamanne commented on Mar 30, 2020

    @DonJayamanne
    Author

    Luciana Abud (@luabud) we have an external PR for this issue.
    FYI, this was meant to be an experiment, hence the label.
    We might also want to list down each file that we want to support/look for.

  9. karthiknadig commented on Mar 31, 2020

    @karthiknadig
    Member

    Don Jayamanne (@DonJayamanne) this is a change to package.json. Is there a way to add this to experiment?

  10. DonJayamanne commented on Apr 27, 2020

    @DonJayamanne
    Author

    Sorry, I missed that question.
    I can see only one way of doing this.
    When extension loads, we modify package.json file, then next time they load extension package.json file will contain the required changes and things will work as expected.

    I.e. extension will need to modify package.json during runtime, instead of shipping it.

    We might need to change how this experiment works, else we'll get telemetry for users who open VSC once and we'll (via telemetry) get notified they are in the experiment, when in fact they aren't (not until they re-load VS Code).

  11. 33 remaining items

  12. lsorber commented on Apr 8, 2021

    @lsorber

    Dhaval Soneji (@Soneji) Could you also add a trigger for environment.yml for conda users? 🙏

  13. Soneji commented on Apr 8, 2021

    @Soneji

    hey Laurent Sorber (@lsorber)

    I can send another PR (and so could you! 😉 ) but it's up to the team that maintains the project (Brett Cannon (@brettcannon) , Luciana Abud (@luabud) , etc.) whether they approve of it and ultimately whether it gets merged.

  14. Soneji commented on Apr 8, 2021

    @Soneji

    Also, if we're increasing the list of files, we should definitely add the poetry files too (from the first comment), like pyproject.toml

  15. brettcannon commented on Apr 8, 2021

    @brettcannon
    Member

    Laurent Sorber (@lsorber) environment.yml is a little tricky because it's used by conda in all languages they support, e.g. R. So we would over-trigger in that instance and we have already received a lot of complaints in the past about launching when we weren't wanted. And because this is declarative in package.json we can't programmatically say "trigger for environment.yml if it lists a Python version" or something.

    Dhaval Soneji (@Soneji) we have actually been triggering for pyproject.toml for at least 7 months now, so Poetry users are all good 😄

  16. lsorber commented on Apr 8, 2021

    @lsorber

    Brett Cannon (@brettcannon) thanks for clarifying, that makes sense. Would it be possible to trigger activation based on their being a virtual/conda environment associated with the workspace? That should have pretty high recall and precision I expect.

  17. brettcannon commented on Apr 9, 2021

    @brettcannon
    Member

    Laurent Sorber (@lsorber) only if there's a way to statically list a file to trigger against. All the details of what we can trigger on can be found at https://code.visualstudio.com/api/references/activation-events. We purposefully don't blindly trigger due to how big/heavy the extension is.

  18. lsorber commented on Apr 9, 2021

    @lsorber

    Right, but VS Code knows whether there's a Python environment associated with the workspace, so that seems like it would be a perfect trigger, or not?

  19. benlindsay commented on Apr 9, 2021

    @benlindsay

    Laurent Sorber (@lsorber) I like that idea if it's possible. I think all my python projects have python.pythonPath set in the workspace's settings.json file

  20. brettcannon commented on Apr 9, 2021

    @brettcannon
    Member

    Laurent Sorber (@lsorber) VS Code only "knows" that there's a Python environment because our extension makes that true. Technically VS Code itself couldn't care less about any of this; all it cares about is knowing when to launch our extension. We then bring in the concept of a Python environment after we start up. So this issue is specifically about when to launch our extension which itself brings in the concept of Python environments.

  21. lsorber commented on Apr 9, 2021

    @lsorber

    Brett Cannon (@brettcannon) I see, then how about a minimal startup to check whether there's a Python environment associated with the workspace and if not (and nothing else would trigger the extension) immediately shut down again?

  22. brettcannon commented on Apr 12, 2021

    @brettcannon
    Member

    Laurent Sorber (@lsorber) that is still a very expensive thing to do (and especially for conda).

  23. Soneji commented on Apr 12, 2021

    @Soneji

    Maybe this could be taken to the vscode repo itself and see if they can add another type of activation event? Is there any sort of (not very intensive) activation event that could work for conda, and could even be useful for other developers?

  24. lsorber commented on Apr 12, 2021

    @lsorber

    Brett Cannon (@brettcannon) why would that be expensive? I'm referring to simply checking whether the user associated a Python environment with the workspace in their workspace settings.json.

    Making the presence of a workspace-specific setting a new type of trigger sounds like it could be a solution (based on my limited understanding of VS Code).

  25. brettcannon commented on Apr 13, 2021

    @brettcannon
    Member

    why would that be expensive? I'm referring to simply checking whether the user associated a Python environment with the workspace in their workspace settings.json.

    We would still have to launch the extension to detect this. Plus not every user who sets up a Python environment wants to load the extension every time (e.g. C/C++ users who have some Python code to gather test data). The existence of settings is not enough information to infer that activation of the extension is desirable in all cases. Hence why we have only trigger automatic loading on project-level files instead of any Python file existing.

    Now if you're proposing a hypothetical check for a setting, then that's different, but not at all under our control as that would have to come from VS Code.

    Otherwise you can open a feature request at https://github.com/microsoft/vscode-python/discussions/categories/ideas and see if enough people can convince us to ignore non-Python conda users and thus trigger on environment.yml (or you find some other file we can use to trigger on).

  26. locked as resolved and limited conversation to collaborators on Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-editor-*feature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions