Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class CohostInlayHintResolveEndpoint(

var hint = await _remoteServiceInvoker.TryInvokeAsync<IRemoteInlayHintService, InlayHint>(
razorDocument.Project.Solution,
(service, solutionInfo, cancellationToken) => service.ResolveHintAsync(solutionInfo, razorDocument.Id, request, cancellationToken),
(service, solutionInfo, cancellationToken) => service.ResolveHintAsync(solutionInfo, razorDocument.Id, request, razorData.InDeclDocument, cancellationToken),
cancellationToken).ConfigureAwait(false);

if (hint is null)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.GoToDefinition;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;

namespace Microsoft.CodeAnalysis.Razor.Workspaces;
Expand All @@ -13,3 +13,5 @@ internal interface ITagHelperSearchEngine
{
Task<LspLocation[]?> TryLocateTagHelperDefinitionsAsync(ImmutableArray<BoundTagHelperResult> boundTagHelpers, IDocumentSnapshot documentSnapshot, ISolutionQueryOperations solutionQueryOperations, CancellationToken cancellationToken);
}

internal sealed record BoundTagHelperResult(TagHelperDescriptor ElementDescriptor, BoundAttributeDescriptor? AttributeDescriptor);
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Microsoft.CodeAnalysis.Razor.Protocol.InlayHints;

internal record class InlayHintDataWrapper(TextDocumentIdentifier TextDocument, object? OriginalData, Position OriginalPosition);
internal record class InlayHintDataWrapper(TextDocumentIdentifier TextDocument, object? OriginalData, Position OriginalPosition, bool InDeclDocument);
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ internal interface IRemoteInlayHintService : IRemoteJsonService
{
ValueTask<InlayHint[]?> GetInlayHintsAsync(JsonSerializableRazorSolutionWrapper solutionInfo, JsonSerializableDocumentId razorDocumentId, InlayHintParams inlayHintParams, bool displayAllOverride, CancellationToken cancellationToken);

ValueTask<InlayHint> ResolveHintAsync(JsonSerializableRazorSolutionWrapper solutionInfo, JsonSerializableDocumentId razorDocumentId, InlayHint inlayHint, CancellationToken cancellationToken);
ValueTask<InlayHint> ResolveHintAsync(JsonSerializableRazorSolutionWrapper solutionInfo, JsonSerializableDocumentId razorDocumentId, InlayHint inlayHint, bool inDeclDocument, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,38 @@ internal sealed class FoldingRangeService(
private readonly IEnumerable<IRazorFoldingRangeProvider> _foldingRangeProviders = foldingRangeProviders;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<FoldingRangeService>();

public ImmutableArray<FoldingRange> GetFoldingRanges(RazorCodeDocument codeDocument, FoldingRange[] csharpRanges, ImmutableArray<FoldingRange> htmlRanges, CancellationToken cancellationToken)
public ImmutableArray<FoldingRange> GetFoldingRanges(RazorCodeDocument codeDocument, FoldingRange[] csharpRanges, FoldingRange[]? declCSharpRanges, ImmutableArray<FoldingRange> htmlRanges, CancellationToken cancellationToken)
{
using var _ = ArrayBuilderPool<FoldingRange>.GetPooledObject(out var mappedRanges);

// We have no idea how many ranges we'll end up with, because we expect to filter out a lot of C# ranges,
// but we will at least have one per html range so can avoid some initial resizing of the backing data store.
mappedRanges.SetCapacityIfLarger(htmlRanges.Length);

var csharpDocument = codeDocument.GetRequiredImplCSharpDocument();
AddMappedCSharpRanges(csharpRanges, declarationDocument: false);
AddMappedCSharpRanges(declCSharpRanges, declarationDocument: true);

foreach (var foldingRange in csharpRanges)
void AddMappedCSharpRanges(FoldingRange[]? ranges, bool declarationDocument)
{
var span = GetLinePositionSpan(foldingRange);
if (ranges is null)
{
return;
}

if (_documentMappingService.TryMapToRazorDocumentRange(csharpDocument, span, out var mappedSpan))
var csharpDocument = codeDocument.GetRequiredCSharpDocument(declarationDocument);
foreach (var foldingRange in ranges)
{
foldingRange.StartLine = mappedSpan.Start.Line;
foldingRange.StartCharacter = mappedSpan.Start.Character;
foldingRange.EndLine = mappedSpan.End.Line;
foldingRange.EndCharacter = mappedSpan.End.Character;
var span = GetLinePositionSpan(foldingRange);

if (_documentMappingService.TryMapToRazorDocumentRange(csharpDocument, span, out var mappedSpan))
{
foldingRange.StartLine = mappedSpan.Start.Line;
foldingRange.StartCharacter = mappedSpan.Start.Character;
foldingRange.EndLine = mappedSpan.End.Line;
foldingRange.EndCharacter = mappedSpan.End.Character;

mappedRanges.Add(foldingRange);
mappedRanges.Add(foldingRange);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace Microsoft.CodeAnalysis.Remote.Razor.FoldingRanges;

internal interface IFoldingRangeService
{
ImmutableArray<FoldingRange> GetFoldingRanges(RazorCodeDocument codeDocument, FoldingRange[] csharpRanges, ImmutableArray<FoldingRange> htmlRanges, CancellationToken cancellationToken);
ImmutableArray<FoldingRange> GetFoldingRanges(RazorCodeDocument codeDocument, FoldingRange[] csharpRanges, FoldingRange[]? declCSharpRanges, ImmutableArray<FoldingRange> htmlRanges, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,22 @@ private async ValueTask<ImmutableArray<RemoteFoldingRange>> GetFoldingRangesAsyn
ImmutableArray<RemoteFoldingRange> htmlRanges,
CancellationToken cancellationToken)
{
var generatedDocument = await context.Snapshot
.GetGeneratedDocumentAsync(cancellationToken)
.ConfigureAwait(false);

var lineFoldingOnly = _clientCapabilitiesService.ClientCapabilities.TextDocument?.FoldingRange?.LineFoldingOnly ?? false;
var globalOptions = generatedDocument.Project.Solution.Services.ExportProvider.GetService<IGlobalOptionService>();
var globalOptions = context.TextDocument.Project.Solution.Services.ExportProvider.GetService<IGlobalOptionService>();

var generatedDocument = await context.Snapshot.GetGeneratedDocumentAsync(declarationDocument: false, cancellationToken).ConfigureAwait(false);
var csharpRanges = await FoldingRangesHandler.GetFoldingRangesAsync(globalOptions, generatedDocument, lineFoldingOnly, cancellationToken).ConfigureAwait(false);

FoldingRange[]? declCSharpRanges = null;
if (await context.Snapshot.TryGetGeneratedDocumentAsync(declarationDocument: true, cancellationToken).ConfigureAwait(false) is SourceGeneratedDocument declGeneratedDocument)
{
declCSharpRanges = await FoldingRangesHandler.GetFoldingRangesAsync(globalOptions, declGeneratedDocument, lineFoldingOnly, cancellationToken).ConfigureAwait(false);
}

var convertedHtml = htmlRanges.SelectAsArray(RemoteFoldingRange.ToLspFoldingRange);

var codeDocument = await context.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
return _foldingRangeService.GetFoldingRanges(codeDocument, csharpRanges, convertedHtml, cancellationToken)
return _foldingRangeService.GetFoldingRanges(codeDocument, csharpRanges, declCSharpRanges, convertedHtml, cancellationToken)
.SelectAsArray(RemoteFoldingRange.FromLspFoldingRange);
}
}
Loading