0

I'm sorry about the strange title but hopefully a GIF of what is happening can help. visual studio code colors stop working when I begin to edit

The issue: Whenever I load a C# script into visual studio code and begin to edit the script, the script loses its correct color coding. It loads with everything correctly up until I edit it, and as soon as I begin to edit, it loses the color. Another strange behavior that I encountered happened when I used Unity's Random.Range() function which then caused Visual Studio Code to import Systems.Numeric automatically at the top of the script.

Up until a few weeks ago I had never had any issues whatsoever. I installed an update for Visual Studio Code right around the time of this issue but other than that, everything else is the same.

I haven't been able to get much help with this issue anywhere over the past few weeks but I was able to find some leads that fixed the issue for a few minutes before breaking again.

These solutions that didn't work included

  1. a full reinstall of visual studio code (deleting all extensions, all hidden folders, and visual studio code itself)
  2. Restarting Omnisharp inside Visual Studio Code
  3. Reinstalling the Visual Studio Code packages inside the Unity Package Manager and regenerating the project files inside Unity

Solutions I haven't tried because I can't figure out how included

  1. Reverting Visual Studio Code to a past version (I can't remember which version I was on before updating and am worried I'll either go too far back or not far enough to fix the issue)

If anyone has encountered this before, has any idea on how to fix this, or could point me in a general direction for solving this issue, I would greatly appreciate it! Thanks!

additional information: Unity Editor version 202.3.18f1 Visual Studio Code version 1.81.1

What happened trying the solutions

  1. a full reinstall of visual studio code (deleting all extensions, all hidden folders, and visual studio code itself) Result: worked for a few seconds before losing all color and continuing to import libraries I did not want

  2. Restarting Omnisharp inside Visual Studio Code Result: Nothing changed, same issue as before. Would load properly then upon editing, cease working.

  3. Reinstalling the Visual Studio Code packages inside the Unity Package Manager and regenerating the project files inside Unity Result: Nothing changed, same issue as before. Would load properly then upon editing, cease working.

edit: adding the Help: About output

Version: 1.81.1 (Universal) Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794 Date: 2023-08-09T22:20:33.924Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin x64 19.6.0

cesco
  • 11
  • 3
  • duplicate I think of https://stackoverflow.com/q/76944652/11107541. still pending an answer there. I'll investigate later. – starball Aug 22 '23 at 02:04
  • @starball I appreciate the link thank you, it does seem like it could be the same issue. – cesco Aug 22 '23 at 13:53
  • currently found an inexplicable fix that has been working for a few hours so I don't want to post it as an answer BUT uninstalling every extension from "visual studio code" except for ".NET Install Tool" seems to have restored functionality to the way it was before. This includes removing all C# extensions – cesco Aug 22 '23 at 17:09
  • do you reinstall the extensions afterward? Wouldn't it be a pain to do C# development without the C# extensions? – starball Aug 22 '23 at 23:14
  • @starball added it in! I did not re-install the C# extensions and I can also confirm that the color coding issue has been temporarily resolved as well as the auto-adding "Systems" to my file issue. I have no idea why removing the C# library fixed it but now everything is back to normal for the time being. Since I can't explain why this fixed things I'm hesitant to say it is resolved but it does work right now for me – cesco Aug 23 '23 at 16:05

1 Answers1

0

I have temporarily fixed the Color Coding issue as well as the auto-filling in Systems issue. I'm not sure if this is a permanent fix, but as of now (8/23/23) this is working.

I uninstalled every Visual Studio Code extension (the C# ones as well) except for the .NET Install extension. I then quit VSCode and Unity, restarted my Unity project, went assets->open C# project, and suddenly it was working again. I ignored the "install recommended C#..." popup from Visual Studio code and I can now use Visual Studio Code with Unity just as I did before.

gif example of it working (Color coding doesn't dissapear and using functions such as Random.Range() doesn't auto import "using Systems.xyz") enter image description here

This worked for me using; Unity version 2020.3.18f1, with Visual Studio Code Editor Package version 1.2.5 Visual Studio Code version 1.81.1 (Universal)

cesco
  • 11
  • 3