sharpenrocks / Sharpen

Visual Studio extension that intelligently introduces new C# features into your existing codebase
https://sharpen.rocks
MIT License
416 stars 32 forks source link

Provide information to users if a C# suggestion cannot be applied because of e.g. a lower language version used in project #13

Open ironcev opened 6 years ago

ironcev commented 6 years ago

E.g. if the project sets the C# language version to 5.0 in its settings, the suggestions for e.g. version 7.0 will also be provided in the Sharpen Results window. We need a mechanism to provide visual information to users that the particular suggestion cannot be applied because the project settings use a lower version of the compiler.

We need a more detailed UX/UI concept how to do this.

ironcev commented 5 years ago

A lower language version used in the project is just one of the possible reasons why a suggestion cannot be applied. Type availability in the framework is another one. E.g. only some of the features of C# 8.0 are directly supported in .NET 4.8.

image

We could even have a situation that the framework version does not support a certain type like e.g. Range but the project uses NuGet packages that provide the type.

On the other hand, for e.g. Default interface implementation there are no special framework types needed, but the feature will work only on the Core runtime (at the moment).

Long story short: it's complex 😄 So in general, think well about what it really means that a particular suggestion can be applied in a particular piece of code.

(The table with language feature and framework support is taken from @miroslavpopovic's presentation that can be found in his what-is-new-in-dotnet-core-3 repository.)

shankyjain7243 commented 5 years ago

Sample screenshot if a suggestion is not compatible with language version of the project. Sharpen_Suggestion

ironcev commented 5 years ago

Thanks for digging deeper into the issue @shankyjain7243.

I'll answer the question from your PR #26 here so that we have all the things in one place and document at the same time some additional difficulties we have in this issue.

We are using CSharpLanguageVersions class to identify language versions, which can also be done via Microsoft.CodeAnalysis.CSharp.LanguageVersion enum, do I replace the class with the enum around the source code ?

No, this replacement wouldn't work. Why? Because of these two major reasons:

In the meanwhile, two more difficulties popped up. The first one is explained in this TODO. Basically, we can have analyzers that analyze files from a certain project and report findings in different projects. The solution provided in the PR does not support that, same as the existing implementation of the analyzers.

The second one is the larger-scale refactoring which we want to do, basically fixing all the points mentioned in the above TODO.

The PR #26 is a WIP as the title suggests but I wouldn't integrate it before we solve the other issues which are pretty heavy:

So I will close the PR and I suggest that we postpone the work on this issue until all the points above are closed. Thanks once again for providing more info!