dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.93k stars 4.02k forks source link

support syntax highlighting for code documentation comments #75181

Open Meir017 opened 5 days ago

Meir017 commented 5 days ago

Summary

In many libraries authors add code sample inside the <code> documentation comment, it would be helpful to have syntax highlighting for these code comments

Background and Motivation

This type of syntax-highlighting already exists in the form of adding a // lang=C#-test or annotation an argument with [StringSyntax("C#-test")]

however, this doesn't work

// lang=C#-test
var code = """
using System;
using System.Text;
var builder = new StringBuilder();
test.AppendLine(""Hello, World!"");
Console.WriteLine(builder.ToString());
""";

/// <code lang="C#-test">
/// using System;
/// using System.Text;
/// var builder = new StringBuilder();
/// test.AppendLine("Hello, World!");
/// Console.WriteLine(builder.ToString());
/// </code>
void Test() { }

from vscode: image

sharwell commented 1 day ago

Changing from Feature Request to Design Debt, since this feature was originally implemented in #35667 and the more recent LSP work failed to meet parity.

CyrusNajmabadi commented 1 day ago

@sharwell we added support for c# syntax highlighting within a doc comment codeblock in VS?

sharwell commented 23 hours ago

@CyrusNajmabadi Sorry, I added the above comment after seeing #75215. There are two separate reports here: a request for syntax highlighting, and an observation that the comment renders as inline text instead of a code block. The part implemented previously is just the code block portion.