Skip to content

Highlight call-arguments range for reveal_type, static_assert, … #209

@sharkdp

Description

@sharkdp

Description

We currently highlight the full call expression for reveal_type-diagnostics and static_assert diagnostics:

info: revealed-type
 --> /home/shark/playground/test.py:3:1
  |
1 | from knot_extensions import static_assert
2 |
3 | reveal_type(2 + 3)
  | ------------------ info: Revealed type is `Literal[5]`
4 |
5 | static_assert((2 + 3) < 4)
  |

error: lint:static-assert-error
 --> /home/shark/playground/test.py:5:1
  |
3 | reveal_type(2 + 3)
4 |
5 | static_assert((2 + 3) < 4)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Static assertion error: argument evaluates to `False`
  |

I would like it better if only the argument was highlighted. I wanted to make this change quickly, but it's not completely straightforward and messes with CallOutcome (which @AlexWaygood is working on), so I figured I'd create a ticket instead.

This is also somewhat related to multiple-range diagnostics, because for functions like assert_type(<expr>, <type-expr>), we might want to highlight the first argument ("… has type <actual-type>") and then create a separate (informational?) text range for <type-expr> to highlight it as the expected type. In any case, we can certainly do better than this:

error: lint:type-assertion-failure
 --> /home/shark/playground/test.py:4:1
  |
2 | from typing import assert_type
3 |
4 | assert_type(2 + 3, str)
  | ^^^^^^^^^^^^^^^^^^^^^^^ Actual type `Literal[5]` is not the same as asserted type `str`
  |

Metadata

Metadata

Assignees

Labels

diagnosticsRelated to reporting of diagnostics.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions