I've written a Source generator which creates an error, I would love to be able to give the user more information about the specific error that they have by going to a documentation page.
Luckily DiagnosticDescriptor has a helpLinkUri
field which is described as:
An optional hyperlink that provides a more detailed description regarding the diagnostic.
But when I try to use this by setting helpLinkUri
to a test website like google.com
, http://google.com
, https://google.com
or www.google.com
I instead get sent to https://learn.microsoft.com/en-us/visualstudio/ide/not-in-toc/default which isn't what I set. This is when using Visual Studio and clicking on the error code in the errors panel.
How do I open a custom webpage for source generator diagnostic? Are there any limitations that the documentation doesn't mention? Is this a limitation present inside Visual Studio?
CodeExample:
private static void ErrorMessage(SourceProductionContext _arg1, AttributeSourceWithContext _arg2)
{
DiagnosticDescriptor errorType = new DiagnosticDescriptor(
id: "Error1",
title: "Incorrect line",
messageFormat: "This is complex, open help link for good explanation",
helpLinkUri: "google.com", // <----- this is not opened when inspecting the error
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);
Diagnostic errorInstance = Diagnostic.Create(errorType, _arg2.GetLocation());
_arg1.ReportDiagnostic(errorInstance);
}