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

Omnisharp ignores code in newly added source files #4223

Closed
ManfredLange opened this issue Nov 21, 2020 · 10 comments
Closed

Omnisharp ignores code in newly added source files #4223

ManfredLange opened this issue Nov 21, 2020 · 10 comments

Comments

@ManfredLange
Copy link

ManfredLange commented Nov 21, 2020

Issue Description

Omnisharp ignores code in new files, e.g. when a file with C# code is added, no suggestions are made. This includes not making suggestions for adding appropriate using statements for class identifiers in referenced assemblies, e.g. TestFixture in package NUnit.

Steps to Reproduce

  1. Set "omnisharp.path" to "latest". At the time of writing this will install version 1.37.4-beta.61

  2. Open a folder with a C# project, e.g. a test project that references NUnit.Framework

  3. Create a new file for a class inside of a namespace, e.g. namespace Foo and class Bar. Have the implementation use a class exists in a referenced assembly, e.g. NUnit.Framework

  4. Omnisharp will not make any suggestions to add the using statement for NUnit.Framework. OmniSharp Log will have entries as follows:

    [info]: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
         Could not find document for file /app/src/Foo22Tests.cs
    

    However, the file does exist at that location.

Other things I tried:

  • Saving the file makes no difference
  • (re-)building the project or solution makes no difference
  • Restarting Omnisharp resolves the problem

Expected Behavior

Omnisharp should pick up the content of the new file. A restart of OmniSharp should not be required.

Actual Behavior

Requires frequent restart of Omnisharp server

Please let me know in case you cannot reproduce this. I'll then attempt to provide a minimal repro git repo.

Logs

OmniSharp log

Starting OmniSharp server at 11/21/2020, 12:11:31 AM Target: /app/RimuTec.Piranha.sln

OmniSharp server started.
Path: /home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/run
PID: 959

Starting OmniSharp on debian 10.0 (x64)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 16.8.0 - "/home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild/Current/Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 16.8.0 - "/home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild/Current/Bin"
CscToolExe = csc.exe
MSBuildToolsPath = /home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild/Current/Bin
CscToolPath = /home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild/Current/Bin/Roslyn
BypassFrameworkInstallChecks = true
MSBuildExtensionsPath = /home/piranha/.vscode-server/extensions/ms-dotnettools.csharp-1.23.6/.omnisharp/1.37.4-beta.61/omnisharp/.msbuild
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/app'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
Detecting projects in '/app/RimuTec.Piranha.sln'.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for '/app/src/PiranhaNH/PiranhaNH.csproj'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for '/app/src/PiranhaNH.Tests/PiranhaNH.Tests.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/app'.
info: OmniSharp.MSBuild.ProjectManager
Loading project: /app/src/PiranhaNH/PiranhaNH.csproj
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/app' on host 177.
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file '/app/src/PiranhaNH/PiranhaNH.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project '/app/src/PiranhaNH/PiranhaNH.csproj'
info: OmniSharp.MSBuild.ProjectManager
Loading project: /app/src/PiranhaNH.Tests/PiranhaNH.Tests.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file '/app/src/PiranhaNH.Tests/PiranhaNH.Tests.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project '/app/src/PiranhaNH.Tests/PiranhaNH.Tests.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: PiranhaNH
info: OmniSharp.MSBuild.ProjectManager
Update project: PiranhaNH.Tests
info: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
Solution initialized -> queue all documents for code analysis. Initial document count: 28.
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs
info: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
Could not find document for file /app/src/Foo22Tests.cs

C# log

Getting latest OmniSharp version information Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done! Installing OmniSharp Version = 1.37.4-beta.61... Platform: linux, x86_64, name=debian, version=10

Downloading package 'OmniSharp for Linux (x64), Version = 1.37.4-beta.61' (47240 KB).................... Done!
Installing package 'OmniSharp for Linux (x64), Version = 1.37.4-beta.61'

Finished

Environment information

VSCode version: 1.51.1
C# Extension: 1.23.6
OmniSharp: 1.37.4-beta.61
Host: Windows 10
Docker Desktop for Windows: 2.5.0.1
Base image: mcr.microsoft.com/dotnet/sdk:5.0

Note that this base image does not come with ps installed, Without ps restarting omnisharp-vscode is not possible. Other omnisharp-vscode commands depend on ps as well and won't work without ps.

The first few lines of the Dockerfile need to look similar to this:

FROM mcr.microsoft.com/dotnet/sdk:5.0

# Install 'ps' as it is missing from the base image and omnisharp-vscode needs it:
RUN apt-get update && \
    apt-get install -y procps

