Skip to content

Conversation

@lucach
Copy link
Contributor

@lucach lucach commented Nov 19, 2025

Summary

When computing semantic tokens, there are a few more statements potentially containing definitions than what is currently covered.

This commit reviews all the statements and completes the list of those requiring a custom visitor to add the DEFINITION modifier for the appropriate tokens.

Note: I've not added the DEFINITION modifier to the target of an augmented assignment. A new test makes that explicit. This is consistent with Pylance's behavior, although one could argue that given that all "regular" assignments are marked as definitions, perhaps also the augmented assignments should.

Test Plan

Added new tests for each new statement with a custom visitor. When a test was already existing, I've reviewed and applied the diff.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 19, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 19, 2025

mypy_primer results

No ecosystem changes detected ✅

No memory usage changes detected ✅

@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Nov 19, 2025
@AlexWaygood AlexWaygood removed their request for review November 19, 2025 11:20
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

Handling augmented assignments the way you do in this PR seems right to me.

@MichaReiser
Copy link
Member

Can you run the ty_server tests and update the semantic tokens snapshot

There are a few more statements potentially containing definitions than what is currently covered.
This commit reviews all the statements and completes the list of those
requiring a custom visitor to add the `DEFINITION` modifier for the
appropriate tokens.
@lucach lucach force-pushed the semantic_tokens_definitions branch from af6215a to 9fd6b24 Compare November 19, 2025 11:33
@lucach
Copy link
Contributor Author

lucach commented Nov 19, 2025

Whoops, sorry. I even ran them, I just overlooked the output 🤦‍♂️

@MichaReiser MichaReiser merged commit 18a14bf into astral-sh:main Nov 19, 2025
40 checks passed
dcreager added a commit that referenced this pull request Nov 19, 2025
* origin/main:
  [ty] Fix flaky tests on macos (#21524)
  [ty] Add tests for generic implicit type aliases (#21522)
  [ty] Semantic tokens: consistently add the `DEFINITION` modifier (#21521)
  Only render hyperlinks for terminals known to support them (#21519)
  [ty] Keep colorizing `mypy_primer` output (#21515)
  [ty] Exit with `2` if there's any IO error (#21508)
  [`ruff`] Fix false positive for complex conversion specifiers in `logging-eager-conversion` (`RUF065`) (#21464)
  [ty] tighten up handling of subscripts in type expressions (#21503)
dcreager added a commit that referenced this pull request Nov 19, 2025
* origin/main:
  [ty] Fix flaky tests on macos (#21524)
  [ty] Add tests for generic implicit type aliases (#21522)
  [ty] Semantic tokens: consistently add the `DEFINITION` modifier (#21521)
  Only render hyperlinks for terminals known to support them (#21519)
  [ty] Keep colorizing `mypy_primer` output (#21515)
  [ty] Exit with `2` if there's any IO error (#21508)
  [`ruff`] Fix false positive for complex conversion specifiers in `logging-eager-conversion` (`RUF065`) (#21464)
  [ty] tighten up handling of subscripts in type expressions (#21503)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants