Skip to content

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jul 11, 2025

Summary

Closes astral-sh/ty#814

cargo-dist only sets the version of the ty crate. That means, the CARGO_PKG_VERSION is always 0.0.0 for the ty_server.

This PR works around this by adding the program_version to ruff_db which gets initialized by the ty crate (where the version is correct)
and the server can read from. This has the nice side effect that the same version can be used in the type checking panic handler (in ty_project).

An alternative would have been to pass the version to ty_server but we then couldn't use it in the catch handler in ty_project.

I made some changes to ty's build script to take the commit from the ruff repository when not built inside the ty repository.
This gives us at least some meaningful version identifier for debug builds.

Test Plan

Version in initialize response:

    "serverInfo": {
        "name": "ty",
        "version": "ruff/0.12.2+87 (426fa4bb1 2025-07-11)"
    }

Version logged during startup

2025-07-11 15:19:23.122004000 DEBUG Version: ruff/0.12.2+87 (426fa4bb1 2025-07-11)
2025-07-11 15:19:23.127378000  INFO Defaulting to python-platform `darwin`
2025-07-11 15:19:23.127599000 DEBUG Discovering virtual environment in `/Users/micha/astral/test`

Version in panic handler

error[panic]: Panicked at crates/ty_python_semantic/src/types.rs:97:5 when checking `/Users/micha/astral/test/create.py`: `Test`
info: This indicates a bug in ty.
info: If you could open an issue at https://github.com/astral-sh/ty/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Platform: macos aarch64
info: Args: ["target/debug/ty", "check", "../test/create.py"]
info: Version: ruff/0.12.2+88 (0f58920fc 2025-07-11)
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information
info: query stacktrace:
   0: check_file_impl(Id(c00))
             at crates/ty_project/src/lib.rs:474

@MichaReiser MichaReiser requested a review from carljm as a code owner July 11, 2025 13:25
@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Jul 11, 2025
@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Jul 11, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser force-pushed the micha/fix-server-version branch from 0f58920 to 474d4ac Compare July 11, 2025 13:45
@MichaReiser MichaReiser force-pushed the micha/fix-server-version branch from 474d4ac to a82b6ff Compare July 11, 2025 13:45
@sharkdp
Copy link
Contributor

sharkdp commented Jul 11, 2025

Hmm... isn't showing the ruff version in the ty server even more confusing than showing 0.0.0? Sure, the commit hash is useful for us, but most users won't know that the ty codebase lives inside the ruff repo?

@MichaReiser
Copy link
Member Author

MichaReiser commented Jul 11, 2025

Hmm... isn't showing the ruff version in the ty server even more confusing than showing 0.0.0? Sure, the commit hash is useful for us, but most users won't know that the ty codebase lives inside the ruff repo?

We only use the ruff commit version when you build ty from within the Ruff repository. Only developers should really be doing this. The builds that we release are all built from within the ty repository and, therefore, they use the version from the dist-workspace.toml and the commit from the ty repository.

@AlexWaygood AlexWaygood removed their request for review July 11, 2025 18:09
@dhruvmanila
Copy link
Member

cargo-dist only sets the version of the ty crate. That means, the CARGO_PKG_VERSION is always 0.0.0 for the ty_server.

Should we use the CARGO_PKG_VERSION from the ty crate? This is what the ruff_server crate does as well.

}: Args,
) -> Result<ExitStatus> {
{
ruff_db::set_program_version(crate::version::version().to_string()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Why is this required? Isn't this the entrypoint for the Ruff CLI?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is more a precaution that we don't introduce a panic in ruff when we add a new path accessing version (Both the diagnostics and ruff analzye use the ruff_db crate).

@MichaReiser
Copy link
Member Author

Should we use the CARGO_PKG_VERSION from the ty crate? This is what the ruff_server crate does as well.

I think it's important that the server version matches the output of ty version. That's why I went with using that version string instead.

@MichaReiser MichaReiser merged commit 3da8b51 into main Jul 14, 2025
37 checks passed
@MichaReiser MichaReiser deleted the micha/fix-server-version branch July 14, 2025 07:06
dcreager added a commit that referenced this pull request Jul 14, 2025
* dcreager/merge-arguments: (223 commits)
  fix docs
  Combine CallArguments and CallArgumentTypes
  [ty] Sync vendored typeshed stubs (#19334)
  [`refurb`] Make example error out-of-the-box (`FURB122`) (#19297)
  [refurb] Make example error out-of-the-box (FURB177) (#19309)
  [ty] ignore errors when reformatting codemodded typeshed (#19332)
  [ty] Provide docstrings for stdlib APIs when hovering over them in an IDE (#19311)
  [ty] Add virtual files to the only project database (#19322)
  Add t-string fixtures for rules that do not need to be modified (#19146)
  [ty] Remove `FileLookupError` (#19323)
  [ty] Fix handling of metaclasses in `object.<CURSOR>` completions
  [ty] Use an interval map for scopes by expression (#19025)
  [ty] List all `enum` members (#19283)
  [ty] Handle configuration errors in LSP more gracefully (#19262)
  [ty] Use python version and path from Python extension (#19012)
  [`pep8_naming`] Avoid false positives on standard library functions with uppercase names (`N802`) (#18907)
  Update Rust crate toml to 0.9.0 (#19320)
  [ty] Fix server version (#19284)
  Update NPM Development dependencies (#19319)
  Update taiki-e/install-action action to v2.56.13 (#19317)
  ...
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.

(🐞) lsp doesn't report the correct version

4 participants