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

Use Roslyn's editorconfig support #1771

Merged
merged 6 commits into from
Apr 21, 2020

Conversation

JoeRobich
Copy link
Member

Resolves #1657

@filipw
Copy link
Member

filipw commented Apr 19, 2020

thanks a lot, this is a very welcome change!

I left some small comments and just have a few questions:

  • should we not add the discovered editorconfig to the watcher here
    private void WatchProjectFiles(ProjectFileInfo projectFileInfo)
    ? so far it was not needed because the options were reapplied before formatting
  • it would be good to have some extra test similar to this one
    public async Task WhenProjectIsLoadedThenItContainsCustomRulesetsFromCsproj()
    that verifies that analyzer diagnostic options from editorconfig are correctly loaded
  • I wasn't aware of the EditorConfigFiles msbuild item - in which versions of VS is this supported? (I think in the past it wasn't possible to provide your own custom file path)

}
}

private void UpdateAnalyzerConfigFiles(Project project, IList<string> analyzerConfigFiles)
Copy link
Member

Choose a reason for hiding this comment

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

should this code be conditioned on editorconfig being enabled in OmniSharp?
otherwise, if you disable it, it would be respected on formatting, but the analyzer options would still apply

@@ -292,7 +306,8 @@ private ProjectInfo GetProject(CakeScript cakeScript, string filePath)
metadataReferences: GetMetadataReferences(cakeScript.References),
// TODO: projectReferences?
isSubmission: true,
hostObjectType: hostObjectType);
hostObjectType: hostObjectType)
.WithAnalyzerConfigDocuments(analyzerConfigDocuments);
Copy link
Member

Choose a reason for hiding this comment

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

I think the same should be applied here

public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
as well?

@JoeRobich
Copy link
Member Author

  • it would be good to have some extra test similar to this one

Yep, I agree

should this code be conditioned on editorconfig being enabled in OmniSharp?

Yeah, there are a few places to update if we want to disable the analyzer part. With it being under FormattingOptions I wasn't sure the expected behavior.

I'll update soon.

@@ -377,6 +377,11 @@ private void WatchProjectFiles(ProjectFileInfo projectFileInfo)
QueueProjectUpdate(projectFileInfo.FilePath, allowAutoRestore: true, projectFileInfo.ProjectIdInfo);
});

_fileSystemWatcher.Watch(".editorconfig", (file, changeType) =>
Copy link
Member

Choose a reason for hiding this comment

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

should this watch on projectFileInfo.AnalyzerConfigFiles instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it still need a catch-all to handle new .editorconfigs being added to subfolders? I expected this would be easy way of handling Add and Update.

@@ -75,6 +75,54 @@ public async Task WhenProjectIsLoadedThenItContainsCustomRulesetsFromCsproj()
}
}

[Fact]
public async Task WhenProjectIsLoadedThenItContainsAnalyzerConfigurationFromEditorConfig()
Copy link
Member

Choose a reason for hiding this comment

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

👍👍

@@ -29,6 +29,8 @@ public static void Initialize(IServiceProvider serviceProvider, CompositionHost
projectEventForwarder.Initialize();
var projectSystems = compositionHost.GetExports<IProjectSystem>();

workspace.EditorConfigEnabled = options.CurrentValue.FormattingOptions.EnableEditorConfigSupport;
Copy link
Member

Choose a reason for hiding this comment

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

it would be good to also reset this flag here https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Host/WorkspaceInitializer.cs#L62-L65
this way it should be effective in real time when options change (since they are watched)

Copy link
Member Author

Choose a reason for hiding this comment

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

This would be useful if there were a way to force all the projects to update. Is this option worth all this extra complexity? I would assume the presence of an .editorconfig would be the indicator of whether a user wanted .editorconfig support.

Copy link
Member

Choose a reason for hiding this comment

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

you are right we can solve this systematically separately as there are other areas that would benefit from that

Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

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.

Use Roslyn's native .editorconfig support
2 participants