Skip to content

Commit c382522

Browse files
authored
Re-apply "Some random clean up and improvements (#11095)" (#11177)
1 parent 40d2a6f commit c382522

File tree

36 files changed

+273
-131
lines changed

36 files changed

+273
-131
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ Render Children
493493
ignoreLineEndingDifferences: true);
494494
}
495495

496-
[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
496+
[ConditionalTheory(Is.Windows)]
497497
[InlineData(@"test.cshtml", @"test.cshtml")]
498498
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
499499
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
@@ -540,7 +540,7 @@ public void LinePragma_Is_Adjusted_On_Windows(string fileName, string expectedFi
540540
ignoreLineEndingDifferences: true);
541541
}
542542

543-
[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
543+
[ConditionalTheory(Is.Windows)]
544544
[InlineData(@"test.cshtml", @"test.cshtml")]
545545
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
546546
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System;
77
using System.IO;
88
using System.Linq;
9-
using System.Runtime.InteropServices;
109
using Xunit;
1110

1211
namespace Microsoft.AspNetCore.Razor.Language;
@@ -261,15 +260,10 @@ public void GetItem_ReturnsFileFromDisk()
261260
Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
262261
}
263262

264-
[Fact]
263+
// "This test does not makes sense for case sensitive Operating Systems."
264+
[ConditionalFact(Is.Windows)]
265265
public void GetItem_MismatchedCase_ReturnsFileFromDisk()
266266
{
267-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
268-
{
269-
// "This test does not makes sense for case sensitive Operating Systems."
270-
return;
271-
}
272-
273267
// Arrange
274268
var filePath = "/Views/About/About.cshtml";
275269
var lowerCaseTestFolder = TestFolder.ToLowerInvariant();

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<Compile Include="..\..\shared\JsonReaderExtensions.cs" LinkBase="Shared" />
3131
<Compile Include="..\..\shared\RazorDiagnosticJsonConverter.cs" LinkBase="Shared" />
3232
<Compile Include="..\..\shared\TagHelperDescriptorJsonConverter.cs" LinkBase="Shared" />
33-
<Compile Include="..\..\..\Razor\test\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
3433
</ItemGroup>
3534

3635
<ItemGroup>

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Runtime.InteropServices;
5+
using Microsoft.AspNetCore.Razor.Utilities;
66

77
namespace Microsoft.CodeAnalysis.Razor;
88

@@ -14,7 +14,7 @@ public static StringComparer Instance
1414
{
1515
get
1616
{
17-
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
17+
return _instance ??= PlatformInformation.IsLinux
1818
? StringComparer.Ordinal
1919
: StringComparer.OrdinalIgnoreCase;
2020
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Runtime.InteropServices;
5+
using Microsoft.AspNetCore.Razor.Utilities;
66

77
namespace Microsoft.CodeAnalysis.Razor;
88

@@ -14,7 +14,7 @@ public static StringComparison Instance
1414
{
1515
get
1616
{
17-
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
17+
return _instance ??= PlatformInformation.IsLinux
1818
? StringComparison.Ordinal
1919
: StringComparison.OrdinalIgnoreCase;
2020
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
using System.Diagnostics;
99
using System.Globalization;
1010
using System.Linq;
11-
using System.Runtime.InteropServices;
1211
using Microsoft.AspNetCore.Razor.Language.Intermediate;
12+
using Microsoft.AspNetCore.Razor.Utilities;
1313

1414
namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;
1515

@@ -661,7 +661,7 @@ public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, Source
661661

662662
private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context)
663663
{
664-
if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
664+
if (context.Options.RemapLinePragmaPathsOnWindows && PlatformInformation.IsWindows)
665665
{
666666
// ISSUE: https://github.com/dotnet/razor/issues/9108
667667
// The razor tooling normalizes paths to be forward slash based, regardless of OS.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

4-
using System.Runtime.InteropServices;
4+
using Microsoft.AspNetCore.Razor.Utilities;
55
using Microsoft.CodeAnalysis.Razor.Workspaces;
66

77
namespace Microsoft.AspNetCore.Razor.LanguageServer;
@@ -25,8 +25,7 @@ internal class DefaultLanguageServerFeatureOptions : LanguageServerFeatureOption
2525

2626
// Code action and rename paths in Windows VS Code need to be prefixed with '/':
2727
// https://github.com/dotnet/razor/issues/8131
28-
public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash
29-
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
28+
public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash => PlatformInformation.IsWindows;
3029

3130
public override bool ShowAllCSharpCodeActions => false;
3231

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7-
using System.Runtime.InteropServices;
87
using Microsoft.AspNetCore.Razor.Language;
98
using Microsoft.AspNetCore.Razor.Utilities;
109
using Microsoft.CodeAnalysis.Razor;
@@ -82,7 +81,7 @@ protected override string NormalizeAndEnsureValidPath(string path)
8281

8382
static bool IsPathRootedForPlatform(string path)
8483
{
85-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && path == "/")
84+
if (PlatformInformation.IsWindows && path == "/")
8685
{
8786
// We have to special case windows and "/" because for some reason Path.IsPathRooted returns true on windows for a single "/" path.
8887
return false;

src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Utilities;
1212

1313
internal static class FilePathNormalizer
1414
{
15-
private static readonly Func<char, char> s_charConverter = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
15+
private static readonly Func<char, char> s_charConverter = PlatformInformation.IsLinux
1616
? c => c
1717
: char.ToLowerInvariant;
1818

@@ -223,7 +223,7 @@ private static (int start, int length) NormalizeCore(ReadOnlySpan<char> source,
223223
// Replace slashes in our normalized span.
224224
NormalizeAndDedupeSlashes(destination, ref charsWritten);
225225

226-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
226+
if (PlatformInformation.IsWindows &&
227227
charsWritten > 1 &&
228228
destination is ['/', ..] and not ['/', '/', ..])
229229
{

src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Immutable;
66
using System.Diagnostics.CodeAnalysis;
77
using System.IO;
8-
using System.Runtime.InteropServices;
98
using System.Threading;
109
using System.Threading.Tasks;
1110
using Microsoft.AspNetCore.Razor.Language;
@@ -34,7 +33,7 @@ internal readonly record struct ConversionResult(RazorProjectInfo? ProjectInfo,
3433

3534
static RazorProjectInfoFactory()
3635
{
37-
s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
36+
s_stringComparison = PlatformInformation.IsLinux
3837
? StringComparison.Ordinal
3938
: StringComparison.OrdinalIgnoreCase;
4039
}

0 commit comments

Comments
 (0)