Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
foreach (var project in projects)
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var driver = AnalyzerDriver.Create(compilation, ImmutableArray.Create(analyzer), null, out compilation, cancellationToken);
var discarded = compilation.GetDiagnostics(cancellationToken);
var diags = await driver.GetDiagnosticsAsync().ConfigureAwait(false);
var compilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create(analyzer), null, cancellationToken);
var diags = await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().ConfigureAwait(false);
foreach (var diag in diags)
{
if (diag.Location == Location.None || diag.Location.IsInMetadata)
Expand Down Expand Up @@ -106,7 +105,7 @@ protected static async Task<ImmutableArray<Diagnostic>> GetSortedDiagnosticsFrom
/// <see cref="Diagnostic.Location"/>.</returns>
private static Diagnostic[] SortDistinctDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).Distinct(default(DiagnosticEqualityComparer)).ToArray();
return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
}

#endregion
Expand Down Expand Up @@ -170,7 +169,7 @@ private static Project CreateProject(string[] sources, string language = Languag

var projectId = ProjectId.CreateNewId(debugName: TestProjectName);

var solution = new CustomWorkspace()
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.AddMetadataReference(projectId, CorlibReference)
Expand All @@ -190,43 +189,5 @@ private static Project CreateProject(string[] sources, string language = Languag
return solution.GetProject(projectId);
}
#endregion

/// <summary>
/// A little helper to be able to use Enumerable.Distinct. Currently Roslyn does have a bug so that Diagnostic.GetHashCode()
/// is not implemented correctly. <see href="https://github.com/dotnet/roslyn/issues/57"/>.
/// </summary>
struct DiagnosticEqualityComparer : IEqualityComparer<Diagnostic>
{
public bool Equals(Diagnostic x, Diagnostic y)
{
return (x == null && y == null)
|| x.Equals(y);
}

public int GetHashCode(Diagnostic obj)
{
return Combine(obj.Descriptor,
Combine(obj.Location.GetHashCode(),
Combine(obj.Severity.GetHashCode(), obj.WarningLevel)
));
}

int Combine<T>(T newKeyPart, int currentKey) where T : class
{
int hash = unchecked(currentKey * (int)0xA5555529);

if (newKeyPart != null)
{
return unchecked(hash + newKeyPart.GetHashCode());
}

return hash;
}
int Combine(int newKey, int currentKey)
{
return unchecked((currentKey * (int)0xA5555529) + newKey);
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,67 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeAnalysis">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Desktop">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Desktop">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0.0-beta2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
<Reference Include="Microsoft.CodeAnalysis.Workspaces.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0-rc1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.1.32.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\packages\System.Collections.Immutable.1.1.32-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Composition.AttributedModel">
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Composition.Convention">
<Reference Include="System.Composition.Convention, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Composition.Hosting">
<Reference Include="System.Composition.Hosting, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Composition.Runtime">
<Reference Include="System.Composition.Runtime, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Composition.TypedParts">
<Reference Include="System.Composition.TypedParts, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Reflection.Metadata">
<HintPath>..\..\packages\System.Reflection.Metadata.1.0.17-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
<Reference Include="System.Reflection.Metadata, Version=1.0.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -106,6 +120,10 @@
<Name>OpenStackNetAnalyzers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0-rc1\tools\analyzers\C#\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0-rc1\tools\analyzers\Microsoft.CodeAnalysis.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer,
{
var actions = new List<CodeAction>();
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), cancellationToken);
await codeFixProvider.ComputeFixesAsync(context).ConfigureAwait(false);
await codeFixProvider.RegisterCodeFixesAsync(context).ConfigureAwait(false);

if (!actions.Any())
{
Expand Down
15 changes: 8 additions & 7 deletions OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.32-beta" targetFramework="net45" />
<package id="System.Reflection.Metadata" version="1.0.17-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.0.0-rc1" targetFramework="net45" userInstalled="true" />
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0-rc1" targetFramework="net45" userInstalled="true" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0-rc1" targetFramework="net45" userInstalled="true" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0-rc1" targetFramework="net45" userInstalled="true" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0-rc1" targetFramework="net45" userInstalled="true" />
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net45" userInstalled="true" />
<package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" userInstalled="true" />
<package id="System.Reflection.Metadata" version="1.0.18-beta" targetFramework="net45" userInstalled="true" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ public class DocumentDelegatingApiCallCodeFix : CodeFixProvider
private static readonly ImmutableArray<string> _fixableDiagnostics =
ImmutableArray.Create(DocumentDelegatingApiCallAnalyzer.DiagnosticId);

public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
{
return _fixableDiagnostics;
}
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;

public override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
}

public override async Task ComputeFixesAsync(CodeFixContext context)
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand All @@ -47,7 +44,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
continue;

string description = "Add documentation for delegating HTTP API call";
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, classDeclarationSyntax, cancellationToken)), diagnostic);
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, classDeclarationSyntax, cancellationToken)), diagnostic);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ public class DocumentValueFromSummaryCodeFix : CodeFixProvider
private static readonly ImmutableArray<string> _fixableDiagnostics =
ImmutableArray.Create(DocumentValueFromSummaryAnalyzer.DiagnosticId);

