Skip to content

Group errors by line number and show count #7299

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
merged 9 commits into from
Jul 13, 2020
Merged

Conversation

eanders-ms
Copy link
Collaborator

@eanders-ms eanders-ms commented Jul 11, 2020

Duplicate compiler errors are grouped, and a count bubble is shown (if count > 1).

Before:
image

After:
image

(screenshots not taken from the same project, so total error count is different)

Fixes: microsoft/pxt-arcade#2105

@eanders-ms eanders-ms requested review from pelikhan and darzu July 11, 2020 00:57

let errorCount = 0;
(errors || []).forEach(e => errorCount += e.count);
Copy link
Member

Choose a reason for hiding this comment

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

nit: (errors || []).reduce((e, count) => e.count + count)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit: (errors || []).reduce((e, count) => e.count + count)

Delayed grouping made this unnecessary. Reverted my changes in this method.

}

function groupErrors(errors: pxtc.KsDiagnostic[]) {
const grouped: { [key: string]: GroupedError} = {};
Copy link
Member

Choose a reason for hiding this comment

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

nit - we have a type def for maps: Map<GroupedError>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit - we have a type def for maps: Map<GroupedError>

Oh yes, the Map type!

Copy link
Contributor

Choose a reason for hiding this comment

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

{ [key: string]: GroupedError} is standard TS syntax and we should prefer that IMO. I'd like to bring this up at the next code review day

@@ -94,7 +101,7 @@ export class ErrorList extends React.Component<ErrorListProps, ErrorListState> {

onErrorsChanged(errors: pxtc.KsDiagnostic[]) {
this.setState({
errors,
errors: groupErrors(errors),
Copy link
Member

Choose a reason for hiding this comment

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

IMO, we should lazily group errors if the error list is visible. In most cases, it is collapsed and this computation is not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO, we should lazily group errors if the error list is visible. In most cases, it is collapsed and this computation is not required.

Agreed that's better. Updated.

@eanders-ms eanders-ms requested a review from pelikhan July 13, 2020 18:00
}
}
let sorted: GroupedError[] = [];
grouped.forEach(value => sorted.push(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

sorted = [...grouped].sort((a, b) => a.index - b.index)

}

function groupErrors(errors: pxtc.KsDiagnostic[]) {
const grouped = new Map<string, GroupedError>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, what are the advantages of using a map type over vanilla objects?

Copy link
Member

Choose a reason for hiding this comment

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

we've been using consistently the Map type accross the entire PXT codebase; so to stay consistent, keep using it. Also, don't have to lookup the TS index syntax every time.

@@ -16,6 +16,7 @@
"emitDecoratorMetadata": true,
"declaration": false,
"preserveConstEnums": true,
"downlevelIteration": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pelikhan use of spread operator on map values required the addition of this compiler option (due to targeting es5). Any issue?

Copy link
Member

Choose a reason for hiding this comment

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

You'd have to ask this to the language gurus, @riknoll @mmoskal . we should decide where to draw the line w.r.t. to typescript features, specially because we might start to confuse STS vs TS versions.
imo: not worth it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll revert the change to avoid risk. Curious what the language gurus think though.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be fine. There's lots of things we do in TS that we cannot do in STS (like async).

@eanders-ms eanders-ms merged commit b0b5ae6 into master Jul 13, 2020
@eanders-ms eanders-ms deleted the eanders/group-errors branch July 13, 2020 20:33
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.

Error list shows thousands of errors
4 participants