Search code examples
pythonvisual-studio-codepylance

VSCode unhide sys.platform Python code for cross platform dev


I'm working on a Python project using Pylance that involves checking if sys.platform == "win32": and elif sys.platform == "darwin": Working on a Windows machine makes all the code inside the elif sys.platform == "darwin": greyed out (code is unreachable) which I understand. But it also means that menu options like Rename Symbol and Find all References don't alter or find parts in that section of code... I don't want this, I want all the code to be evaluated / visible to VSCode menu commands for cross platform development... is there a way to change it?


Solution

  • It's provided by the Language Server of Pylance. And it has not available methods to disable it for now. You can refer to this page for more details.

    My suggestion is, change the code of if sys.platform == "win32": to something others, such as if sys.platform == "win322": temporarily. Or you can have a try on some other Language Serve, such as: JediLSP.