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

Allow <code> in DocComments to render as a block in Hover response #75215

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.SpellCheck;
using Microsoft.CodeAnalysis.Tags;
Expand Down Expand Up @@ -936,6 +935,24 @@ public static LSP.MarkupContent GetDocumentationMarkupContent(ImmutableArray<Tag

codeFence = null;

break;
case TextTags.Text when taggedText.Style.HasFlag(TaggedTextStyle.Code):
// This represents `<code></code>` in doc comments. It can be a block or it can be inline.
// Since code elements optionally support a `lang` attribute and we do not have access to the
// language which was specified at this point, we tell the client to render it as plain text.

if (markdownBuilder.IsLineEmpty())
{
// If the current line is empty, we can append a code block.
markdownBuilder.AppendLine($"{BlockCodeFence}text");
markdownBuilder.AppendLine(taggedText.Text);
markdownBuilder.AppendLine(BlockCodeFence);
}
else
{
// There is text on the line already - we should append an in-line code block.
markdownBuilder.Append($"`{taggedText.Text}`");
}
break;
case TextTags.LineBreak:
// A line ending with double space and a new line indicates to markdown
Expand Down
Loading