public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
{
return _fixableDiagnostics;
}
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;

public override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
}

public override async Task ComputeFixesAsync(CodeFixContext context)
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand All @@ -46,7 +43,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
continue;

string description = "Document value from summary";
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, propertyDeclarationSyntax, cancellationToken)), diagnostic);
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedDocument(context, propertyDeclarationSyntax, cancellationToken)), diagnostic);
}
}

Expand Down Expand Up @@ -99,7 +96,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope
if (index >= 0)
valueText = valueText.Remove(index, 5);

SyntaxToken replaced = SyntaxFactory.Token(getsToken.LeadingTrivia, getsToken.CSharpKind(), text, valueText, getsToken.TrailingTrivia);
SyntaxToken replaced = SyntaxFactory.Token(getsToken.LeadingTrivia, getsToken.Kind(), text, valueText, getsToken.TrailingTrivia);
summaryContent = summaryContent.Replace(firstText, firstText.ReplaceToken(getsToken, replaced));
}
}
Expand Down Expand Up @@ -148,7 +145,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope

private bool IsContentElement(XmlNodeSyntax syntax)
{
switch (syntax.CSharpKind())
switch (syntax.Kind())
{
case SyntaxKind.XmlCDataSection:
case SyntaxKind.XmlElement:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static SyntaxList<XmlNodeSyntax> WithoutFirstAndLastNewlines(this SyntaxL
{
SyntaxToken newFirstToken = SyntaxFactory.Token(
firstTextToken.LeadingTrivia,
firstTextToken.CSharpKind(),
firstTextToken.Kind(),
trimmed,
firstTextToken.ValueText.TrimStart(),
firstTextToken.TrailingTrivia);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ public class ImplementBuilderPatternCodeFix : CodeFixProvider
private static readonly ImmutableArray<string> _fixableDiagnostics =
ImmutableArray.Create(ImplementBuilderPatternAnalyzer.DiagnosticId);

public sealed override ImmutableArray<string> GetFixableDiagnosticIds()
{
return _fixableDiagnostics;
}
public sealed override ImmutableArray<string> FixableDiagnosticIds => _fixableDiagnostics;

public override FixAllProvider GetFixAllProvider()
{
// This code fix can only be applied to one property at a time
return null;
}

public override async Task ComputeFixesAsync(CodeFixContext context)
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
Expand All @@ -52,7 +49,7 @@ public override async Task ComputeFixesAsync(CodeFixContext context)
continue;

string description = string.Format("Implement builder method 'With{0}'", propertyDeclaration.Identifier.ValueText);
context.RegisterFix(CodeAction.Create(description, cancellationToken => CreateChangedSolution(context, classDeclarationSyntax, propertyDeclaration, cancellationToken)), diagnostic);
context.RegisterCodeFix(CodeAction.Create(description, cancellationToken => CreateChangedSolution(context, classDeclarationSyntax, propertyDeclaration, cancellationToken)), diagnostic);
}
}

Expand Down
Loading