Add "related spans" to diagnostic messages · Issue #10489 · microsoft/TypeScript (original) (raw)
We already have --pretty
error message output, but we can do even better. In this blog post @jonathandturner describes a set of improvements to Rust's error message framework to allow for an error to specify related spans, other than the primary span where the error was encountered - and to provide extra elaboration on each of those spans. This is incredibly useful, and we can do the same.
For example, when we report a duplicate definition error, in the diagnostic object, we could return the spans for the secondary declaration locations in the diagnostics object (potentially with elaboration on how they are a duplicate hidden behind a --elaborate
flag). Missing member errors can have a reference back to the type definition (since the error is equally likely to be fixed there). Type errors on assignments can reference back to the declaration of the LHS. There's probably countless errors where we could refer to a secondary location where either a type is likely wrong and causing the error or where the error is likely to be fixed. On the command line, this can just be surfaced as part of the current pretty
output, and inside vscode we could potentially coordinate to cause additional related spans to cause a code window to appear in the details popover.