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
19.04k stars 4.03k forks source link

support syntax highlighting for code documentation comments #75181

Open Meir017 opened 1 month ago

Meir017 commented 1 month 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

tasks from this issues:

sharwell commented 1 month 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 month ago

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

sharwell commented 1 month 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.

JakeYallop commented 1 month ago

The impression I have is that the C#-test option is not really a public feature (hence the slightly awkward name) - although the fact is it used by people (including myself in projects) maybe demonstrates that properly exposing such functionality would be a good idea.

If this was going to be exposed, wouldn't it be better to expose it as just C#? The reason its C#-test currently is because it has support for the test markup syntax used for unit testing analyzers:

image

And people (like me) just use it as a stand in even outside of analzyer tests as there is no better option.

Meir017 commented 1 month ago

I added tasks to the main comment here including the different requests we have here, I think that while discussing having syntax highlighting inside <code> comment tags it would make sense to even have intellisense (as if the code was inside this project)