Skip to content

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

Open

Description

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.

Activity

  1. added
    Domain: API
    Experience Enhancement
    on Dec 7, 2018
  2. weswigham commented on Dec 7, 2018

    @weswigham
    Member

    Daniel Rosenwasser (@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.

  3. DanielRosenwasser commented on Dec 10, 2018

    @DanielRosenwasser
    Member

    Seems pretty reasonable to me.

  4. added
    Breaking Change
    on Dec 13, 2018
  5. ajafff commented on Dec 14, 2018

    @ajafff
    ContributorAuthor

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeDomain: APIExperience EnhancementSuggestion

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions