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

feat: ignore diagnostics for generated code #2509

Merged
merged 31 commits into from
Aug 22, 2023

Conversation

Anakael
Copy link
Contributor

@Anakael Anakael commented Feb 26, 2023

Was described in: #2437

  1. Added logging option for logging to a file for convenient logging in neovim setup
  2. Skip diagnosing for excluded files
  3. Skip diagnosing for generated files (found by .g.cs extension or by // tag or by .editorconfig)
  4. Some small refactor for CsDiagnosticWorker's

UPD:
5) I've also dropped CsDiagnosticWorker as it seems to be strange to have two classes for the same logic. Also, this class wasn't updated for two years.

@Anakael
Copy link
Contributor Author

Anakael commented Mar 3, 2023

Ready for review now.

@Anakael
Copy link
Contributor Author

Anakael commented May 10, 2023

@dibarbet
@filipw
Any chance that PR will be reviewed? :)

@JoeRobich
Copy link
Member

JoeRobich commented May 26, 2023

Hi @Anakael, please restore the CsDiagnosticWorker. Not all users want the added overhead of running analyzers in their editor. The CsDiagnosticWorker exists to provide compiler diagnostics which are less costly.

@Anakael
Copy link
Contributor Author

Anakael commented May 30, 2023

Hi @Anakael, please restore the CsDiagnosticWorker. Not all users want the added overhead of running analyzers in their editor. The CsDiagnosticWorker exists to provide compiler diagnostics which are less costly.

I've added enableAnalyzers option to CSharpDiagnosticWorkerWithAnalyzers. With enableAnalyzers = false it CSharpDiagnosticWorkerWithAnalyzers works the same way CsDiagnosticWorker did (that is just provides diagnostics from document semantic model).

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution. I know there are a lot of developers who will appreciate this improvement. To move forward with this please move new logging option to a separate PR as that will take additional time to consider.

