Skip to content

Commit

Permalink
Remove documentFilePath parameter from HoverFactory.GetHoverAsync(...)
Browse files Browse the repository at this point in the history
The document file path can be retrieved from the RazorCodeDocument parameter.
  • Loading branch information
DustinCampbell committed Oct 31, 2024
1 parent b2e5bc8 commit 155e3c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V

return await HoverFactory.GetHoverAsync(
codeDocument,
documentContext.FilePath,
positionInfo.HostDocumentIndex,
options,
_projectManager.GetQueryOperations(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ internal static class HoverFactory
{
public static Task<LspHover?> GetHoverAsync(
RazorCodeDocument codeDocument,
string documentFilePath,
int absoluteIndex,
HoverDisplayOptions options,
ISolutionQueryOperations solutionQueryOperations,
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -218,7 +217,7 @@ internal static class HoverFactory
}

private static async Task<LspHover?> ElementInfoToHoverAsync(
string documentFilePath,
string? documentFilePath,
ImmutableArray<TagHelperDescriptor> descriptors,
LinePositionSpan span,
HoverDisplayOptions options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static class ClassifiedTagHelperTooltipFactory
private static readonly ClassifiedTextRun s_nullableType = new(ClassificationTypeNames.Punctuation, "?");

public static async Task<ContainerElement?> TryCreateTooltipContainerAsync(
string documentFilePath,
string? documentFilePath,
AggregateBoundElementDescription elementDescriptionInfo,
ISolutionQueryOperations solutionQueryOperations,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -140,7 +140,7 @@ public static bool TryCreateTooltip(AggregateBoundAttributeDescription attribute
}

private static async Task<ImmutableArray<DescriptionClassification>> TryClassifyElementAsync(
string documentFilePath,
string? documentFilePath,
AggregateBoundElementDescription elementInfo,
ISolutionQueryOperations solutionQueryOperations,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -169,8 +169,11 @@ private static async Task<ImmutableArray<DescriptionClassification>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Razor.Tooltip;
internal static class MarkupTagHelperTooltipFactory
{
public static async Task<MarkupContent?> TryCreateTooltipAsync(
string documentFilePath,
string? documentFilePath,
AggregateBoundElementDescription elementDescriptionInfo,
ISolutionQueryOperations solutionQueryOperations,
MarkupKind markupKind,
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 155e3c9

Please sign in to comment.