Skip to content

[ty] Omit semantic tokens for unresolved symbols#24718

Merged
charliermarsh merged 4 commits intoastral-sh:mainfrom
denyszhak:fix/omit-semantic-tokens-for-unresolved-symbols
Apr 20, 2026
Merged

[ty] Omit semantic tokens for unresolved symbols#24718
charliermarsh merged 4 commits intoastral-sh:mainfrom
denyszhak:fix/omit-semantic-tokens-for-unresolved-symbols

Conversation

@denyszhak
Copy link
Copy Markdown
Contributor

Closes astral-sh/ty#3090

Summary

Stop emitting fallback semantic tokens for unknown symbols. Unresolved names, imports, and attributes now omit semantic tokens instead of being classified as Variable, so editors fall back to grammar highlighting.

Test Plan

Added tests and updated snapshots for older ones.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Apr 19, 2026
@denyszhak denyszhak marked this pull request as ready for review April 19, 2026 18:11
@astral-sh-bot astral-sh-bot Bot requested a review from charliermarsh April 19, 2026 18:11
@AlexWaygood AlexWaygood removed their request for review April 19, 2026 21:31
Comment thread crates/ty_ide/src/semantic_tokens.rs Outdated
tokens: Vec<SemanticToken>,
}

enum UnifiedTokenType {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can be moved back into the local function.

@charliermarsh charliermarsh changed the title [ty] omit semantic tokens for unresolved symbols [ty] Omit semantic tokens for unresolved symbols Apr 20, 2026
@charliermarsh charliermarsh merged commit 5062d0d into astral-sh:main Apr 20, 2026
50 checks passed
z = obj.CONSTANT # CONSTANT should be variable with readonly modifier
w = obj.prop # prop should be property
v = MyClass.method # method should be method (function)
u = List.__name__ # __name__ should be variable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test expectation here is now outdated. Can we say why we no longer expect a variable here (should probably be a property)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

List.__name__ currently goes into the unresolved-attribute path but there is no reason not to keep it as resolvable class attr instead (like MyClass__name__) and you are right this should be a property now, not a variable.

Comment on lines -3617 to -3618
"app" @ 26..29: Variable
"route" @ 30..35: Variable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if we should update this test. We're now clearly testing less than before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

app.route is unresolved now so it's consistent with what the change does. A better way would be to make the decorator resolvable, though. I can send a small follow-up PR and reference the same issue for context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider omitting semantic tokens for unresolved symbols

3 participants