vscode-csharp: Renaming file or creating new file breaks omnisharp lookup

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

VS Code version:

Version 1.20.1 (1.20.1)

C# Extension version:

1.14.0

Steps to reproduce

Create a file or rename a file and wait for Omnisharp to parse the file.

Expected behavior

VSCode should be able to find all existing namespace and assemblies.

Actual behavior

VSCode failed to find interfaces in the same namespace, and we can only reproduce it in current session, restarting VSCode, the issue is gone.

It seems Omnisharp somehow couldn’t recognize new file or renamed file are in the same namespace.

Screenshots

Existing file:

screen shot 2018-02-15 at 14 48 51

Create a new file with simple class name change:

screen shot 2018-02-15 at 14 48 51

Problems:

screen shot 2018-02-15 at 14 49 18

Restart or reload VSCode:

screen shot 2018-02-15 at 14 55 07

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 8
  • Comments: 39 (4 by maintainers)

Most upvoted comments

I’ve run into this problem as well with VSCode + Unity and would love a fix. I can only get it to consistently work by closing and restarting VSCode every time I create a new file.

I whipped out a small script that should fix this issue for Unity projects - https://gist.github.com/SirIntruder/5a8b0659df44f29b3538538a82313f66

I’ve tested it around a bit (Unity is at 2020.3) and it seems it works, Do tell if you encounter any problems.

Ideally, Unity should have out-of-the-box solution for this as part of vscode-editor package, I don’t see a way for omnisharp to fix this properly by itself.

I have the same problem and I’m wondering why Omnisharp doesn’t simply add the file to a csproj that covers any file close by, this would at least work for creating files in the same directory as existing files.

Visual Studio is able to add files to an open Unity solution just fine. What is keeping omnisharp from doing the same? Or is this something that should happen on vscode project management level?

I’d love to see this fix. 👍

Unfortunately, as a workaround, restarting omnisharp is not great. In a pretty small project, it takes me about 8-9 seconds to see the results in the file I’m working in, and this can happen over 20-30+ times a day when you’re making a decent amount of changes or doing some refactoring/cleanups.

Internal Tracking devdivcsef 412378

Yup, fIxing that would require Omsnisharp to be able to “read Unity’s mind”. Basically, there is code in omnisharp that takes a filePath for the new file on one hand, and list of project files on the other hand, and tries to find the most likely match. If there was a way for a plugin to be inserted at this point, it would be possible to inject Unity’s magic formula and have everything work out of the box. I don’t know much about omnisharp’s plugin architecture though, a member of omnisharp team could comment on this.

@DustinCampbell since this is a known limit, are there:

  • workaround? like a forced refresh without exiting VS Code.
  • substitute? where I can manually create .sln/csproj file, use file globbing pattern, and set VS Code to it (without affecting Unity, of course).

Basically, using VS Code with Unity means VS Code don’t have to “build” the project. I just need it to know enough about Unity and my source code so that OmniSharp can provide basic intellisense suggestions.