public Matcher BuildMatcher()
{
Matcher matcher = new();
matcher.AddIncludePatterns(new string[] { "./**/*", "./*" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could open a folder containing a project which has document links to source files which exist outside of the open folder. How can we make this work for that situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed exclude to include.
Now I can get diagnostics from documents outside of current directory.
But now there is opposite problem: documents outside of current directory can not be ignored via options :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason Matcher doesn't work well will relation pathes outside current directory.
But I don't think this is huge problem since ignoring documents outside directory of current solution is not frequent case.

@Anakael
Copy link
Contributor Author

Anakael commented Jun 1, 2023

Thank you for this contribution. I know there are a lot of developers who will appreciate this improvement. To move forward with this please move new logging option to a separate PR as that will take additional time to consider.

Done.

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears there are some failing tests. Do they pass when you run them locally?

# for testing against mono
./build.sh -T Test

# for testing against dotnet
./build.sh -T Test --use-dotnet-test

Anakael and others added 2 commits June 19, 2023 22:20
Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>
…icWorkerWithAnalyzers.cs

Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>
@Anakael
Copy link
Contributor Author

Anakael commented Jun 19, 2023

It appears there are some failing tests. Do they pass when you run them locally?

# for testing against mono
./build.sh -T Test

# for testing against dotnet
./build.sh -T Test --use-dotnet-test

Nope. Now 2 tests are failed.

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took some time to look at the errors and have a few suggestions.

I would also update the OmniSharpEnvironment.cs to always ensure the TargetDirectory contains an ending slash. Otherwise the GetRelativePath call can return some odd results.

            if (TargetDirectory[TargetDirectory.Length - 1] != Path.DirectorySeparatorChar)
            {
                TargetDirectory += Path.DirectorySeparatorChar;
            }

var documentIds = GetDocumentIdsFromPaths(documentPaths);
ImmutableArray<DocumentId> documentIds = (await Task.WhenAll(
documentPaths
.Select(docPath => _workspace.GetDocumentsFromFullProjectModelAsync(docPath))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change. When projects are loaded on demand the documents may not be part of the workspace, since it will be waiting on a design time build.

src/OmniSharp.Shared/Options/RoslynExtensionsOptions.cs Outdated Show resolved Hide resolved
@Anakael
Copy link
Contributor Author

Anakael commented Jun 20, 2023

I took some time to look at the errors and have a few suggestions.

I would also update the OmniSharpEnvironment.cs to always ensure the TargetDirectory contains an ending slash. Otherwise the GetRelativePath call can return some odd results.

            if (TargetDirectory[TargetDirectory.Length - 1] != Path.DirectorySeparatorChar)
            {
                TargetDirectory += Path.DirectorySeparatorChar;
            }

Done.

@Anakael
Copy link
Contributor Author

Anakael commented Jun 21, 2023

After pulling the latest update from this PR I've got 56 tests failed. Most with such error:

 [warn]: OmniSharp.MSBuild.ProjectManager
         Failed to load project file '/tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithNoAdditionalFiles.csproj'.
 [info]: OmniSharp.MSBuild.ProjectManager
         Loading project: /tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithMultiAdditionalFiles.csproj
 [dbug]: OmniSharp.MSBuild.SdksPathResolver
         Set MSBuildSDKsPath environment variable to: /home/dmitry/Documents/Programming/omnisharp-roslyn/.dotnet/sdk/6.0.203/Sdks
 [fail]: OmniSharp.MSBuild.ProjectLoader
         The "ProcessFrameworkReferences" task failed unexpectedly.
         System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
         File name: 'NuGet.Frameworks, Version=6.1.0.103, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
          ---> System.IO.FileLoadException: Could not load file or assembly 'NuGet.Frameworks, Version=6.7.0.50, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
            at System.Runtime.Loader.AssemblyLoadContext.<LoadFromPath>g____PInvoke|5_0(IntPtr __ptrNativeAssemblyBinder_native, UInt16* __ilPath_native, UInt16* __niPath_native, ObjectHandleOnStack __retAssembly_native)
            at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
            at Microsoft.Build.Shared.MSBuildLoadContext.Load(AssemblyName assemblyName)
            at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName)
            at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
            at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
            at Microsoft.NET.Build.Tasks.TaskBase.Execute()
            at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
            at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
 [warn]: OmniSharp.MSBuild.ProjectManager
         Failed to load project file '/tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithMultiAdditionalFiles.csproj'.
 [fail]: OmniSharp.MSBuild.ProjectManager
         Attempted to update project that is not loaded: /tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithSingleAdditionalFiles.csproj
 [fail]: OmniSharp.MSBuild.ProjectManager
         Attempted to update project that is not loaded: /tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithNoAdditionalFiles.csproj
 [fail]: OmniSharp.MSBuild.ProjectManager
         Attempted to update project that is not loaded: /tmp/sq14ctpe.kd3/ProjectWithAdditionalFiles/ProjectWithMultiAdditionalFiles.csproj

@Anakael
Copy link
Contributor Author

Anakael commented Jul 19, 2023

Still get errors after merge.

@Anakael
Copy link
Contributor Author

Anakael commented Aug 19, 2023

Now all tests pass success locally.

@@ -44,20 +44,6 @@ private Task ReadyHost(bool roslynAnalyzersEnabled)
{{"RoslynExtensionsOptions:EnableAnalyzersSupport", roslynAnalyzersEnabled.ToString()}});
}

[Fact]
public async Task CheckAllFilesOnNonAnalyzerReturnImmediatlyAllResults()
Copy link
Contributor Author

@Anakael Anakael Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now non analyzer diagnostic worker works the same way as analyzer which uses queue. I think this test is not actual anymore.

tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs Outdated Show resolved Hide resolved
Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anakael I appreciate you sticking with this PR. Thanks for the contribution!

@JoeRobich JoeRobich merged commit b2e64c6 into OmniSharp:master Aug 22, 2023
22 checks passed
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

Successfully merging this pull request may close these issues.

2 participants