Files randomly break in editor when saved in VS Code

Hi, I recently switched to Visual Studio Code as my code editor, and have been loving it. However, after I started to use it for a real project, I have this very annoying and potentially project-breaking bug that appears every 3rd or 4th or so time I save a file in VS Code. Screenshot after bug appears:

“Main” is a “.cs” (monobehavior) file attached to the “Main” game object in the scene. What happened here, is that I was working on Main.cs within VS Code, then saved that file with ctrl+s, returned to the Unity editor, and suddenly the script is no longer recognized by Unity. As a result, my “Main” game object causes the two warnings in the screenshot, and the errors keep popping up as long as I have Main.cs selected in the Assets view. Here’s a screenshot of the game object where you can see the script being reported as missing:

If I double click Main.cs, it still sends me to Main.cs in VS Code, so the file still exists. It just seems like the Unity editor lost some kind of connection. This is also the case after restarting the editor and VS Code. I even tried creating a new clean project and copying over all my files via text, but it still happens.

As mentioned, this issue has happened to me about every 3rd or 4th time I save or so, seemingly randomly. It has happened to both my “.cs” files and “.compute” compute shader files. How I’ve dealt with it so far, is that whenever it happens, I copy all the content of the file to the clipboard, then delete the unrecognized file within the Assets view in the Unity editor, then create a new asset of the same type, and then paste the content back in there. This also means I have to go back into my game object and drag in all the references into the inspector again, because they are all lost. In my case, it’s just one game object with 4 references to drag in, but it’s still very tedious to do, especially since I have to do it about every 10-15 minutes or so. I have done this process very many times now.

I have tried disabling all my extensions within VS Code, as well as deleting the “.vscode” folder in the project directory, and installing the latest stable Unity version, but none of that has fixed it. I couldn’t find anyone else that have had this problem, so I’m posting a thread here. I could probably file a bug report, but I have a feeling that would take a long time to resolve, especially since it seems like a problem that might only happen to some people.

Do any of you have ideas for things I could try to get this working?

Thank you.

Are you messing with the meta files?

I did add a filter to hide meta-files in my VS code project view when setting up VS code, to avoid all the littering of meta-files in the project view. But I removed this filter while trying to fix the issue and it still happens. Maybe the act of having once had the filter enabled persists in Unity as a bug somehow? Are there any registry files or the like I can delete maybe?