Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Add a code analyzer to fix certain Span<T> usage #2206

Merged
merged 4 commits into from
Apr 16, 2018

Conversation

ahsonkhan
Copy link
Member

@ahsonkhan ahsonkhan commented Apr 13, 2018

I wanted to try and create a code analyzer and used the following Span<T> usage scenario as motivation:
Collapse AsSpan().Slice(start, length) into AsSpan(start, length)

This can be used to fix https://github.com/dotnet/corefx/issues/27330 (see dotnet/corefx#29078)

Screenshots:

  1. image

  2. image

  3. image

Majority of the code here is template code. Focus on the following files:

TODOs (I will file separate issues, and address outside this PR):

  1. Add to corefxlab.sln (and build script to produce NuGet package and VSIX that get uploaded to MyGet) - Add to corefxlab.sln (and build script to produce NuGet package and VSIX that get uploaded to MyGet) #2212
  2. Fix VSIX project to run using dotnet cli (via the command line) - Fix VSIX project so it can be built using dotnet cli (via the command line) #2213
    • Currently only builds in VS.
    • D:\GitHub\Fork\corefxlab\samples\SpanUsage\SpanUsage\SpanUsage.Vsix\SpanUsage.Vsix.csproj(94,3): error MSB4019: The imported project "D:\GitHub\Fork\corefxlab\dotnetcli\sdk\2.1.300-preview2-008530\Microsoft\VisualStudio\v15.0\VSSDK\Microsoft.VsSDK.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
  3. Adjust the Diagnostic location to be more precise (currently highlights the parent tree, which ends up over highlighting whenever there are several method calls chained together). - Consider adjusting the diagnostic location to be more precise #2214
  4. Update the VSIX description

Future code analysis rules that we can introduce:

cc @dotnet/corefxlab-contrib, @tarekgh, @stephentoub, @atsushikan, @khellang, @VSadov, @KrzysztofCwalina

@ahsonkhan ahsonkhan added the area-CodeAnalyzer Code Analyzer for Span<T> Usage label Apr 13, 2018
@ahsonkhan
Copy link
Member Author

ahsonkhan commented Apr 13, 2018

Fixed all AsSpan() calls in aspnet:
aspnet/SignalR#1991
aspnet/KestrelHttpServer#2491

@ahsonkhan
Copy link
Member Author

And corefxlab: #2207

# Visual Studio 15
VisualStudioVersion = 15.0.27604.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpanUsage", "SpanUsage\SpanUsage\SpanUsage.csproj", "{A99829A8-F185-4044-904F-211077DD11B8}"
Copy link
Member

Choose a reason for hiding this comment

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

Is it really a sample?

Copy link
Member Author

@ahsonkhan ahsonkhan Apr 13, 2018

Choose a reason for hiding this comment

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

TODO: 1. Add to corefxlab.sln

It could be considered a sample code analyzer for span. I wanted to start it there, and move it to the solution. Would you be fine with adding it to the solution?

Copy link
Member

Choose a reason for hiding this comment

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

@terrajobst is working on a package for many .NET analyzers. I think this analyzer might be a good fit for such package.

Having said that, I am totally fine with adding it to this samples project short term.

@ahsonkhan
Copy link
Member Author

@dotnet-bot test Innerloop Ubuntu16.04 Release Build and Test

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeAnalyzer Code Analyzer for Span<T> Usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Look for places to collapse AsSpan().Slice(start, length) into .AsSpan(start,length)
2 participants