Skip to content

Add assertion when classification has unexpected length #33938

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

Merged

Conversation

uniqueiniquity
Copy link
Contributor

While investigating #33935, one reported repro was found because it caused a classification to have negative length.
Here, we add an assertion so that the language service fails, rather than the client having to handle such a case.

@@ -499,8 +499,10 @@ namespace ts {
return { spans, endOfLineState: EndOfLineState.None };

function pushClassification(start: number, end: number, type: ClassificationType): void {
const length = end - start;
Debug.assert(length >= 0, `Classification had non-positive length of ${length}`);
Copy link
Member

@DanielRosenwasser DanielRosenwasser Oct 17, 2019

Choose a reason for hiding this comment

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

Slightly nervous about a 0-length span getting a classification unless we classify 0-length trivia...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. It seemed like some classification spans made sense to only have trivia (since node.getStart is the start used here) but I now see that those won't come up in this path.

@uniqueiniquity uniqueiniquity merged commit 1bfc472 into microsoft:master Oct 18, 2019
@uniqueiniquity uniqueiniquity deleted the classifcationAssertion branch October 18, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants