Skip to content

Conversation

@MatthewMckee4
Copy link
Contributor

Summary

We previously highlighted the whole attribute access for goto definition. This does not align with other language servers (rust-analyzer, python, etc).

More related discussion has been had here astral-sh/ty#169.

But I think for goto definition it seems unintuitive to highlight the whole expression

Test Plan

Update ty_ide tests

@github-actions
Copy link
Contributor

github-actions bot commented Aug 10, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MatthewMckee4 MatthewMckee4 marked this pull request as ready for review August 10, 2025 20:35
@MatthewMckee4 MatthewMckee4 changed the title Update goto range for attribute access to only target the attribute [ty] Update goto range for attribute access to only target the attribute Aug 10, 2025
@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Aug 10, 2025
@MichaReiser
Copy link
Member

MichaReiser commented Aug 11, 2025

Thank you. This makes sense to me. I still think it should be consistent with how we highlight attribute access in diagnostics, where other Python LSPs also only highlight the attribute part (and not the object). Which makes sense to me, but it seems we don't have alignment as a team.

@AlexWaygood
Copy link
Member

I'm not sure I see a strong argument for consistency here -- to me, the range we show for an invalid attribute-access operation seems like a pretty different concept to the range we use as the target for jumping to the original definition/declaration of an attribute. I don't have a very strong opinion, though.

@MichaReiser
Copy link
Member

I guess that depends on the reasoning why it's preferable to use self.x for diagnostics but not for go-to definition. For me, it seems to be similar enough in concept to at least treat it the same (which other type checkers do).

I did a quick check and TypeScript, Pyright, and Rust all highlight the attribute portion only in diagnostics and in goto definition. I still think we should just change our diagnostics.

Maybe I should stop arguing and just merge this to have another reason why we should change the diagnostic ;)

@MichaReiser
Copy link
Member

MichaReiser commented Aug 11, 2025

I'm okay going forward as it brings me closer to my goal, changing the range on the diagnostic and it matches my expectation for go to definition ;) It's also something that's easy to revert. Thank you

@MichaReiser MichaReiser merged commit 5063a73 into astral-sh:main Aug 11, 2025
40 checks passed
dcreager added a commit that referenced this pull request Aug 11, 2025
* main:
  [ty] Add `static-frame` as a walltime benchmark (#19844)
  [ty] Update goto range for attribute access to only target the attribute (#19848)
dcreager added a commit that referenced this pull request Aug 11, 2025
* dcreager/bound-typevar: (41 commits)
  [ty] Use separate Rust types for bound and unbound type variables (#19796)
  fix ide tests
  better unbound typevar rendering
  Apply suggestions from code review
  [ty] Add `static-frame` as a walltime benchmark (#19844)
  add explanatory comment
  [ty] Update goto range for attribute access to only target the attribute (#19848)
  remove unneeded ord
  add TODO for broken hover test
  better PEP 695 binding context
  Add AIR301 rule (#17707)
  Avoid underflow in default ranges before a BOM (#19839)
  Update actions/download-artifact digest to de96f46 (#19852)
  Update docker/login-action action to v3.5.0 (#19860)
  Update rui314/setup-mold digest to 7344740 (#19853)
  Update cargo-bins/cargo-binstall action to v1.14.4 (#19855)
  Update actions/cache action to v4.2.4 (#19854)
  Update Rust crate hashbrown to v0.15.5 (#19858)
  Update Rust crate camino to v1.1.11 (#19857)
  Update Rust crate proc-macro2 to v1.0.96 (#19859)
  ...
@MatthewMckee4 MatthewMckee4 deleted the goto-attribute-range branch November 6, 2025 11:48
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