Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix roslyn multi-targeting #1407

Merged
merged 3 commits into from
Feb 19, 2024
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
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
}