Skip to content

Change Diagnostic.code to 'string | number' #28911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ajafff opened this issue Dec 7, 2018 · 3 comments
Open

Change Diagnostic.code to 'string | number' #28911

ajafff opened this issue Dec 7, 2018 · 3 comments
Labels
API Relates to the public API for TypeScript Breaking Change Would introduce errors in existing code Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Dec 7, 2018

I'm writing a LanguageService plugin for TypeScript that returns custom diagnostics. A Diagnostic needs to have a code property of type number.

I don't have a number. Instead I can provide a string that represents the name of the rule producing the diagnostic. In addition a random number I would choose looks quite ugly in the tooltip VSCode displays for the Diagnostic.

I know TypeScript only ever creates Diagnostics with numeric code, but it's too limiting for plugins.
I looked it up and the LanguageServer protocol specifies it as code?: number | string.

My current workaround is to use a type assertion. Until now nothing bad has happened.

@weswigham weswigham added API Relates to the public API for TypeScript Experience Enhancement Noncontroversial enhancements labels Dec 7, 2018
@weswigham
Copy link
Member

@DanielRosenwasser I wholeheartedly agree with this - I've made it twice in PRs we never merged about extensibility - it just makes a lot of sense for diagnostics that aren't from us.

@DanielRosenwasser
Copy link
Member

Seems pretty reasonable to me.

@ajafff
Copy link
Contributor Author

ajafff commented Dec 14, 2018

Continuing discussion from #28959

it might be better to return a new property on Diagnostic objects.

Does this only affect Diagnostic (DiagnosticRelatedInformation to be precise) or should it also be added to DiagnosticMessageChain and/or DiagnosticMessage?

Does this require a change to the LanguageServerProtocol spec?

@RyanCavanaugh RyanCavanaugh added the Suggestion An idea for TypeScript label Mar 7, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Breaking Change Would introduce errors in existing code Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants