pylance-release
pylance-release copied to clipboard
Features break when editing certain files
Environment data
- Language Server version: v2024.3.2
- OS and version: Windows_NT x64 10.0.14393 (also occurs on RHEL 8 machine)
- Python version (& distribution if applicable, e.g. Anaconda): 3.11.2
Result of "Help: Start Extension Bisect": Pylance extension Problem Summary: Editing certain files in any way breaks Pylance features for that file
Expected behavior
I expect to be able to edit my files and have syntax highlighting, hover hints, refactoring, etc. function as intended.
Actual behavior
When editing certain files, syntax highlighting and hints break. They behave as though the file has not been edited since VS Code was last loaded, despite this not being the case. Problem is demonstrated in the pictures below:
Figure 1: File Without Edits
I then decide to add in the new function, test_func
. As you can see in the picture below, all highlighting and hints following this change break. Hovering over anything in an edited line behaves as it did before changes were made.
Figure 2: File With Edits
Logs
Things I have tried
Action: Restarting VS Code / Calling reload command Result: Pylance "fixes" itself and functions as expected until you edit anything, then the problem returns
Action: Disable all extensions Result: No problem because, obviously, the bug has to do with Pylance's features.
Action: Disable all extensions, except Pylance and its dependencies Result: Problem persists
Action: Rename the problem file Result: File can be freely edited with Pylance features working. The moment the filename is returned to its original, all the problems return if the file has been edited in any way since program restart.
Action: Duplicate workspace (File > Duplicate Workspace) Result: File can be freely edited with Pylance features working
This issue does not seem to have any rhyme or reason in what causes it. I have multiple files throughout my projects and most of them have no issues, but then certain files will suddenly start doing this. Once they "get the bug", it's there forever unless I create an entirely new workspace. Over time, that workspace develops its own new set of "problem files".
My problem seems a bit similar to this one opened for VS Code here, but with some key differences:
- My issue persists with all extensions disabled, excluding Pylance
- Removing the changes does "fix" the problem
- Their problem is with Java, so obviously cannot be Pylance related
Any help would be greatly appreciated!
Thanks for the issue. It looks like there's something else modifying the file after you edit it. We get this in the log at the very end:
2024-03-26 07:59:17.616 [info] [Info - 7:59:17 AM] (12428) SourceFile: Received fs event 'change' for path 'e:\projects\code\PROJECT\PROJECTcore\PROJECTcore\support\userprompts.py'
2024-03-26 07:59:17.617 [info] [Info - 7:59:17 AM] (12428) SourceFile: Received fs event 'change' for path 'e:\projects\code\PROJECT\PROJECTcore\PROJECTcore\support\userprompts.py'
Is there another process modifying this file? Like maybe a format on save?
What happens if you delete all of the code in the file and then say add something like:
import sys
sys.
Do completions work after the sys.
? I'm trying to see if we think the file isn't getting any change notifications.
Okay, it does seem like format on save might be causing this issue. Typically I have this setting enabled, but after disabling it and restarting VS Code the problem seems to have gone away (for now anyway)
We should still work in that case though. Hmm. I wonder if one of your formatters is saving the file outside of using VS code APIs. Although you said you repro'd it with just Pylance enabled? So just VS code would be doing the edits then.
I'm trying the same thing myself and not hitting a problem, but it might be timing dependent.
Can you upload your settings.json (well the old settings)?
The problem came back not long after it went away. I have kept the "editor.formatOnSave"
as false, but I did re-enable all my other extensions. Since I've seen the problem with just Pylance enabled, I don't think they are playing a role. If needed, I can disable them again, but restarting VS Code does effect the behavior of this bug.
I'm seeing the problem in a few files now. Here is an example of when I've added import os
. All code below it highlights incorrectly and the suggestions for os.
are not accurate.
Including current settings, which are identical to my initial settings except for format on save now being false. Also including a new log. The file I'm editing in the picture above is core.py and unlike in the previous log, I am not seeing an fs event 'change'
being logged twice.
User Settings: settings.json Language Server Log: 202403027_Python Language Server.log
The change event may be a red herring. I get them too but the colorization works fine for me (using your settings)
Can you share your project? Without a repro, I don't think logging is going to be enough to figure out what's happening.
I'm having a very similar (likely the same) issue. In my case, it only effects files in one specific folder/repo (although it does this regardless of whether I open it in its own workspace, or in the same workspace as other folders, which remain unaffected). I could share my project although I would prefer to do so privately for the time being.
Hey @rchiodo, this issue might need further attention.
@jocropsey, you can help us out by closing this issue if the problem no longer exists, or adding more information.
@malcolmsailor if you still want to share your project, you can e-mail it to me directly. My e-mail address is the same as my github id at microsoft.com.
@malcolmsailor if you still want to share your project, you can e-mail it to me directly. My e-mail address is the same as my github id at microsoft.com.
OK, sending an email!
Thanks for the e-mail. Unfortunately I can't reproduce even with your example project. Although maybe it's a timing related issue as I couldn't use the extra paths you had set (they pointed to a google drive).
It might be that the language server is just busy? So busy that it doesn't have a chance to respond to anything. This should be detectable by checking if there's any output in the Python Language Server
log after you type in a file. It should cause analysis to run on the file being typed in.
For example, I get this as soon as I type in a file (after setting python.analysis.logLevel
to Trace
):
2024-05-08 09:43:55.164 [info] (28464) [FG] parsing: file:///c%3A/Users/rchiodo/source/testing/music_df/music_df/add_feature.py (20ms)
2024-05-08 09:43:55.164 [info] (28464) [FG] binding: file:///c%3A/Users/rchiodo/source/testing/music_df/music_df/add_feature.py (6ms)
This issue has been closed automatically because it needs more information and has not had recent activity. If the issue still persists, please reopen with the information requested. Thanks.