dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 675 forks source link

Intellisense cross-talk between projects which copy (but don't use in compilation) each others' source files. #5258

Closed quassnoi closed 4 days ago

quassnoi commented 2 years ago

Issue Description

omnisharp-intellisense-bug.tar.gz

In the solution folder, there are two projects: consumer (an xUnit test suite) and source (a classlib project).

Consumer copies *.cs files from source into its output folder on build, with a custom task.

This is a minimal reproducible example of the problem, but in my original project consumer is a unit test suite for a Roslyn analyzer, and source has the set of files I'm running the tests on. I prefer to keep them in a project because I can auto-format them, run syntax checks etc., but conceptually, source is just a source of data for unit tests, the data items being C# course code.

source is not a part of the solution and doesn't produce any artifacts.

Since source is not a part of compilation, I would expect that Intellisense would not look into source files while analyzing consumer.

However, it's not the case. One of the files in source redefines XUnit.FactAttribute and Intellisense is complaining about it, even though consumer is not using this file in compilation.

The problem only affects Intellisense. dotnet build doesn't produce any warnings.

This only happens if there is a solution file in the project. If I remove the solution file, the problem goes away.

If I go to consumer.csproj and remove the custom task which copies the files from source on build, the problem goes away as well.

Steps to Reproduce

  1. Open the attached solution in VSCode
  2. Run dotnet build. Observe that there are no errors or warnings on build.
  3. Open the Problems tab in VSCode

Expected Behavior

No problems shown

Actual Behavior

[{
    "resource": "/home/********/projects/omnisharp-intellisense-bug/consumer/ConsumerTest.cs",
    "owner": "csharp",
    "code": "CS0436",
    "severity": 4,
    "message": "Тип \"FactAttribute\" в \"/home/********/projects/omnisharp-intellisense-bug/source/SourceTest.cs\" конфликтует с импортированным типом \"FactAttribute\" в \"xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c\". Используется тип, определенный в \"/home/********/projects/omnisharp-intellisense-bug/source/SourceTest.cs\". [consumer]",
    "source": "csharp",
    "startLineNumber": 7,
    "startColumn": 6,
    "endLineNumber": 7,
    "endColumn": 10
},{
    "resource": "/home/********/projects/omnisharp-intellisense-bug/source/SourceTest.cs",
    "owner": "csharp",
    "code": "CS0436",
    "severity": 4,
    "message": "Тип \"FactAttribute\" в \"/home/********/projects/omnisharp-intellisense-bug/source/SourceTest.cs\" конфликтует с импортированным типом \"FactAttribute\" в \"xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c\". Используется тип, определенный в \"/home/********/projects/omnisharp-intellisense-bug/source/SourceTest.cs\". [consumer]",
    "source": "csharp",
    "startLineNumber": 8,
    "startColumn": 10,
    "endLineNumber": 8,
    "endColumn": 14
}]

Logs

OmniSharp log

``` Starting OmniSharp server at 07.06.2022, 21:25:57 Target: /home/********/projects/omnisharp-intellisense-bug/omnisharp-intellisense-bug.sln OmniSharp server started with .NET 6.0.300 . Path: /home/********/.vscode-server/extensions/ms-dotnettools.csharp-1.25.0-linux-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 8988 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Unknown 0.0 (Unknown) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: .NET Core SDK 6.0.300 17.2.0 - "/usr/share/dotnet/sdk/6.0.300/" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 6.0.300 17.2.0 - "/usr/share/dotnet/sdk/6.0.300/" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in '/home/********/projects/omnisharp-intellisense-bug/omnisharp-intellisense-bug.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/********/projects/omnisharp-intellisense-bug/consumer/consumer.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/home/********/projects/omnisharp-intellisense-bug'. [info]: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/home/********/projects/omnisharp-intellisense-bug' on host 8869. [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/********/projects/omnisharp-intellisense-bug/consumer/consumer.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/********/projects/omnisharp-intellisense-bug/consumer/consumer.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/home/********/projects/omnisharp-intellisense-bug/consumer/consumer.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: consumer [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 5. Received response for /findusages but could not find request. Received response for /findusages but could not find request. Received response for /findusages but could not find request. Received response for /findusages but could not find request. Received response for /v2/getcodeactions but could not find request. Received response for /v2/getcodeactions but could not find request. ```

C# log

No output

Environment information

VSCode version: 1.67.2 C# Extension: 1.25.0

Mono Information There is a problem with running OmniSharp on mono: Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Dotnet Information Пакет SDK для .NET (отражающий любой global.json): Version: 6.0.300 Commit: 8473146e7d Среда выполнения: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /usr/share/dotnet/sdk/6.0.300/ Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6 .NET SDKs installed: 6.0.300 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [/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.25.0| |dotnet-test-explorer|formulahendry|0.7.7| |EditorConfig|EditorConfig|0.16.4| |xml|DotJoshJohnson|2.5.1|;
JoeRobich commented 2 years ago

@quassnoi The SourceTest.cs file is being opened as a transient file in the miscellaneous workspace. You would see the following in your log if the LogLevel was set to trace:

[dbug]: OmniSharp.Roslyn.BufferManager
        Adding transient file for /Users/joeyrobichaud/Downloads/omnisharp-intellisense-bug/source/SourceTest.cs

This workspace has a fairly small core set of references that are used to provide language services in the editor. It just happens that xunit is one of the references.

quassnoi commented 2 years ago

@quassnoi The SourceTest.cs file is being opened as a transient file in the miscellaneous workspace. You would see the following in your log if the LogLevel was set to trace:

[dbug]: OmniSharp.Roslyn.BufferManager
        Adding transient file for /Users/joeyrobichaud/Downloads/omnisharp-intellisense-bug/source/SourceTest.cs

This workspace has a fairly small core set of references that are used to provide language services in the editor. It just happens that xunit is one of the references.

I must admit I'm not intimately familiar with the inner workings of OmniSharp, but the Intellisense warning goes away if I comment out the <ItemGroup> in consumer.csproj and restart the extension.

The log entry for "adding transient file" is still there when I do that.

JoeRobich commented 4 days ago

A lot has changed with O# project loading since this issue was opened. If you are still having problems, please open a new issue at https://github.com/omnisharp/omnisharp-roslyn/issues