Skip to content

Commit

Permalink
Re-apply "Some random clean up and improvements (#11095)" (#11177)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Nov 7, 2024
1 parent 40d2a6f commit c382522
Show file tree
Hide file tree
Showing 36 changed files with 273 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Render Children
ignoreLineEndingDifferences: true);
}

[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[ConditionalTheory(Is.Windows)]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
Expand Down Expand Up @@ -540,7 +540,7 @@ public void LinePragma_Is_Adjusted_On_Windows(string fileName, string expectedFi
ignoreLineEndingDifferences: true);
}

[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[ConditionalTheory(Is.Windows)]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

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

[Fact]
// "This test does not makes sense for case sensitive Operating Systems."
[ConditionalFact(Is.Windows)]
public void GetItem_MismatchedCase_ReturnsFileFromDisk()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// "This test does not makes sense for case sensitive Operating Systems."
return;
}

// Arrange
var filePath = "/Views/About/About.cshtml";
var lowerCaseTestFolder = TestFolder.ToLowerInvariant();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<Compile Include="..\..\shared\JsonReaderExtensions.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\RazorDiagnosticJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\TagHelperDescriptorJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\..\Razor\test\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Utilities;

namespace Microsoft.CodeAnalysis.Razor;

Expand All @@ -14,7 +14,7 @@ public static StringComparer Instance
{
get
{
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
return _instance ??= PlatformInformation.IsLinux
? StringComparer.Ordinal
: StringComparer.OrdinalIgnoreCase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Utilities;

namespace Microsoft.CodeAnalysis.Razor;

Expand All @@ -14,7 +14,7 @@ public static StringComparison Instance
{
get
{
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
return _instance ??= PlatformInformation.IsLinux
? StringComparison.Ordinal
: StringComparison.OrdinalIgnoreCase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Microsoft.AspNetCore.Razor.Utilities;

namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;

Expand Down Expand Up @@ -661,7 +661,7 @@ public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, Source

private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context)
{
if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (context.Options.RemapLinePragmaPathsOnWindows && PlatformInformation.IsWindows)
{
// ISSUE: https://github.com/dotnet/razor/issues/9108
// The razor tooling normalizes paths to be forward slash based, regardless of OS.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor.Workspaces;

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

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

public override bool ShowAllCSharpCodeActions => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor;
Expand Down Expand Up @@ -82,7 +81,7 @@ protected override string NormalizeAndEnsureValidPath(string path)

static bool IsPathRootedForPlatform(string path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && path == "/")
if (PlatformInformation.IsWindows && path == "/")
{
// We have to special case windows and "/" because for some reason Path.IsPathRooted returns true on windows for a single "/" path.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Utilities;

internal static class FilePathNormalizer
{
private static readonly Func<char, char> s_charConverter = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
private static readonly Func<char, char> s_charConverter = PlatformInformation.IsLinux
? c => c
: char.ToLowerInvariant;

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

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
if (PlatformInformation.IsWindows &&
charsWritten > 1 &&
destination is ['/', ..] and not ['/', '/', ..])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
Expand Down Expand Up @@ -34,7 +33,7 @@ internal readonly record struct ConversionResult(RazorProjectInfo? ProjectInfo,

static RazorProjectInfoFactory()
{
s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
s_stringComparison = PlatformInformation.IsLinux
? StringComparison.Ordinal
: StringComparison.OrdinalIgnoreCase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Threading;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor;
Expand Down Expand Up @@ -305,7 +305,7 @@ public static string GetProjectSystemFilePath(Uri uri)
// however, it's the only way to get the correct file path for a document to map to a corresponding project
// system.

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformInformation.IsWindows)
{
// VSWin
return uri.GetAbsoluteOrUNCPath().Replace('/', '\\');
Expand Down
6 changes: 3 additions & 3 deletions src/Razor/src/rzls/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -31,10 +31,10 @@ public static async Task Main(string[] args)
if (args[i].Contains("debug", StringComparison.OrdinalIgnoreCase))
{
await Console.Error.WriteLineAsync($"Server started with process ID {Environment.ProcessId}").ConfigureAwait(true);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformInformation.IsWindows)
{
// Debugger.Launch() only works on Windows.
_ = Debugger.Launch();
Debugger.Launch();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation;

public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
{
[OSSkipConditionFact(["OSX", "Linux"])]
[ConditionalFact(Is.Windows)]
public async Task Handle_SimpleComponent_ReturnsResult()
{
// Arrange
Expand Down Expand Up @@ -83,7 +83,7 @@ await projectManager.UpdateAsync(updater =>
Assert.Equal("<MyTagHelper />", documentEdits[0].Edits[0].NewText);
}

[OSSkipConditionFact(["OSX", "Linux"])]
[ConditionalFact(Is.Windows)]
public async Task Handle_SimpleComponentWithChildFile_ReturnsResult()
{
// Arrange
Expand Down Expand Up @@ -148,7 +148,7 @@ await projectManager.UpdateAsync(updater =>
Assert.Equal("<MyTagHelper />", documentEdits[0].Edits[0].NewText);
}

[OSSkipConditionFact(["OSX", "Linux"])]
[ConditionalFact(Is.Windows)]
public async Task Handle_ComponentWithRequiredAttribute_ReturnsResult()
{
// Arrange
Expand Down Expand Up @@ -308,7 +308,7 @@ public async Task Handle_NotComponent_ReturnsNull()
Assert.Null(result);
}

[OSSkipConditionFact(["OSX", "Linux"])]
[ConditionalFact(Is.Windows)]
public async Task Handle_ComponentWithNestedFiles_ReturnsResult()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -63,7 +63,7 @@ protected override async Task OnInitializedAsync()
}
""";

private static readonly string s_fetchDataContents = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
private static readonly string s_fetchDataContents = PlatformInformation.IsWindows
? FetchDataContents
: FetchDataContents.Replace("\n", "\r\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task TryResolveAllProjects_MiscellaneousOwnerProjectWithOthers_Retu
AssertSnapshotsEqual(miscProject, project);
}

[OSSkipConditionFact(["OSX", "Linux"])]
[ConditionalFact(Is.Windows)]
public async Task TryResolveAllProjects_OwnerProjectDifferentCasing_ReturnsTrue()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#nullable disable

using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Utilities;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -54,7 +54,7 @@ public void GetItem_RootedFilePath_DoesNotBelongToProject()
RemoteRazorProjectFileSystem fileSystem;
string documentFilePath;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformInformation.IsWindows)
{
fileSystem = new RemoteRazorProjectFileSystem(@"C:\path\to");
documentFilePath = @"C:\otherpath\to\file.cshtml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand All @@ -19,6 +18,7 @@
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
Expand Down Expand Up @@ -903,7 +903,7 @@ public void GetMappedCSharpRanges_MinimalRangeVsSmallDisjointRanges_DisjointRang
else
{
// Note that the expected lengths are different on Windows vs. Unix.
var expectedCsharpRangeLength = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 945 : 911;
var expectedCsharpRangeLength = PlatformInformation.IsWindows ? 945 : 911;
Assert.True(codeDocument.TryGetMinimalCSharpRange(razorRange, out var csharpRange));
var textSpan = csharpSourceText.GetTextSpan(csharpRange);
Assert.Equal(expectedCsharpRangeLength, textSpan.Length);
Expand Down Expand Up @@ -1120,7 +1120,7 @@ private string GetBaselineFileContents(string baselineFileName)

var baselineContents = semanticFile.ReadAllText();

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (!PlatformInformation.IsWindows)
{
baselineContents = s_matchNewLines.Replace(baselineContents, "\n");
}
Expand Down
Loading

0 comments on commit c382522

Please sign in to comment.