Skip to content
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

Introduce related spans into tsserver protocol #24548

Merged
merged 3 commits into from
Jun 15, 2018

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Jun 1, 2018

This just introduces related information spans into our protocol, this way we can start adding them to diagnostics and seeing them light up in the editor - needs a small change in vscode once the protocol element has been published as well.

Ref #22789, #10489

file: SourceFile | undefined;
start: number | undefined;
length: number | undefined;
messageText: string | DiagnosticMessageChain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageText: string | DiagnosticMessageChain; [](start = 8, length = 45)

I think I need more information about how these are intended to be used. Roslyn diagnostics support additional locations, but those locations don't have messages. We could create separate diagnostics but we would need a new code and category and I don't believe we'd be able to link them together. I think Roslyn more or less dropped this functionality (vs the old native compiler).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secondary code locations and more information pertaining to specifically that location in the context of the diagnostic. (eg, "Defined here", "Declared here", "Replicated here", and so on. The additional spans also allow us to use those spans when calculating quick fixes - so we can, for example, know what we can suggest a cast at the site of an assignability error, but also suggest modifying the type the assignment is failing against (because it is mentioned as a related span). The only diagnostic set we currently do a similar thing with is the esModuleInterop import error, which we currently issue a secondary diagnostic for (so there's no obvious link between the two).

Copy link
Member Author

@weswigham weswigham Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this isn't a new concept and there is prior art, which is why vscode has basic support for them (and is looking to iterate on their UI) - rust makes good use of related spans in it's errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying that it's either novel or bad, just that it goes against the grain of the API we're using.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to sit down and design this feature.. there seems to be two uses cases,

  1. additional locations, e.g. duplicate identifier errors, you would list them all in the same error message
  2. related diagnostics, e.g. type of var x is not assignable to string, and here is where x was declated

function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: ReadonlyArray<string> = [], category = diagnosticCategoryName(message), reportsUnnecessary?: {}): protocol.Diagnostic {
return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category, reportsUnnecessary, source: undefined };
function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: ReadonlyArray<string> = [], category = diagnosticCategoryName(message), reportsUnnecessary?: {}, relatedInformation?: protocol.DiagnosticRelatedInformation[]): protocol.Diagnostic {
return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category, reportsUnnecessary, relatedInformation, source: undefined };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relatedInformation [](start = 130, length = 18)

Should this new property be validated in some way?

Copy link
Member Author

@weswigham weswigham Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing has been modified to produce one yet, though we have a massive list courtesy of @DanielRosenwasser - this just makes it so we can start chipping that list away.

relatedInformation: map(diag.relatedInformation, formatRelatedInformation),
};
return includeFileName
? { ...common, fileName: diag.file && diag.file.fileName }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to create an object just to inline it.. you can set fileName to undefined

@mhegazy
Copy link
Contributor

mhegazy commented Jun 7, 2018

//CC @mjbvz

@mhegazy
Copy link
Contributor

mhegazy commented Jun 7, 2018

@weswigham we should also show the additional locations under --pretty.

@weswigham weswigham force-pushed the allow-relatedinfo-on-diag branch from a51811c to fb03d91 Compare June 14, 2018 21:43
@weswigham
Copy link
Member Author

@mhegazy
image
thoughts?

@weswigham
Copy link
Member Author

@mhegazy I've implemented the pretty output (as above) as well as the esModuleInterop import error related information.

@weswigham weswigham merged commit 640af3f into microsoft:master Jun 15, 2018
@weswigham weswigham deleted the allow-relatedinfo-on-diag branch June 15, 2018 17:54
@weswigham
Copy link
Member Author

@DanielRosenwasser Wanna open your massive list of error-updating backlog issues now that this is in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Related Error Spans Specifying regions for error messages/diagnostics on multiple locations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants