diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs index 95098ca968b..90afa35df3f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs @@ -90,7 +90,6 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V return await HoverFactory.GetHoverAsync( codeDocument, - documentContext.FilePath, positionInfo.HostDocumentIndex, options, _projectManager.GetQueryOperations(), diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Hover/HoverFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Hover/HoverFactory.cs index 8f005337958..7c750004e0a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Hover/HoverFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Hover/HoverFactory.cs @@ -27,7 +27,6 @@ internal static class HoverFactory { public static Task GetHoverAsync( RazorCodeDocument codeDocument, - string documentFilePath, int absoluteIndex, HoverDisplayOptions options, ISolutionQueryOperations solutionQueryOperations, @@ -96,7 +95,7 @@ internal static class HoverFactory var span = containingTagNameToken.GetLinePositionSpan(codeDocument.Source); return ElementInfoToHoverAsync( - documentFilePath, binding.Descriptors, span, options, solutionQueryOperations, cancellationToken); + codeDocument.Source.FilePath, binding.Descriptors, span, options, solutionQueryOperations, cancellationToken); } if (HtmlFacts.TryGetAttributeInfo(owner, out containingTagNameToken, out _, out var selectedAttributeName, out var selectedAttributeNameLocation, out attributes) && @@ -218,7 +217,7 @@ internal static class HoverFactory } private static async Task ElementInfoToHoverAsync( - string documentFilePath, + string? documentFilePath, ImmutableArray descriptors, LinePositionSpan span, HoverDisplayOptions options, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/ClassifiedTagHelperTooltipFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/ClassifiedTagHelperTooltipFactory.cs index 73f78994d69..603cf2f8459 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/ClassifiedTagHelperTooltipFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/ClassifiedTagHelperTooltipFactory.cs @@ -58,7 +58,7 @@ internal static class ClassifiedTagHelperTooltipFactory private static readonly ClassifiedTextRun s_nullableType = new(ClassificationTypeNames.Punctuation, "?"); public static async Task TryCreateTooltipContainerAsync( - string documentFilePath, + string? documentFilePath, AggregateBoundElementDescription elementDescriptionInfo, ISolutionQueryOperations solutionQueryOperations, CancellationToken cancellationToken) @@ -140,7 +140,7 @@ public static bool TryCreateTooltip(AggregateBoundAttributeDescription attribute } private static async Task> TryClassifyElementAsync( - string documentFilePath, + string? documentFilePath, AggregateBoundElementDescription elementInfo, ISolutionQueryOperations solutionQueryOperations, CancellationToken cancellationToken) @@ -169,8 +169,11 @@ private static async Task> TryClassify TryClassifySummary(documentationRuns, descriptionInfo.Documentation); // 3. Project availability - await AddProjectAvailabilityInfoAsync( - documentFilePath, descriptionInfo.TagHelperTypeName, solutionQueryOperations, documentationRuns, cancellationToken).ConfigureAwait(false); + if (documentFilePath is not null) + { + await AddProjectAvailabilityInfoAsync( + documentFilePath, descriptionInfo.TagHelperTypeName, solutionQueryOperations, documentationRuns, cancellationToken).ConfigureAwait(false); + } // 4. Combine type + summary information descriptions.Add(new DescriptionClassification(typeRuns, documentationRuns)); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/MarkupTagHelperTooltipFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/MarkupTagHelperTooltipFactory.cs index 7c6635b6433..fd70b55bc97 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/MarkupTagHelperTooltipFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Tooltip/MarkupTagHelperTooltipFactory.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Razor.Tooltip; internal static class MarkupTagHelperTooltipFactory { public static async Task TryCreateTooltipAsync( - string documentFilePath, + string? documentFilePath, AggregateBoundElementDescription elementDescriptionInfo, ISolutionQueryOperations solutionQueryOperations, MarkupKind markupKind, @@ -73,14 +73,17 @@ internal static class MarkupTagHelperTooltipFactory descriptionBuilder.Append(finalSummaryContent); } - var availability = await solutionQueryOperations - .GetProjectAvailabilityTextAsync(documentFilePath, tagHelperType, cancellationToken) - .ConfigureAwait(false); - - if (availability is not null) + if (documentFilePath is not null) { - descriptionBuilder.AppendLine(); - descriptionBuilder.Append(availability); + var availability = await solutionQueryOperations + .GetProjectAvailabilityTextAsync(documentFilePath, tagHelperType, cancellationToken) + .ConfigureAwait(false); + + if (availability is not null) + { + descriptionBuilder.AppendLine(); + descriptionBuilder.Append(availability); + } } } diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Hover/HoverFactoryTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Hover/HoverFactoryTest.cs index 81dea3d1b27..c2ec26046cf 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Hover/HoverFactoryTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Hover/HoverFactoryTest.cs @@ -44,7 +44,7 @@ public async Task GetHoverAsync_TagHelper_Element() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -68,7 +68,7 @@ public async Task GetHoverAsync_TagHelper_Element_WithParent() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -92,7 +92,7 @@ public async Task GetHoverAsync_TagHelper_Attribute_WithParent() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -114,7 +114,7 @@ public async Task GetHoverAsync_TagHelper_Element_EndTag() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -136,7 +136,7 @@ public async Task GetHoverAsync_TagHelper_Attribute() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -159,7 +159,7 @@ public async Task GetHoverAsync_TagHelper_AttributeTrailingEdge() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -182,7 +182,7 @@ public async Task GetHoverAsync_TagHelper_AttributeValue_ReturnsNull() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -200,7 +200,7 @@ public async Task GetHoverAsync_TagHelper_AfterAttributeEquals_ReturnsNull() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -218,7 +218,7 @@ public async Task GetHoverAsync_TagHelper_AttributeEnd_ReturnsNull() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -236,7 +236,7 @@ public async Task GetHoverAsync_TagHelper_MinimizedAttribute() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -263,7 +263,7 @@ public void Increment(){ var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, "text.razor", SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -285,7 +285,7 @@ public async Task GetHoverAsync_TagHelper_MalformedElement() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -307,7 +307,7 @@ public async Task GetHoverAsync_TagHelper_MalformedAttribute() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -330,7 +330,7 @@ public async Task GetHoverAsync_HTML_MarkupElement() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseMarkdown, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -348,7 +348,7 @@ public async Task GetHoverAsync_TagHelper_PlainTextElement() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -371,7 +371,7 @@ public async Task GetHoverAsync_TagHelper_PlainTextElement_EndTag() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -393,7 +393,7 @@ public async Task GetHoverAsync_TagHelper_TextComponent() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: true, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.razor", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -417,7 +417,7 @@ public async Task GetHoverAsync_TagHelper_TextComponent_NestedInHtml() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: true, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.razor", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -442,7 +442,7 @@ public async Task GetHoverAsync_TagHelper_TextComponent_NestedInCSharp() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: true, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.razor", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -464,7 +464,7 @@ public async Task GetHoverAsync_TagHelper_TextComponent_NestedInCSharpAndText() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: true, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.razor", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -487,7 +487,7 @@ public async Task GetHoverAsync_TagHelper_PlainTextAttribute() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -511,7 +511,7 @@ public async Task GetHoverAsync_HTML_PlainTextElement() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -529,7 +529,7 @@ public async Task GetHoverAsync_HTML_PlainTextAttribute() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UsePlainText, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.Null(hover); @@ -547,7 +547,7 @@ public async Task GetHoverAsync_TagHelper_Element_VSClient_ReturnVSHover() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseVisualStudio, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseVisualStudio, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover); @@ -585,7 +585,7 @@ public async Task GetHoverAsync_TagHelper_Attribute_VSClient_ReturnVSHover() var codeDocument = RazorCodeDocumentFactory.CreateCodeDocument(code.Text, isRazorFile: false, SimpleTagHelpers.Default); // Act - var hover = await HoverFactory.GetHoverAsync(codeDocument, "file.cshtml", code.Position, UseVisualStudio, CreateSolutionQueryOperations(), DisposalToken); + var hover = await HoverFactory.GetHoverAsync(codeDocument, code.Position, UseVisualStudio, CreateSolutionQueryOperations(), DisposalToken); // Assert Assert.NotNull(hover);