-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #734 from sharwell/analyzer-config
Add support for .editorconfig documents
- Loading branch information
Showing
12 changed files
with
692 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...eAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/ProjectExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.CodeAnalysis.Testing | ||
{ | ||
internal static class ProjectExtensions | ||
{ | ||
private static readonly Func<Project, IEnumerable<TextDocument>> s_analyzerConfigDocuments; | ||
|
||
static ProjectExtensions() | ||
{ | ||
var analyzerConfigDocumentType = typeof(Project).GetTypeInfo().Assembly.GetType("Microsoft.CodeAnalysis.AnalyzerConfigDocument"); | ||
if (analyzerConfigDocumentType is { }) | ||
{ | ||
var analyzerConfigDocumentsProperty = typeof(Project).GetProperty(nameof(AnalyzerConfigDocuments), typeof(IEnumerable<>).MakeGenericType(analyzerConfigDocumentType)); | ||
if (analyzerConfigDocumentsProperty is { GetMethod: { } getMethod }) | ||
{ | ||
s_analyzerConfigDocuments = (Func<Project, IEnumerable<TextDocument>>)getMethod.CreateDelegate(typeof(Func<Project, IEnumerable<TextDocument>>), target: null); | ||
} | ||
else | ||
{ | ||
s_analyzerConfigDocuments = project => Enumerable.Empty<TextDocument>(); | ||
} | ||
} | ||
else | ||
{ | ||
s_analyzerConfigDocuments = project => Enumerable.Empty<TextDocument>(); | ||
} | ||
} | ||
|
||
public static IEnumerable<TextDocument> AnalyzerConfigDocuments(this Project project) | ||
=> s_analyzerConfigDocuments(project); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...Analysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/SolutionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.Testing | ||
{ | ||
internal static class SolutionExtensions | ||
{ | ||
private static readonly Func<Solution, DocumentId, string, SourceText, IEnumerable<string>?, string?, Solution> s_addAnalyzerConfigDocument; | ||
|
||
static SolutionExtensions() | ||
{ | ||
var methodInfo = typeof(Solution).GetMethod(nameof(AddAnalyzerConfigDocument), new[] { typeof(DocumentId), typeof(string), typeof(SourceText), typeof(IEnumerable<string>), typeof(string) }); | ||
if (methodInfo is { }) | ||
{ | ||
s_addAnalyzerConfigDocument = (Func<Solution, DocumentId, string, SourceText, IEnumerable<string>?, string?, Solution>)methodInfo.CreateDelegate(typeof(Func<Solution, DocumentId, string, SourceText, IEnumerable<string>, string, Solution>), target: null); | ||
} | ||
else | ||
{ | ||
s_addAnalyzerConfigDocument = (solution, documentId, name, text, folders, filePath) => throw new NotSupportedException(); | ||
} | ||
} | ||
|
||
public static Solution AddAnalyzerConfigDocument(this Solution solution, DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null) | ||
{ | ||
return s_addAnalyzerConfigDocument(solution, documentId, name, text, folders, filePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.