microsoft / microsoft/TypeScript
Add structure to diagnostics to enable nicer diagnostic output and interactivity in tooling such as IDEs
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔍 Search Terms
diagnostics, interactive errors, structured diagnostics, error formatting
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
change diagnostics to some structured data instead of plain strings. At its simplest this would be including an array of the sources for the text that populates the substitution variables in the diagnostic message strings. If we also keep a cache or recent sources and include a key into that cache in the diagnostic, then we can provide callback functionality for tools to get more information in both the TS api and tssserver.
📃 Motivating Example
IDEs can provide much richer displays for error messages and even add interactivity. Imagine having syntax highlighting for types or being able to click to "go to definition" in an error message.
A very rough proof of concept showing an enhancement to the problems view in VsCode
https://github.com/microsoft/TypeScript/assets/84949734/25f8366d-a94e-44fb-bfd2-9f204be96097
💻 Use Cases
- What do you want to use this for?
a. Better display and interaction with error message - What shortcomings exist with current approaches?
a. Currently only possible by parsing error text.
b. Advanced usages require traversing the AST to find the nodes and types that contribute to the error - What workarounds are you using in the meantime?
a. see 2.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the diagnostics exposed through the TypeScript API and tssserver, then compare the current plain-string diagnostics with the suggested structured data and source information. Review how IDE tooling currently parses messages or traverses the AST; done means tools can obtain richer diagnostic context and support interactive displays without changing existing runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100