ty icon indicating copy to clipboard operation
ty copied to clipboard

Inconsistent semantic highlighting for imports in VS Code

Open GlobalMin opened this issue 2 months ago • 3 comments

I'm very excited to be using ty given how well uv and ruff have changed my Python dev experience, and so far it's clearly very fast. The one issue I'm having in VSCode is some 3rd party libraries, meaning needing to install with uv add are not highlighted like others and it looks off. See below for example where pandas is colored white while the other import paths are in green. Not all external libs have issues as shown in screenshot as well - fastapi looks fine.

Image

GlobalMin avatar Dec 20 '25 03:12 GlobalMin

I don't think it's related to third-party imports as it happens for standard library imports as well (https://play.ty.dev/2b5f19b2-59d7-496f-9b65-8ea19f7ee6ef).

I think it's because for an aliased import like import foo as bar, the server only sends the Namespace token for bar and not foo (code ref). Maybe we should send the Namespace token for foo as well?

It's interesting that I'm not seeing this discrepancy with the colorscheme that I'm using in VS Code (Gruvbox Material) but only with the default colorscheme.

dhruvmanila avatar Dec 23 '25 08:12 dhruvmanila

I used Developer: Inspect Editor Tokens and Scopes to inspect the semantic tokens produced by pylance and it classifies both pathlib tokens as namespace

MichaReiser avatar Dec 23 '25 08:12 MichaReiser

Ok I can confirm it's not about native Python versus 3rd party it's the import a as b pattern. Can reproduce 100% when adding imports like this.

GlobalMin avatar Dec 23 '25 17:12 GlobalMin