Skip to content

Commit

Permalink
Fix roslyn multi-targeting (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Feb 19, 2024
1 parent e928f82 commit ce1aacd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1019](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1019) ([PR](https://github.com/dotnet/roslynator/pull/1402))
- Fix analyzer [RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250) ([PR](https://github.com/dotnet/roslynator/pull/1403), [PR](https://github.com/dotnet/roslynator/pull/1404))
- Fix code fix for [CS8600](https://josefpihrt.github.io/docs/roslynator/fixes/CS8600) changing the wrong type when casts or `var` are involved ([PR](https://github.com/dotnet/roslynator/pull/1393) by @jroessel)
- Fix Roslyn multi-targeting ([PR](https://github.com/dotnet/roslynator/pull/1407))

## [4.10.0] - 2024-01-24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if ROSLYN_4_2
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using System.Composition;
Expand Down Expand Up @@ -33,6 +32,7 @@ public override ImmutableArray<string> FixableDiagnosticIds

public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
#if ROSLYN_4_2
SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

if (!TryFindFirstAncestorOrSelf(root, context.Span, out SyntaxNode node, predicate: f => f.IsKind(SyntaxKind.StringLiteralExpression, SyntaxKind.InterpolatedStringExpression)))
Expand Down Expand Up @@ -83,8 +83,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
context.RegisterCodeFix(codeAction, diagnostic);
}
}
#else
await Task.CompletedTask;
#endif
}

#if ROSLYN_4_2
private static Task<Document> RefactorAsync(
Document document,
LiteralExpressionSyntax literalExpression,
Expand Down Expand Up @@ -221,5 +225,5 @@ private static Task<Document> UseRawStringLiteralAsync(

return document.WithTextChangeAsync(interpolatedString.Span, sb.ToString(), cancellationToken);
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if ROSLYN_4_2
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
Expand All @@ -26,10 +25,10 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
}
}

#if ROSLYN_4_2
public override void Initialize(AnalysisContext context)
{
base.Initialize(context);

context.RegisterCompilationStartAction(startContext =>
{
if (((CSharpCompilation)startContext.Compilation).LanguageVersion >= LanguageVersion.CSharp11)
Expand Down Expand Up @@ -116,5 +115,5 @@ private static bool ContainsBackSlashOrQuoteOrOpenBrace(string text, int start,

return false;
}
}
#endif
}
6 changes: 3 additions & 3 deletions src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if ROSLYN_4_2
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
Expand All @@ -26,6 +25,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
}
}

#if ROSLYN_4_2
public override void Initialize(AnalysisContext context)
{
base.Initialize(context);
Expand Down Expand Up @@ -89,5 +89,5 @@ private static void AnalyzeInterpolatedStringExpression(SyntaxNodeAnalysisContex
}
}
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if ROSLYN_4_0
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -27,6 +26,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
}
}

#if ROSLYN_4_0
public override void Initialize(AnalysisContext context)
{
base.Initialize(context);
Expand Down Expand Up @@ -86,5 +86,5 @@ internal static SyntaxNode GetNodeAfterNamespaceDeclaration(FileScopedNamespaceD
? usingDirective
: memberDeclaration;
}
}
#endif
}

0 comments on commit ce1aacd

Please sign in to comment.