Skip to content

Commit 76dd37a

Browse files
authored
PR feedback from #12415 which accidentally didn't get pushed (#12424)
1 parent fd9e1dc commit 76dd37a

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Hover/CohostHoverEndpoint.cs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Collections.Immutable;
56
using System.Composition;
67
using System.Threading;
@@ -97,41 +98,43 @@ public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilitie
9798
static markupContent => markupContent.Value
9899
);
99100

100-
if (htmlStringResponse is not null)
101+
if (htmlStringResponse is null)
101102
{
102-
// This logic is to prepend HTML hover content to the razor hover content if both exist.
103-
// The razor content comes through as a ContainerElement, while the html content comes
104-
// through as MarkupContent. We need to extract the html content and insert it at the
105-
// start of the combined ContainerElement.
106-
if (razorHover is VSInternalHover razorVsInternalHover
107-
&& razorVsInternalHover.RawContent is ContainerElement razorContainerElement)
108-
{
109-
var htmlStringClassifiedTextElement = ClassifiedTextElement.CreatePlainText(htmlStringResponse);
110-
var verticalSpacingTextElement = ClassifiedTextElement.CreatePlainText(string.Empty);
111-
var htmlContainerElement = new ContainerElement(
112-
ContainerElementStyle.Stacked,
113-
[htmlStringClassifiedTextElement, verticalSpacingTextElement]);
114-
115-
// Modify the existing hover's RawContent to prepend the HTML content.
116-
razorVsInternalHover.RawContent = new ContainerElement(razorContainerElement.Style, [htmlContainerElement, .. razorContainerElement.Elements]);
117-
}
118-
else
103+
return razorHover;
104+
}
105+
106+
// This logic is to prepend HTML hover content to the razor hover content if both exist.
107+
// The razor content comes through as a ContainerElement, while the html content comes
108+
// through as MarkupContent. We need to extract the html content and insert it at the
109+
// start of the combined ContainerElement.
110+
if (razorHover is VSInternalHover razorVsInternalHover
111+
&& razorVsInternalHover.RawContent is ContainerElement razorContainerElement)
112+
{
113+
var htmlStringClassifiedTextElement = ClassifiedTextElement.CreatePlainText(htmlStringResponse);
114+
var verticalSpacingTextElement = ClassifiedTextElement.CreatePlainText(string.Empty);
115+
var htmlContainerElement = new ContainerElement(
116+
ContainerElementStyle.Stacked,
117+
[htmlStringClassifiedTextElement, verticalSpacingTextElement]);
118+
119+
// Modify the existing hover's RawContent to prepend the HTML content.
120+
razorVsInternalHover.RawContent = new ContainerElement(razorContainerElement.Style, [htmlContainerElement, .. razorContainerElement.Elements]);
121+
}
122+
else
123+
{
124+
var razorStringResponse = razorHover.Contents.Match(
125+
static s => s,
126+
static markedString => throw new NotImplementedException(),
127+
static stringOrMarkedStringArray => throw new NotImplementedException(),
128+
static markupContent => markupContent.Value
129+
);
130+
131+
if (razorStringResponse is not null)
119132
{
120-
var razorStringResponse = razorHover.Contents.Match(
121-
static s => s,
122-
static markedString => null,
123-
static stringOrMarkedStringArray => null,
124-
static markupContent => markupContent.Value
125-
);
126-
127-
if (razorStringResponse is not null)
133+
razorHover.Contents = new MarkupContent()
128134
{
129-
razorHover.Contents = new MarkupContent()
130-
{
131-
Kind = MarkupKind.Markdown,
132-
Value = htmlStringResponse + "\n\n---\n\n" + razorStringResponse
133-
};
134-
}
135+
Kind = MarkupKind.Markdown,
136+
Value = htmlStringResponse + "\n\n---\n\n" + razorStringResponse
137+
};
135138
}
136139
}
137140

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/HoverAssertions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@ public static Action<ClassifiedTextRun> Type(string text)
9494

9595
public static Action<ClassifiedTextRun> WhiteSpace(string text)
9696
=> Run(text, ClassificationTypeNames.WhiteSpace);
97+
98+
public static Action<object?> HorizontalRule
99+
=> o => { };
97100
}

src/Razor/test/Microsoft.VisualStudioCode.RazorExtension.Test/Endpoints/Shared/CohostHoverEndpointTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ await VerifyHoverAsync(code, RazorFileKind.Legacy, htmlResponse, async (hover, d
106106
Container(
107107
ClassifiedText(
108108
Text(BodyDescription)),
109-
ClassifiedText(
110-
Text(string.Empty))),
109+
HorizontalRule),
111110
Container(
112111
Image,
113112
ClassifiedText(

src/Razor/test/Microsoft.VisualStudioCode.RazorExtension.Test/HoverAssertions.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ public static void VerifyContents(this LspHover hover, object expected)
1212
{
1313
var markup = hover.Contents.Fourth;
1414

15-
var actual = markup.Value.TrimEnd('\r', '\n');
16-
if (markup.Kind == MarkupKind.Markdown)
17-
{
18-
// Remove any horizontal rules we may have added to separate HTML and Razor content
19-
actual = actual.Replace("\n\n---\n\n", string.Empty);
20-
}
21-
22-
AssertEx.EqualOrDiff(expected.ToString(), actual);
15+
AssertEx.EqualOrDiff(expected.ToString(), markup.Value.TrimEnd('\r', '\n'));
2316
}
2417

2518
// Our VS Code test only produce plain text hover content, so these methods are complete overkill,
@@ -61,4 +54,7 @@ public static string Type(string text)
6154

6255
public static string WhiteSpace(string text)
6356
=> text;
57+
58+
public static string HorizontalRule
59+
=> "\n\n---\n\n";
6460
}

0 commit comments

Comments
 (0)