Some checks failed
Publish NuGet Packages / publish (pull_request) Has been cancelled
Introduce a Roslyn analyzer to enforce unique ownership semantics for structs marked with the `[NonCopyable]` attribute. Added a corresponding code fix to resolve violations by suggesting the use of `Share()` or other ownership transfer methods. Key changes: - Added `StructCopyCodeAnalyzer` to detect invalid struct copies. - Implemented `StructCopyCodeFixProvider` to provide code fixes. - Created `Misaki.HighPerformance.Analyzer` and `CodeFixes` projects. - Added unit tests for the analyzer and code fixes. - Introduced `UniquePtr<T>` and `SharedPtr<T>` for pointer ownership. - Added a Visual Studio extension project and packaging support. - Updated `UnsafeUtility` to use `nint`/`nuint` for indices.
62 lines
3.0 KiB
C#
62 lines
3.0 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CodeFixes;
|
|
using Microsoft.CodeAnalysis.Diagnostics;
|
|
using Microsoft.CodeAnalysis.Testing;
|
|
using Microsoft.CodeAnalysis.Testing.Verifiers;
|
|
using Microsoft.CodeAnalysis.VisualBasic.Testing;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Misaki.HighPerformance.Analyzer.Test
|
|
{
|
|
public static partial class VisualBasicCodeFixVerifier<TAnalyzer, TCodeFix>
|
|
where TAnalyzer : DiagnosticAnalyzer, new()
|
|
where TCodeFix : CodeFixProvider, new()
|
|
{
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic()"/>
|
|
public static DiagnosticResult Diagnostic()
|
|
=> VisualBasicCodeFixVerifier<TAnalyzer, TCodeFix, MSTestVerifier>.Diagnostic();
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(string)"/>
|
|
public static DiagnosticResult Diagnostic(string diagnosticId)
|
|
=> VisualBasicCodeFixVerifier<TAnalyzer, TCodeFix, MSTestVerifier>.Diagnostic(diagnosticId);
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
|
|
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
|
|
=> VisualBasicCodeFixVerifier<TAnalyzer, TCodeFix, MSTestVerifier>.Diagnostic(descriptor);
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
|
|
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
|
|
{
|
|
var test = new Test
|
|
{
|
|
TestCode = source,
|
|
};
|
|
|
|
test.ExpectedDiagnostics.AddRange(expected);
|
|
await test.RunAsync(CancellationToken.None);
|
|
}
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, string)"/>
|
|
public static async Task VerifyCodeFixAsync(string source, string fixedSource)
|
|
=> await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult, string)"/>
|
|
public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
|
|
=> await VerifyCodeFixAsync(source, new[] { expected }, fixedSource);
|
|
|
|
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult[], string)"/>
|
|
public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
|
|
{
|
|
var test = new Test
|
|
{
|
|
TestCode = source,
|
|
FixedCode = fixedSource,
|
|
};
|
|
|
|
test.ExpectedDiagnostics.AddRange(expected);
|
|
await test.RunAsync(CancellationToken.None);
|
|
}
|
|
}
|
|
}
|