... further code omitted for brevity ...
Mono Information OmniSharp using built-in mono
Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.100 Commit: 5044b93829

Runtime Environment:
OS Name: debian
OS Version: 10
OS Platform: Linux
RID: debian.10-x64
Base Path: /usr/share/dotnet/sdk/5.0.100/

Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7

.NET SDKs installed:
5.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
csharp ms-dotnettools 1.23.6
dotnet-test-explorer formulahendry 0.7.4
EditorConfig EditorConfig 0.15.1
gitlens eamodio 11.0.2
markdown-preview-enhanced shd101wyy 0.5.13
powershell ms-vscode 2020.6.0
resourcemonitor mutantdino 1.0.7
roslynator josefpihrt-vscode 3.0.1
vscode-solution-explorer fernandoescolar 0.3.11
@ManfredLange
Copy link
Author

Another observation: Moving the new file to a different folder within the project doesn't even cause the message "Could not find document for file ...".

It appears as if certain file events are not picked up in all cases, e.g. when a new file is created or when a file is moved to a new location (which might trigger the same or a different event). I'm just guessing here as I am not familiar with the inner workings of VS Code or how extensions interact with it.

@333fred
Copy link
Member

333fred commented Nov 21, 2020

Can you give a more detailed set of repro steps? For example, I see no issues with this:

  1. dotnet new console
  2. code .
  3. Right-click the folder, add test.cs.
  4. Invoke completion. I see type completion, such as abstract, etc. I expect that you do not see such completion.

@ManfredLange
Copy link
Author

ManfredLange commented Nov 21, 2020

@333fred I'll create a minimal repro repo and provide detailed steps to reproduce.

@ManfredLange
Copy link
Author

ManfredLange commented Nov 21, 2020

@333fred A minimal repo with detailed steps to reproduce is available at https://github.com/ManfredLange/issue-201121 Steps to reproduce are in file README.md of that repo.

It appears as if OmniSharp doesn't pick up any change when a file is created, moved or deleted.

Please do let me know if you need further details.

If you still cannot reproduce this issue, please let me know as well. I'm happy to arrange a zoom call if that helps.

@333fred
Copy link
Member

333fred commented Nov 21, 2020

Looking at those steps, it seems likely it's docker-specific. I'll try to take a look sometime this weekend, but I have never used the container development model so it may take me a bit.

@ManfredLange
Copy link
Author

ManfredLange commented Nov 21, 2020

@333fred I agree.

With futher experiments I tried to eliminate elements from the picture. I tried this:

  • Redo the same experiment in a directory in the container that is not a mounted directory from the Windows filesystem (NTFS). Result: everything works like a charm
  • Redo the same experiment in a directory that mounts a directory from a distro running on WSL2. Result: everything works like a charm.

Therefore I now tend to believe that this is related to the missing notification issue of WSL2, aka "inotify". WSL2 doesn't have a solution right now for creating inotify events for Windows file systems to the Linux file system running in the container. This issue has tripped up other people as well. It has been submitted in a few places:

It has also been discussed on StackOverflow, e.g. here https://stackoverflow.com/q/64689585/411428

Microsoft themselves suggest to store the files in the same file system on the host as is used in the container. So this would mean to store in the Linux file system on Windows. For example see the note half-way down this article:

https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers

Howeve, this article does not specify in more detail how to work with a git clone, WSL2, a distro, and a Docker Container and how all of that works together. I believe I now have learned how to make this work and intend to write an article over the next few weeks that hopefully allows others avoid this problem in the first place.

The fact that WSL2 does not send inotify events to Linux file systems and that Microsoft did not provide a solution at this stage has probably caused a large number of wasted hours. Not only mine, but those of other people as well. What a shame! :-)

I think we can close this issue for now. Once I have an article with the details I intend to post a link here as well.

@ManfredLange
Copy link
Author

As promised I wrote an article that describes the details of the root cause of this problem and how to avoid it:

Article on Medium.com: "Docker Desktop on WSL2: The Problem with Mixing File Systems"

@BinarySpike
Copy link

I am getting this error for 1.23.8. I reverted to 1.23.3 and the issue is no longer experienced.

@carlossanlop
Copy link
Member

I also downgraded to 1.23.3 as a workaround. Any version above that does not work in Windows or in WSL.

@asmi24886
Copy link

You do not have to downgrade to 1.23.3 if you are using Windows.
Steps to follow:

  1. Create script in Unity.
  2. Attach script to Game Object as Component.
  3. Find Assembly-CSharp.csproj
  4. Find the first field under which your old script names are present for compilation.
  5. Add new script name.
  6. Save in Unity.
  7. Restart VS Code if required.

It should get solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants