Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Intellisense broke #329

Closed
CallMeTheWolf opened this issue Aug 5, 2023 · 63 comments
Closed

[BUG] Intellisense broke #329

CallMeTheWolf opened this issue Aug 5, 2023 · 63 comments
Assignees
Labels
area-unity Unity support bug Something isn't working

Comments

@CallMeTheWolf
Copy link

Describe the Issue

Intellisense is not picking up anything from Unity variables/methods. It worked prior to installing the new extension. The problem began when switching to Microsoft Unity extension. A few examples are provided.

image

image

Thank you for your time and assistance.

Steps To Reproduce

  1. Install Windows Unity Extension v0.9.0
  2. Login for C# Dev Kit
  3. Close VS Code
  4. Update VS Editor in Unity
  5. Select VS Code under preferences in Unity
  6. Generate .csproj files
  7. Open script in unity
  8. Sigh in defeat

Expected Behavior

Intellisense to pick up Unity Variables and functions. When typing the intellisense populate with options used by unity. Colors change and when hovering over a variable vscode gives the tooltip.

Environment Information

  • OS: Windows 11 22H2
  • VSCode v1.81.0
  • Tried Unity 2022.3.5f1 and 2022.3.6f1
  • Visual Studio Editor v2.0.20
  • .Net 7.0.306
    image

Extensions:

  • C# Dev Kit v0.4.2
  • Microsoft Unity v0.9.0
  • C# v2.0.328
@CallMeTheWolf CallMeTheWolf added the bug Something isn't working label Aug 5, 2023
@microsoft-issue-labeler microsoft-issue-labeler bot added the area-project Project load, Solution Explorer label Aug 5, 2023
@newUser483
Copy link

newUser483 commented Aug 5, 2023

is your vscode status bar show the vscode keep processing workspace in background?
aaaa
i think i meet the same issue as you
#326

@lc-spxl
Copy link

lc-spxl commented Aug 5, 2023

Hi from ubuntu: Projects in bar spinning endless and no autocomplete. Thanks

@jbevain jbevain added the area-unity Unity support label Aug 5, 2023
@976047167
Copy link

976047167 commented Aug 5, 2023

same .this is my log
image
image

@CallMeTheWolf
Copy link
Author

image

image

image

@CallMeTheWolf
Copy link
Author

I did not mean to close the ticket, was a misclick. But I am not showing an infinite load like others, but it does look like mine is stuck creating a server.

image

@cacheflowe
Copy link

I did not mean to close the ticket, was a misclick. But I am not showing an infinite load like others, but it does look like mine is stuck creating a server.

image

I'm having this same issue - my output log stops at Starting Server..., and I have no Intellisense for Unity libraries. I've updated Unity's Visual Studio package to 2.0.20 as instructed, and removed all previous Unity/C#-related extensions in VSCode, then reinstalled the new official Unity/MS package and dependencies. This is happening on both Mac & PC for me.

@jbevain
Copy link
Member

jbevain commented Aug 5, 2023

Hi folks,

Thanks for filling this issue. Looks like a few of you are facing this issue with our preview, hopefully you all share a common root cause that we can diagnose and fix promptly. We haven't seen this happening, so it will take some investigation.

For what it's worth, while “it works on my machine”, the C# output for me is similar to yours:

C# output

A few questions:

  • Do you see any issue or exception in Unity that could be triggered by our project generation?

  • In your Unity project folder, do you see the .sln and .csproj that our package should generate? In Unity's preferences, External Tools, could you do Regenerate project files just in case? Do the .csproj and .sln look weird?

External Tools
  • There are other Output categories, like C# Dev Kit, C# LSP Trace Logs. Do any of those have any information?

  • What happens if you use the VS Code command .NET Open Solution? Or .NET Close Solution then .NET Open Solution? Or .NET Restart Language Server?

@jbevain
Copy link
Member

jbevain commented Aug 5, 2023

Also from #333 we've learned that having the Unity Package Netcode for Entities crashes the Language Server Protocol providing code completion.

@lc-spxl
Copy link

lc-spxl commented Aug 5, 2023

Tried regenerating the sln files from Unity also adding those as you shared.

Relevant logging only from C# tap that outputs Starting server... .

Projects keep spinning.

image

.NET open / close projects does nothing in my editor

Another note, closing and reopening the editor, ask me to reinstall the Unity package ...

@newUser483
Copy link

newUser483 commented Aug 5, 2023

Do you see any issue or exception in Unity that could be triggered by our project generation?
i am not sure but unity can successfully regenerate project files and open c# project in vscode

In your Unity project folder, do you see the .sln and .csproj that our package should generate? In Unity's preferences, External Tools, could you do Regenerate project files just in case? Do the .csproj and .sln look weird?
the .sln shows it is "Microsoft Visual Studio Solution File, Format Version 12.00"

There are other Output categories, like C# Dev Kit, C# LSP Trace Logs. Do any of those have any information?
c# dev kit:
Starting Spawn .NET server...
Starting Open a solution...
Starting Open a solution with environment service...
Starting Clear environment...
.NET server started and IPC established in 2302ms
Completed Spawn .NET server (2326ms)
Completed Clear environment (2877ms)
Completed Open a solution with environment service (2926ms)
Starting Restore solution...
Completed Open a solution (2944ms)
Completed Restore solution (2329ms)

C# lsp trace log: (i install other extensions back after i failed to configure my vscode so i filter them with c#)
Extension vscode.csharp does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.csdevkit does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.csharp does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.vscode-dotnet-runtime does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.vscodeintellicode-csharp does not contribute csharpExtensionLoadPaths
Extension visualstudiotoolsforunity.vstuc does not contribute csharpExtensionLoadPaths
c# dev kit test explorer
Created Test Controller
Using vstest from dotnet sdk in [C:\Program Files (x86)\dotnet\sdk\7.0.306].
Initialized Test Explorer Server [16452]
Test Store Folder: c:\Users\\AppData\Roaming\Code\User\workspaceStorage\\ms-dotnettools.csdevkit
Test data store opened in 0.010 sec.
Initialized project system provider.

What happens if you use the VS Code command .NET Open Solution? Or .NET Close Solution then .NET Open Solution? Or .NET Restart Language Server
Trying

@cacheflowe
Copy link

cacheflowe commented Aug 5, 2023

Thank you for looking @jbevain !

I didn't find anything odd about my project files, and everything else works as it should.

I did just run .NET Open Solution from the command palette, and that brought back Intellisense recognition of Unity library definitions! However, it died shortly after that. I think I had changed something in VSCode settings.json.

After more fiddling, I ran .NET Clean, then .NET Open Solution, and now it's working again, for now 😱 It took a little while for things to rebuild.

@CallMeTheWolf
Copy link
Author

CallMeTheWolf commented Aug 5, 2023

I have tried regenerating the project files many times to no avail. .Net Clean doesnt appear to do anything and I do not see anything populate on any of the logs. I do get this error though when running .Net Open Solution, perhaps something wrong with the .sln? The files themselves do not look weird on first glance, showing VisualStudio.Launcher.csproj.15.0 and the .sln also appears to show 15

image

@CallMeTheWolf
Copy link
Author

CallMeTheWolf commented Aug 5, 2023

Tried regenerating the sln files from Unity also adding those as you shared.

Relevant logging only from C# tap that outputs Starting server... .

Projects keep spinning.

image

.NET open / close projects does nothing in my editor

Another note, closing and reopening the editor, ask me to reinstall the Unity package ...

I had that same issue initially with the extension where it kept deleting itself and everytime vscode opened it asked to install it.
What fixed it for me was to turn off settings sync, go into the vscode folder and delete the extensions.json for the saved extensions, and let vscode repopulate it then downloading it again.

@newUser483
Copy link

tried .net close->open or clean->open, but my vscode still keep processing workspace in background

@cacheflowe
Copy link

I fixed on my PC earlier (after running in circles), and just fixed it on my Mac with a much more focused set of steps. I noticed some error messages about my project files being out of date while I was doing this.

In Unity

  • Manually update the Visual Studio Editor package in Unity Package Manager. Ignore the VS Code package, even though we're wanting our VS Code IDE to work properly. It sounds like that one's getting deprectad.
    • Click on the Visual Studio Editor package
    • Click the "Unlock" button in upper-right
    • Click "Version History"
    • Update to 2.0.20
  • Go to Unity's Preferences section: External Tools
    • Choose Visual Studio Code as the External Script Editor
    • Click "Regenerate Project Files"

In VS Code

  • Update VSCode extensions to pre-release versions:
    • C# Dev Kit v0.4.2
    • C# v2.0.328
  • Back in VS Code, run the following commands from the command palette
    • .NET Clean
    • .NET Open Solution
    • Maybe try .NET Restart Language Server too

Hopefully this helps someone!

@CallMeTheWolf
Copy link
Author

I fixed on my PC earlier (after running in circles), and just fixed it on my Mac with a much more focused set of steps. I noticed some error messages about my project files being out of date while I was doing this.

In Unity

  • Manually update the Visual Studio Editor package in Unity Package Manager. Ignore the VS Code package, even though we're wanting our VS Code IDE to work properly. It sounds like that one's getting deprectad.

    • Click on the Visual Studio Editor package
    • Click the "Unlock" button in upper-right
    • Click "Version History"
    • Update to 2.0.20
  • Go to Unity's Preferences section: External Tools

    • Choose Visual Studio Code as the External Script Editor
    • Click "Regenerate Project Files"

In VS Code

  • Update VSCode extensions to pre-release versions:

    • C# Dev Kit v0.4.2
    • C# v2.0.328
  • Back in VS Code, run the following commands from the command palette

    • .NET Clean
    • .NET Open Solution
    • Maybe try .NET Restart Language Server too

Hopefully this helps someone!

I'm glad you got your project working and appreciate the help! In my case though the steps didn't change anything for my projects. I tried deleting all the .csproj and the .sln, the project manager visual studio extension, and then restarted the process again. It still is stuck at the same spot of the posts above, no intellisense, server looks like it starts ok, no issues in the other consoles, I get no errors or anything strange in Unity, and I get the error that no solution is found when .Net Open Solution is run. Thanks y'all for the helpful leads.

@newUser483
Copy link

Do you guys have sdk installed in program(x86)?

@CallMeTheWolf
Copy link
Author

image

@newUser483
Copy link

my vscode keep stuck on this even i close solution, restart language server or open solution
aaaa

@lc-spxl
Copy link

lc-spxl commented Aug 6, 2023

I tried to run the language server with debug logging and when moving hover UnityEngine it says no reference.

The Solution Explorer tab shows the sub projects that looks ok. However, trying to expand them result in the usual endless spinner

image

Where could I see the logging of the Projects loading process ?

Thx

@nkoudelia
Copy link

nkoudelia commented Aug 6, 2023

For me adding the .vscode/settings.json with a path to the solution file fixes the issue of broken intellisense:

{
    "dotnet.defaultSolution": "path/to/my/solution/file.sln"
}

But most of my projects are simple console apps without a solution file... what should I do then?

And by the way in my case this is not related to Unity - just plain C# console apps.

@CallMeTheWolf
Copy link
Author

CallMeTheWolf commented Aug 7, 2023

@nkoudelia I appreciate the insight, was there anything else you did besides modify the settings.json? I was not able to get the fix to work unfortunately. I still get the same error, but it populates in the console immediately rather than after running .Net open solution:

image

It's like vscode is not correctly loading the project files and/or solution. Is there anything amiss from this .csproj file that may be causing the issue? I omitted the sections following the pictured that have all the Reference Include's.

image

-*.sln
Microsoft Visual Studio Solution File, Format Version 12.00
Visual Studio 15

C# Dev Kit
image

C# LSP Trace Logs
image
image

@nkoudelia
Copy link

nkoudelia commented Aug 7, 2023

Nope, not doing anything else. Here are my steps using the ms-dotnettools.csharp extension version v2.0.328:

  1. Create an empty console app
    image

  2. Open VS Code and see broken intellisense
    image

  3. Create a .sln file and add .vscode/settings.json.
    image
    image

  4. Ctrl+Shift+P & Reload Window - intellisense works now
    image

@lc-spxl
Copy link

lc-spxl commented Aug 7, 2023

Unity extension add it by its own. However is not enough to have intellisense to work. Seems to me there is something not working properly in the Projects parts as it fails after a while loading subprojects

@MrRadian
Copy link

MrRadian commented Aug 8, 2023

Maybe remove all unity plugins and install it again
Try to remove folder .vscode and .config/vscode folders. This will remove all extensions and potencial bug settings

@sailro
Copy link
Member

sailro commented Aug 12, 2023

Maybe remove all unity plugins and install it again Try to remove folder .vscode and .config/vscode folders. This will remove all extensions and potencial bug settings

Be careful removing your .vscode folder, because we store dedicated settings and launch profiles. At least regenerate project files from Unity to restore default settings/profiles after deletion.

@sailro
Copy link
Member

sailro commented Aug 12, 2023

I'm trying to summarize the thread with the following:

1- Make sure you have the proper VSCode prerequisites:

  • C# Dev Kit v0.4.2+
  • Microsoft Unity v0.9.0+
  • C# v2.0.328+

2- Make sure you have the proper Unity prerequisites:

  • Visual Studio Editor Package 2.0.20+
  • VSCode should be selected as your preferred external editor. You should select an entry similar to Visual Studio Code [[Version]].
  • You can try to regenerate project files from Unity / Preferences / External Tools
  • Please note that Visual Studio >Code< Editor package is a legacy package that is not maintained anymore. The Visual Studio Editor package now handles the entire family of Visual Studio products (VS, VSMac, VSCode).

3- Make sure C# Dev Kit is not displaying any error message:

  • regarding .NET runtime acquisition (perhaps you need to bump the timeout: In VSCode, go to File/Preferences/Settings, Extension/.NET Install Tool and bump install timeout value to 1200).
  • regarding .NET SDK not found (install the recommended SDK version).
  • regarding unsupported projects (check Unity prerequisites, select VSCode as your external editor and regenerate project files from Unity)

4- Inspect your .vscode/settings.json

  • you should have a "dotnet.defaultSolution" pointing to your solution file.
  • you can even delete the .vscode folder then try to regenerate project files from Unity to restore defaults.
  • back in VS Code, you can try to run the following commands from the command palette: .NET Clean, .NET Open Solution, .NET Restart Language Server.

5- Miscellaneous

  • We have found that Unity Package Netcode for Entities crashes the Language Server Protocol providing code completion

@inancelal
Copy link

I was doing fine since last week, I am having this problem as you can see in the pictures, i guess something updated but idk what. If someone would tell me how to figure out i would be thankful.

Screenshot 2023-08-12 at 6 01 57 PM Screenshot 2023-08-12 at 6 02 16 PM Screenshot 2023-08-12 at 6 02 28 PM

@sailro
Copy link
Member

sailro commented Aug 12, 2023

I was doing fine since last week, I am having this problem as you can see in the pictures, i guess something updated but idk what. If someone would tell me how to figure out i would be thankful.

Screenshot 2023-08-12 at 6 01 57 PM Screenshot 2023-08-12 at 6 02 16 PM Screenshot 2023-08-12 at 6 02 28 PM

I think the solution is here (section 2):
#329 (comment)

I guess you are not using the latest VS Editor package v2.0.20. Please update using Unity Package Manager.

@gingaramo
Copy link

I had the same problem of not getting code navigation and completion working, I followed all the steps in comment #329 plus a few dozen other SO and issue discussions too, spending a few hours trying everything from re-installing Unity VSCode, trying different extensions versions, etc.

Finally arrived to a workaround that worked for my issue.

I had the problem of infinite load, and of project not loading without helpful messages. Upon expanding the "Solution Explorer" tab I saw "A compatible .NET SDK was not found" and that ended up taking me to a few more issues discussed in the past month, with finally a workaround that worked.

image

