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

Expose a few things to Razor #73361

Merged
merged 1 commit into from
May 7, 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
34 changes: 34 additions & 0 deletions src/Tools/ExternalAccess/Razor/ChecksumWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor;

internal readonly struct ChecksumWrapper(Checksum checksum) : IEquatable<ChecksumWrapper>
{
private readonly Checksum _value = checksum;

public override int GetHashCode()
{
return _value.GetHashCode();
}

public override bool Equals(object? obj)
{
if (obj is ChecksumWrapper wrapper)
{
return Equals(wrapper);
}
return false;
}

public bool Equals(ChecksumWrapper other)
{
return _value.Equals(other._value);
}

public override string ToString()
=> _value.ToString();
}
3 changes: 0 additions & 3 deletions src/Tools/ExternalAccess/Razor/RazorUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ public static Uri CreateAbsoluteUri(string absolutePath)

public static string GetDocumentFilePathFromUri(Uri uri)
=> ProtocolConversions.GetDocumentFilePathFromUri(uri);

public static Uri CreateUri(this TextDocument document)
=> document.GetURI();
}
3 changes: 3 additions & 0 deletions src/Tools/ExternalAccess/Razor/SolutionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public static ImmutableArray<TextDocument> GetTextDocuments(this Solution soluti

public static ImmutableArray<DocumentId> GetDocumentIds(this Solution solution, Uri documentUri)
=> LanguageServer.Extensions.GetDocumentIds(solution, documentUri);

public static int GetWorkspaceVersion(this Solution solution)
=> solution.WorkspaceVersion;
}
19 changes: 19 additions & 0 deletions src/Tools/ExternalAccess/Razor/TextDocumentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServer;

namespace Microsoft.CodeAnalysis.ExternalAccess.Razor;

internal static class TextDocumentExtensions
{
public static Uri CreateUri(this TextDocument document)
=> document.GetURI();

public static async Task<ChecksumWrapper> GetChecksumAsync(this TextDocument document, CancellationToken cancellationToken)
=> new ChecksumWrapper(await document.State.GetChecksumAsync(cancellationToken).ConfigureAwait(false));
}
Loading