Skip to content

Comments

[ty] Support goto-definition on vendored typeshed stubs#21020

Merged
Gankra merged 1 commit intomainfrom
gankra/goto-typeshed2
Oct 21, 2025
Merged

[ty] Support goto-definition on vendored typeshed stubs#21020
Gankra merged 1 commit intomainfrom
gankra/goto-typeshed2

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Oct 21, 2025

This is an alternative to #21012 that more narrowly handles this logic in the stub-mapping machinery rather than pervasively allowing us to identify cached files as typeshed stubs. Much of the logic is the same (pulling the logic out of ty_server so it can be reused).

I don't have a good sense for if one approach is "better" or "worse" in terms of like, semantics and Weird Bugs that this can cause. This one is just "less spooky in its broad consequences" and "less muddying of separation of concerns" and puts the extra logic on a much colder path. I won't be surprised if one day the previous implementation needs to be revisited for its more sweeping effects but for now this is good.

Fixes astral-sh/ty#1054

@Gankra Gankra requested a review from carljm as a code owner October 21, 2025 16:02
@Gankra Gankra added the server Related to the LSP server label Oct 21, 2025
@Gankra Gankra added the ty Multi-file analysis & type inference label Oct 21, 2025
@github-actions
Copy link
Contributor

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 ✅

Comment on lines +294 to +298
/// Get the cache-relative path where vendored paths should be written to.
pub fn relative_cached_vendored_root() -> SystemPathBuf {
// The vendored files are uniquely identified by the source commit.
SystemPathBuf::from(format!("vendored/typeshed/{}", ty_vendored::SOURCE_COMMIT))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is morally a const fn but I didn't want to deal with making that work and it's not a huge deal.

Copy link
Member

Choose a reason for hiding this comment

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

haha, I wanted something similar recently too and did draw the very same conclusion: I don't want to deal with this right now :)

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

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.

I like that. I agree that it's hard to predict if there are cases where it will break, but we'll see. Thanks for giving this a try!

Comment on lines +294 to +298
/// Get the cache-relative path where vendored paths should be written to.
pub fn relative_cached_vendored_root() -> SystemPathBuf {
// The vendored files are uniquely identified by the source commit.
SystemPathBuf::from(format!("vendored/typeshed/{}", ty_vendored::SOURCE_COMMIT))
}
Copy link
Member

Choose a reason for hiding this comment

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

haha, I wanted something similar recently too and did draw the very same conclusion: I don't want to deal with this right now :)

/// Get the cache-relative path where vendored paths should be written to.
pub fn relative_cached_vendored_root() -> SystemPathBuf {
// The vendored files are uniquely identified by the source commit.
SystemPathBuf::from(format!("vendored/typeshed/{}", ty_vendored::SOURCE_COMMIT))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SystemPathBuf::from(format!("vendored/typeshed/{}", ty_vendored::SOURCE_COMMIT))
SystemPath::from(concat!("vendored/typeshed", ty_vendored::SOURCE_COMMIT))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately concat concatenates only literals so this is a compiler error :(

@Gankra Gankra merged commit 2e13b13 into main Oct 21, 2025
43 checks passed
@Gankra Gankra deleted the gankra/goto-typeshed2 branch October 21, 2025 17:38
dcreager added a commit that referenced this pull request Oct 22, 2025
* main: (65 commits)
  [ty] Some more simplifications when rendering constraint sets (#21009)
  [ty] Make `attributes.md` mdtests faster (#21030)
  [ty] Set `INSTA_FORCE_PASS` and `INSTA_OUTPUT` environment variables from mdtest.py (#21029)
  [ty] Fall back to `Divergent` for deeply nested specializations (#20988)
  [`ruff`] Autogenerate TypeParam nodes (#21028)
  [ty] Add assertions to ensure that we never call `KnownClass::Tuple.to_instance()` or similar (#21027)
  [`ruff`] Auto generate ast Pattern nodes (#21024)
  [`flake8-simplify`] Skip `SIM911` when unknown arguments are present (#20697)
  Render a diagnostic for syntax errors introduced in formatter tests (#21021)
  [ty] Support goto-definition on vendored typeshed stubs (#21020)
  [ty] Implement go-to for binary and unary operators (#21001)
  [ty] Avoid ever-growing default types (#20991)
  [syntax-errors] Name is parameter and global (#20426)
  [ty] Disable panicking mdtest (#21016)
  [ty] Fix completions at end of file (#20993)
  [ty] Fix out-of-order semantic token for function with regular argument after kwargs (#21013)
  [ty] Fix auto import for files with `from __future__` import (#20987)
  [`fastapi`] Handle ellipsis defaults in FAST002 autofix (`FAST002`) (#20810)
  [`ruff`] Skip autofix for keyword and `__debug__` path params (#20960)
  [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998)
  ...
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.

goto-definition on vendored typeshed definitions doesn't work

2 participants