Reputation: 19
I'm encountering a peculiar issue with VSCode's Python syntax highlighting. I use remote ssh to access these workspace. It works fine in some workspaces but fails in others. In the attached screenshots of two different workspaces opened simultaneously, you can see the noticeable differences. Not only does syntax highlighting not work, but the 'Command + Click' for definition navigation is also malfunctioning (it shows 'loading' and then freezes). No error messages are displayed, leading me to suspect an issue with Pylance. Some answers suggest that I could fix this by changing the language server to Pylance, but it's not working.
besides, my folder is like A_folder/B_folder/C_folder, and if I set the workspace to be C folder, the autohighlighting works, and it fails in A_folder or B_folder.
Attempts to resolve this have included:
Replicating the issue on a different computer using VSCode SSH to access these workspaces (shared remote drive). Setting the language server to Pylance for user, remote, and workspace settings instead of the default. Reinstalling the latest version of VSCode. Uninstalling and reinstalling Python or Pylance extensions in VSCode. Restarting the computer. Using "workspace cache clean" extension to clean the cache. None of these steps have resolved the issue. Any insights or suggestions would be appreciated.
Upvotes: 1
Views: 5850
Reputation: 1
One possible explanation is that your B_folder contains more files than pylance can handle in a workspace at once, while the C_folder does not. I was having a similar problem where pylance wouldn't work and then eventually a popup would inform me that pylance had crashed, but the problem only occurred in specific directories. It turned out the problem was that one of the folders in my workspace contained too many files for pylance to analyze, even though I hadn't opened anything in that folder.
In the workspace settings search python.analysis.exclude
and type in the names of files, file types, and/or folders that pylance should exclude from its analysis. Then close out of vscode and reopen it.
Upvotes: 0
Reputation: 9427
If you ensure that you have set python language server like below:
{
"python.languageServer": "Pylance"
}
A possible solution which you didn't try is to reset your python interpreter by using shortcuts Ctrl+Shift+P and type "Python: Select Interpreter".
Upvotes: 1