microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.08k stars 12.49k forks source link

[tsserverlibrary] Allow reporting helpful links and error-names #39009

Open manuth opened 4 years ago

manuth commented 4 years ago

Search Terms

Support Links Helpful Links Diagnostic

Suggestion

VSCode now accepts either strings or numbers alongside with a support-link as the code-property of a Diagnostic, which provides the comfort to easily open up a website showing more details about the error:

https://github.com/microsoft/vscode-languageserver-node/blob/9466bf38aef41849b3d48a882e399a34e3127eb2/types/src/main.ts#L581-L624

It would be very awesome if TypeScript language services had the same option to not only pass a number as error-code but also strings and, most importantly, a link containing helpful info.

Use Cases

Basically whenever you use a plugin which reports errors especially when they're a tiny bit too complex to describe them in a few sentences.

Examples

        interceptor.AddMethod(
            "getSemanticDiagnostics",
            (target, delegate, fileName) =>
            {
                let diagnostics = delegate(fileName);
                diagnostics.push(
                    {
                        file: this.Program.getSourceFile(fileName),
                        start: 1,
                        length: 1,
                        messageText: "The member-ordering is incorrect.",
                        category: ts.DiagnosticCategory.Warning,
                        source: "eslint",
                        code: {
                            value: "import/order",
                            target: "https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md"
                        }
                    }
                return diagnostics;
            });

Checklist

My suggestion meets these guidelines:

manuth commented 4 years ago

@RyanCavanaugh is there anything I need to provide in order to start working on this issue?