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

Add isObject check to ProblemMarker #12251

Closed
wants to merge 1 commit into from

Conversation

eneufeld
Copy link
Contributor

@eneufeld eneufeld commented Mar 2, 2023

What it does

Use isObject check in problem-marker class instead of 'kind' in node check to not get type errors which occur on non marker. These occur because a previously existing check was removed in problem-selection.ts . The error prevents the context menu from showing all entries.

Contributed on behalf of STMicroelectronics

Fixes #12250

How to test

  1. Open problems view
  2. Create a problem marker eg by creating an invalid js file
  3. right click on the problem in the problems view
  4. See that without the fix there is only one entry: Collapse All , with the fix 3 entries are shown: Copy, Copy Message and Collapse All

Review checklist

Reminder for reviewers

Comment on lines 28 to 30
export function is(node: Marker<object>): node is ProblemMarker {
return 'kind' in node && node.kind === PROBLEM_KIND;
return isObject<ProblemMarker>(node) && node.kind === PROBLEM_KIND;
}
Copy link
Member

Choose a reason for hiding this comment

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

The fact that we have to use isObject here to determine that the node is an object implies that the Marker<object> contract doesn't hold up as expected. We should use node: unknown instead.

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!
I updated the pr and changed the cast to Marker<object>

The `in` operator does not work on undefined objects.
So in order to check the node kind we need to make sure,
that the node is an object.

Contributed on behalf of STMicroelectronics

Fixes eclipse-theia#12250
@tortmayr tortmayr requested a review from msujew March 2, 2023 12:47
export function is(node: Marker<object>): node is ProblemMarker {
return 'kind' in node && node.kind === PROBLEM_KIND;
export function is(node: unknown): node is ProblemMarker {
return isObject<Marker<object>>(node) && node.kind === PROBLEM_KIND;
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 not sure this is correct: shouldn't we assert it's a marker first? Right now an object like this wold fit the bill:

{
   kind: 'problem'
}

would fit the bill, even though it's not a marker. But asserting ProblemMarker.is(foo) implies that it's a marker, typing-wise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tsmaeder I agree, the code is very optimistic. But the previous code did the same assumption.
So I would suggest to tackle this improved marker assertion in a separate ticket.

Copy link
Member

@msujew msujew Mar 2, 2023

Choose a reason for hiding this comment

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

Well, during the runtime, yes. But from a static analysis perspective, it assumed that the node already is a Marker<object>. So we should confirm that as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the static typing problem stems from #12253. That is a considerably bigger fish to fry, though, and it would be asking to much from a PR to fix a concrete problem. @msujew what are you suggesting, concretely?

@vince-fugnitto vince-fugnitto added the problems issues related to the problems widget label Mar 2, 2023
@eneufeld
Copy link
Contributor Author

eneufeld commented Mar 9, 2023

Closing as a better fix will be provided by #12259

@eneufeld eneufeld closed this Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
problems issues related to the problems widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProblemsView context menu only shows 'Collapse All'
4 participants