Hope that helps you.

@inancelal
Copy link

I was doing fine since last week, I am having this problem as you can see in the pictures, i guess something updated but idk what. If someone would tell me how to figure out i would be thankful.
Screenshot 2023-08-12 at 6 01 57 PM Screenshot 2023-08-12 at 6 02 16 PM Screenshot 2023-08-12 at 6 02 28 PM

I think the solution is here (section 2): #329 (comment)

I guess you are not using the latest VS Editor package v2.0.20. Please update using Unity Package Manager.

I did everything on section 2 except version of editor, I updated Editor package v2.0.20 but it did not fix anything and now I am having this error:
Screenshot 2023-08-14 at 1 30 36 PM
Screenshot 2023-08-14 at 1 30 13 PM

@z79422957
Copy link

Encountered the same problem as CallMeTheWolf

@sailro
Copy link
Member

sailro commented Aug 15, 2023

I was doing fine since last week, I am having this problem as you can see in the pictures, i guess something updated but idk what. If someone would tell me how to figure out i would be thankful.
Screenshot 2023-08-12 at 6 01 57 PM Screenshot 2023-08-12 at 6 02 16 PM Screenshot 2023-08-12 at 6 02 28 PM

I think the solution is here (section 2): #329 (comment)
I guess you are not using the latest VS Editor package v2.0.20. Please update using Unity Package Manager.

I did everything on section 2 except version of editor, I updated Editor package v2.0.20 but it did not fix anything and now I am having this error: Screenshot 2023-08-14 at 1 30 36 PM Screenshot 2023-08-14 at 1 30 13 PM

It seems there was an issue on the Unity side when fetching the package.

Could you try to close Unity, then delete your Library/PackageCache folder ? this will invalidate and rebuild the package cache when re-opening Unity.

If you are still hitting the issue after this, we recommend to remove the meta-package Engineering and re-add necessary package as standalone ones.

@inancelal
Copy link

I was doing fine since last week, I am having this problem as you can see in the pictures, i guess something updated but idk what. If someone would tell me how to figure out i would be thankful.
Screenshot 2023-08-12 at 6 01 57 PM Screenshot 2023-08-12 at 6 02 16 PM Screenshot 2023-08-12 at 6 02 28 PM

I think the solution is here (section 2): #329 (comment)
I guess you are not using the latest VS Editor package v2.0.20. Please update using Unity Package Manager.

I did everything on section 2 except version of editor, I updated Editor package v2.0.20 but it did not fix anything and now I am having this error: Screenshot 2023-08-14 at 1 30 36 PM Screenshot 2023-08-14 at 1 30 13 PM

It seems there was an issue on the Unity side when fetching the package.

Could you try to close Unity, then delete your Library/PackageCache folder ? this will invalidate and rebuild the package cache when re-opening Unity.

If you are still hitting the issue after this, we recommend to remove the meta-package Engineering and re-add necessary package as standalone ones.

Even if I delete one project's Library/PackageCache folder, problem is happening in all other unity projects even in new projects. I dont know what you mean by saying "remove the meta-package Engineering and re-add necessary package as standalone ones" could you explain with more details pls ?

@Wollbobaggins
Copy link

Wollbobaggins commented Aug 15, 2023

Maddening... ugh sigh. VSCode was working fine up until today when I installed the Microsoft Unity extension. I have an infinite server load problem and so far nothing has worked from above.

UPDATE:

Finally got it working on both MacOS 12 and Windows 10. My setup was similar to @cacheflowe, so I'll repeat some of his steps.

In Unity (2021.3.14f1 was my version for both Mac and Windows):

  1. Manually update the Visual Studio Editor package in Unity Package Manager to 2.0.20 (or maybe later). As @cacheflowe mentioned, the Visual Studio Code Editor package is not important here and it can be deleted or added (make sure Unity compiles at this point, if there are any errors address them now; otherwise, the Visual Studio Editor package will not properly compile)
  2. Go to Unity's Preferences section: External Tools, set your version of Visual Studio Code as the External Script Editor, then Click Regenerate Project Files
  3. (from here I went to Assets -> Open C# Project to open VSCode BUT I think this step is unnecessary)

In VS Code I downloaded the following (after removing all other extensions):

  1. Unity v0.9.0 or later
  2. C# v2.0.328 or later (auto installed by Unity)
  3. C# Dev Kit v0.3.21 or later (auto installed by Unity)
  4. .NET Install Tool for Extension Authors v1.7.0 or later (auto installed by Unity)
  5. IntelliCode for C# Dev Kit v0.1.26 or later (auto installed by Unity)

Lastly in VS Code:

  1. I deleted/commented out User Settings and Workspace Settings that were suspicious (I think this was the main issue in my case) EDIT: See UPDATE 2 for more info
  2. run the following commands from the command palette (Ctrl+Shift+P)
  3. .NET Clean
  4. .NET Open Solution
  5. .NET Restart Language Server

To my surprise it worked (intellisense finally!) on both Mac and Windows by this point. Time to reconfigure both my settings files now...

UPDATE 2: The issue was specifically hiding the .sln file from the Solution Explorer Window within my Settings files.

"files.exclude": {
... list of excluded files ....
"**/*.sln": true, // <- remove this line
... other excluded files ....
}

This sounds like an obvious mistake but confusingly it wasn't an issue in the past. Anyway, everything seems to work now.

@z79422957
Copy link

I tested, Temporary resolution of no code prompts and intelligent perception issues:

I have annotated all of the user's settings. json.

  1. Close vscode, open the script from the Unity editor, and wait for files such as SLN to load

  2. Switch to other scripts to refresh code prompts and intelligent perception normally (each time you open vscode for the first time, you need to operate it once)

  3. I have uncommented all of the user's settings. json.

  4. Complete.

@boxedworks
Copy link

boxedworks commented Aug 21, 2023

For me, my VSCode had the wrong solution selected after installing the new Microsoft Unity extension. I think this is due to my project including code from other projects in it.

So running from the command palette:
.NET Open Solution

Then I had 3 selections to choose from for the solution. So I chose the one for my project and after it loaded for a bit, it is now working.

@jbevain
Copy link
Member

jbevain commented Aug 22, 2023

@Wollbobaggins thanks for taking the time to report how you fixed your issue. Today we're simply generating a new .vscode/settings.json if you don't have one already, and if you have one we're not touching it.

Now we're thinking about adding a step that looks at an existing .vscode/settings.json to remove the .sln file exclusion if there's one.

@alanbork
Copy link

alanbork commented Sep 8, 2023

I'm not sure what to expect here - there's tons of junk in the autocomplete, such as all the floats that you can write with 3 digits. does this count as "working"? Also, all the variables, classes, etc, are listed as type "abc" which isn't super helpful.

@sailro
Copy link
Member

sailro commented Sep 14, 2023

We added a bunch of setting fixes in the VS Editor Package 2.0.21, this should help for those still hitting issues here. Please bump your package version in Unity package manager.

@alanbork
Copy link

We added a bunch of setting fixes in the VS Editor Package 2.0.21, this should help for those still hitting issues here. Please bump your package version in Unity package manager.

What counts as working? My first couple pages of intellisense suggestions are floating point numbers like .015f, pretty darn useless.

@jbevain
Copy link
Member

jbevain commented Sep 14, 2023

Hi,

At this point we believe the C# and C# Dev Kit have pushed a fix for the loading issue, so we're going to close this issue. Please make sure both extensions are up to date and you've followed the README of the Unity extension:

  • In Unity, you need to upgrade the Visual Studio Editor package to 2.0.20 or above (the latest is 2.0.21)
  • Select Visual Studio Code as the External Editor.
  • Regenerate Project Files

Because this issue evolved with multiple different issues, if you hit more loading issues please open a new one.

Thank you!

@jbevain jbevain closed this as completed Sep 14, 2023
@jbevain
Copy link
Member

jbevain commented Sep 14, 2023

@alanbork please open a new issue for this, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-unity Unity support bug Something isn't working
Projects
None yet
Development

No branches or pull requests