3

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);
}
user3797758
  • 829
  • 1
  • 14
  • 28
  • Can you share more information about the inaccurate redirection of your target page? For example, the key code of this module. – wenbingeng-MSFT Dec 01 '22 at 08:51
  • 1
    @wenbingeng-MSFT I don't understand the question. If I give the help url of `Google.com` and I open the help for the error I get sent to the microsoft website in the question not the site that I indicated as having help information for the error. – user3797758 Dec 02 '22 at 14:53
  • This page will only pop up after the program runs wrong. According to your description, there may be a problem with the code. Can share some of your code? – wenbingeng-MSFT Dec 05 '22 at 06:46
  • 1
    @wenbingeng-MSFT it's not during execution, I want the page to open when I double click the error message in Visual Studios "Error List" pane. If you click the error code "Error1" (in the example) I would expect the browser to open to "google.com" as per example but it doesn't. This is my code as it's a custom code generator so I would expect to be able to direct to my own domain not MSDN. – user3797758 Mar 10 '23 at 18:34
  • I'm seeing the same misbehavior. My code generator is interested in attributes that decorate enum members. If my CG diagnoses a malformed attribute, a red or blue squiggle appears under the attribute, as expected. If the user hovers over the squiggle, a tooltip appears with the expected diagnostic text (ID and description) from the DiagnosticDescriptor, e.g., "AS101 The foo attribute is messed up." If the descriptor's helpLinkUri specifies a URI, AS101 would be a link in the tooltip and WOULD navigate to the expected site. But AS101 in the Error List panel would navigate to the MS site. – Rich Armstrong Jun 23 '23 at 20:40

0 Answers0