Skip to content

Add a way to restart the Python Language Server #3073

Closed

Description

If the python language server crashes or gets into an unusable state, the only way to get it working again is to reload the entire editor window. This is very inconvenient.

Environment data

  • VS Code version: 1.28.2
  • Extension version (available under the Extensions sidebar): 2018.9.2
  • OS and version: Windows 10 version 1803
  • Python version (& distribution if applicable, e.g. Anaconda): N/a
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/a
  • Relevant/affected Python packages and their versions: N/a

Actual behavior

The only way to restart the Python Language Server is to reload the window

Expected behavior

A menu option to restart the python language server should be present, like with Typescript
image

Steps to reproduce:

N/a

Logs

N/a

Activity

  1. jimklo commented on Nov 29, 2018

    @jimklo

    This is a much needed feature.

  2. KLDGH commented on Dec 1, 2018

    @KLDGH
  3. angelhdzmultimedia commented on Mar 14, 2019

    @angelhdzmultimedia

    Please add this command! It's crashing a lot! And I have to reload the whole workspace window!

  4. SIGSTACKFAULT commented on Sep 12, 2019

    @SIGSTACKFAULT

    [bump]

  5. angelhdzmultimedia commented on Sep 13, 2019

    @angelhdzmultimedia

    [bump]

  6. DonJayamanne commented on Sep 13, 2019

    @DonJayamanne

    AngelHdz Connor K (@SIGSTACKFAULT)

    Please could you let is know why this is required.
    I.e. if you are having issues with the language server, please could you file an issue with the details.

    I understand the need for such a feature (a quick fix to get the extension working, without reloading the window), however at the same time I'd like to ensure we resolve the root cause, else restarting LS is merely going to mask the underlying problem.

    Also please do upvote 👍 the issue so we can track and prioritize this issue.

  7. angelhdzmultimedia commented on Sep 13, 2019

    @angelhdzmultimedia

    AngelHdz Connor K (@SIGSTACKFAULT)

    Please could you let is know why this is required.
    I.e. if you are having issues with the language server, please could you file an issue with the details.

    I understand the need for such a feature (a quick fix to get the extension working, without reloading the window), however at the same time I'd like to ensure we resolve the root cause, else restarting LS is merely going to mask the underlying problem.

    Also please do upvote 👍 the issue so we can track and prioritize this issue.

    Thank you for replying!

    When I submitted the issue to the VSCode repository, it was implied that if there was any issue, that I must be an extension's fault. But I did my debugging. For my specific issue (issues with code hinting/intelli-sense), I removed every extension I could and only left this one (so I could debug Python files). The issue remained.

    The issue is, after a while of working, intelli-sense just stops auto completing things, and sometimes, it throws errors like "undefined property asdfetasd". It looks like the language server just stops working and remains with cached data.

    So I decided to try other languages in my other workspaces, like Dart language, Javascript, Actionscript 3.0 with the Actionscript & MXML extension, etc.

    And guess what? I had the same issues!!!!

    So, it's either these language's language servers malfunctioning, or is an issue with VSCode's Intellisense!

    This happens to me in every VSCode version I install.

    For example, few days ago I was working with Javascript. And I had the Workspace Settings *.json file opened for editing the Theme's colors.

    And suddenly, I started to have errors that there were undefined things or syntax errors in that file. So I reloaded the workspace without changing anything in the file, and the errors went away!

    Sometimes, just by saving the files, the errors go away.

    But the code hinting/auto-complete/intelli-sense only gets solved if I reload the workspace.

  8. DonJayamanne commented on Sep 13, 2019

    @DonJayamanne

    AngelHdz Sounds like you are experiencing issues with VS Code (if you have similar issues with other languages as well).
    Please could you provide a link to the original issue.

  9. angelhdzmultimedia commented on Sep 13, 2019

    @angelhdzmultimedia

    AngelHdz Sounds like you are experiencing issues with VS Code (if you have similar issues with other languages as well).
    Please could you provide a link to the original issue.

    microsoft/vscode#80289 (comment)

  10. DonJayamanne commented on Sep 13, 2019

    @DonJayamanne

    AngelHdz Please could you try using the Python extension using Jedi (disable the Language Server). To do so, please open your user settings and ensure the setting Python: Jedi Enabled is selected, see below:
    Screenshot 2019-09-13 at 11 55 42

    Let me know how that goes. If you still experience the same issues, then it is related to VS Code, else its related to the Language Server and we probably should get some logs from you (we can do that later - basically enable verbose logging).

  11. 18 remaining items

  12. MikhailArkhipov commented on Jun 21, 2020

    @MikhailArkhipov

    TS server is a different product, implemented in a different language and running in a different environment. There are also fundamental differences in how LS are activated and wired up. Different LS are not always comparable.

    It is doable but amount of work is far from small. Restart may be a solution for mentioned above issues with git or pip installs, but if LS crashed or got stuck analyzing something, it most probably will crash or get stuck again... The underlying issue is should be fixed preferably.

  13. Lexicality commented on Jun 23, 2020

    @Lexicality
    Author

    My apologies, I assumed from jakebailey's earlier comment that there was a function you could call.

    The underlying issue is should be fixed preferably.

    In the long term yes, but in the short term if I'm at work and my python completions system goes haywire my first thought is "Oh god how can I make this start working again as quickly as possible so I can complete my ticket" not "oh that's interesting let me start debugging my IDE"

    If I have to reload the window, that means I have to stare at a blank screen while all my extensions re-initialise and I lose all the terminals I had open and any programs running in them. It's really not good for maintaining flow.

  14. nourselim0 commented on Jul 11, 2020

    @nourselim0

    Mikhail Arkhipov (@MikhailArkhipov) The problem I face isn't the LS crashing or getting stuck analyzing forever, but rather it suddenly has a completely invalid state (eg: it thinks a certain variable is defined at some line while it's a few lines above/below), this happens while I'm doing interactive rebases, my guess is that files change very quickly leading the LS to be very confused as the files change during its analysis.
    If there was a command to restart the LS, I'd gladly run it after one of these intensive rebases. I feel like it will be easier than fixing the underlying bug because it's quite hard to reproduce.

  15. jakebailey commented on Jul 11, 2020

    @jakebailey
    Member

    I still think this is doable (just needs a PR, and a whole lot of testing for the notebooks side of things...), but @hassanselim0 I'd be curious if you had tried out Pylance as your LS to see if it solved any of your issues with the LS getting confused.

  16. jakebailey commented on Jul 14, 2020

    @jakebailey
    Member

    Was bored watching TV last night and made #12952 that implements this (but needs a bit more testing).

  17. nourselim0 commented on Jul 15, 2020

    @nourselim0

    Jake Bailey (@jakebailey) I actually learned about PyLance just 1 day after writing my last comment and I switched to it.

    So far it's faster (don't have to wait a long time to analyze), and I can keep going to definition (F12) recursively in library code seemingly indefinitely (previously at some point I'd hit an invisible wall unable to analyse library code any further). But I'll need more time to see if this rebase confusion happens or not.

  18. markdude247 commented on Jul 19, 2020

    @markdude247

    I would also vote to have a feature/command to manually restart the Language Server. It seems as though the longer it is active, the slower it goes.

    • I also would like to restart it when I install a new library
  19. jakebailey commented on Jul 20, 2020

    @jakebailey
    Member

    I also would like to restart it when I install a new library

    See: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#completions-do-not-update-andor-import-is-still-being-reported-as-unresolved-after-pip-install

    (Or, try Pylance, which does not suffer from the shortcomings that make the above true)

  20. joshwapohlmann commented on Aug 4, 2020

    @joshwapohlmann

    Another scenario:
    I need this feature when developing with ROS2 so intellisense finds libraries I source the ROS2 distribution

    . /opt/ros2/<release>/setup.bash

    This will modify PYTHONPATH which points to ros2 specific libraries which I want intellisense to pick up ... which is doesn't because I have to source this in each termina and vscode doesn't provide a way to do this automatically (to my knowledge).

    UPDATE: A workaround is to start vscode from a terminal where ros2 has already been sourced. This STILL leaves the problem, if I develop new code which is sourced with

    . install/setup.bash

    in the local workspace. So I STILL need a way that IntelliSense will reconsider PYTHONPATH and rebuilds its cache.

  21. camsteffen commented on Sep 17, 2020

    @camsteffen

    Looks like this issue is resolved by #12952.

  22. jakebailey commented on Sep 17, 2020

    @jakebailey
    Member

    Yep, it's been in for a good bit. PR's here only mention the issue they fix, but I don't know exactly when someone goes back to "verify" that it works.

  23. Lexicality commented on Sep 17, 2020

    @Lexicality
    Author

    Seems to work, thanks a lot!

  24. locked as resolved and limited conversation to collaborators on Oct 7, 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-*User-facing catch-allarea-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.feature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions