Skip to content

Commit

Permalink
Revert "Some random clean up and improvements (#11095) (#11169)
Browse files Browse the repository at this point in the history
Revert "Some random clean up and improvements (#11095) for dev17.13
  • Loading branch information
phil-allen-msft authored Nov 6, 2024
2 parents 9b2adb4 + 594c89a commit 05e142e
Show file tree
Hide file tree
Showing 36 changed files with 131 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Render Children
ignoreLineEndingDifferences: true);
}

[ConditionalTheory(Is.Windows)]
[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[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);
}

[ConditionalTheory(Is.Windows)]
[OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[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,6 +6,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Xunit;

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

// "This test does not makes sense for case sensitive Operating Systems."
[ConditionalFact(Is.Windows)]
[Fact]
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,6 +30,7 @@
<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 Microsoft.AspNetCore.Razor.Utilities;
using System.Runtime.InteropServices;

namespace Microsoft.CodeAnalysis.Razor;

Expand All @@ -14,7 +14,7 @@ public static StringComparer Instance
{
get
{
return _instance ??= PlatformInformation.IsLinux
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? 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 Microsoft.AspNetCore.Razor.Utilities;
using System.Runtime.InteropServices;

namespace Microsoft.CodeAnalysis.Razor;

Expand All @@ -14,7 +14,7 @@ public static StringComparison Instance
{
get
{
return _instance ??= PlatformInformation.IsLinux
return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? 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 && PlatformInformation.IsWindows)
if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// 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 Microsoft.AspNetCore.Razor.Utilities;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Razor.Workspaces;

namespace Microsoft.AspNetCore.Razor.LanguageServer;
Expand All @@ -25,7 +25,8 @@ 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 => PlatformInformation.IsWindows;
public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

public override bool ShowAllCSharpCodeActions => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -81,7 +82,7 @@ protected override string NormalizeAndEnsureValidPath(string path)

static bool IsPathRootedForPlatform(string path)
{
if (PlatformInformation.IsWindows && path == "/")
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && 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 = PlatformInformation.IsLinux
private static readonly Func<char, char> s_charConverter = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? 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 (PlatformInformation.IsWindows &&
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
charsWritten > 1 &&
destination is ['/', ..] and not ['/', '/', ..])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 All @@ -27,7 +28,7 @@ internal static class RazorProjectInfoFactory

static RazorProjectInfoFactory()
{
s_stringComparison = PlatformInformation.IsLinux
s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? 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 (PlatformInformation.IsWindows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// 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 @@ -30,10 +30,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 (PlatformInformation.IsWindows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// 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,6 +6,7 @@

<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,6 +6,7 @@

<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)
{
[ConditionalFact(Is.Windows)]
[OSSkipConditionFact(["OSX", "Linux"])]
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);
}

[ConditionalFact(Is.Windows)]
[OSSkipConditionFact(["OSX", "Linux"])]
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);
}

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

[ConditionalFact(Is.Windows)]
[OSSkipConditionFact(["OSX", "Linux"])]
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 = PlatformInformation.IsWindows
private static readonly string s_fetchDataContents = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? FetchDataContents
: FetchDataContents.Replace("\n", "\r\n");

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

<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);
}

[ConditionalFact(Is.Windows)]
[OSSkipConditionFact(["OSX", "Linux"])]
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 (PlatformInformation.IsWindows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
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,6 +8,7 @@
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 @@ -18,7 +19,6 @@
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 = PlatformInformation.IsWindows ? 945 : 911;
var expectedCsharpRangeLength = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 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 (!PlatformInformation.IsWindows)
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
baselineContents = s_matchNewLines.Replace(baselineContents, "\n");
}
Expand Down
Loading

0 comments on commit 05e142e

Please sign in to comment.