-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Add ty_server::Db trait
#21241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ty] Add ty_server::Db trait
#21241
Conversation
| } | ||
|
|
||
| fn report_checked_file(&self, db: &dyn Db, file: File, diagnostics: &[Diagnostic]) { | ||
| fn report_checked_file(&self, db: &ProjectDatabase, file: File, diagnostics: &[Diagnostic]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change the signature of ProgressReporter to take a ProjectDatabase as argument because we now need a ty_server::Db instead of a ty_project::Db in the LSP.
19309e0 to
4adcd15
Compare
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
CodSpeed Performance ReportMerging #21241 will not alter performanceComparing Summary
Footnotes
|
4adcd15 to
aaead0a
Compare
| use ty_project::{Db as ProjectDb, ProjectDatabase}; | ||
|
|
||
| #[salsa::db] | ||
| pub(crate) trait Db: ProjectDb { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this name shadowing here confusing. Is there another name that we could use for the trait here? I assume you named it Db to avoid all kinds of downstream changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that you can always import Db without having to think within which crate you're in (this is also how all our other Db traits are defined)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thank you.
|
|
||
| #[salsa::db] | ||
| pub(crate) trait Db: ProjectDb { | ||
| fn document(&self, file: File) -> Option<&Document>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
| fn document(&self, file: File) -> Option<&Document>; | |
| fn document_from_file(&self, file: File) -> Option<&Document>; |
and similar for notebook_document below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find from more confusing because From implies that there's a conversion at play. But that's not the case. The operation here is closer to a map.get(file) where map is a HashMap<File, Document>.
5662955 to
44ad219
Compare
Introduce a new Db trait in ty_server that extends ty_project::Db and adds server-specific database methods: - document(): Access to Document from the LSP index - notebook_document(): Convenient access to NotebookDocument This trait provides the foundation for notebook support by allowing the server to access document and notebook metadata through the database interface. Use ty_server::Db consistently throughout ty_server Replace all uses of ty_project::Db and ty_python_semantic::Db with crate::Db (ty_server::Db) for consistency. This ensures all code within ty_server uses the server-specific Db trait which extends ty_project::Db. Add ty_server::Db trait Introduce a new Db trait in ty_server that extends ty_project::Db and adds server-specific database methods: - document(): Access to Document from the LSP index - notebook_document(): Convenient access to NotebookDocument This trait provides the foundation for notebook support by allowing the server to access document and notebook metadata through the database interface. Use ty_server::Db consistently throughout ty_server Replace all uses of ty_project::Db and ty_python_semantic::Db with crate::Db (ty_server::Db) for consistency. This ensures all code within ty_server uses the server-specific Db trait which extends ty_project::Db.
aaead0a to
71115b3
Compare
* main: (188 commits) [ty] Discover site-packages from the environment that ty is installed in (astral-sh#21286) [ty] Make special cases for `UnionType` slightly narrower (astral-sh#21276) Require ignore 0.4.24 in `Cargo.toml` (astral-sh#21292) [ty] Favour imported symbols over builtin symbols (astral-sh#21285) docs: revise Ruff setup instructions for Zed editor (astral-sh#20935) [ty] Update salsa (astral-sh#21281) [syntax-error]: no binding for nonlocal PLE0117 as a semantic syntax error (astral-sh#21032) [ty] Constraining a typevar with itself (possibly via union or intersection) (astral-sh#21273) [`ruff`] Fix false positives on starred arguments (`RUF057`) (astral-sh#21256) [ty] Simplify unions containing multiple type variables during inference (astral-sh#21275) [ty] Add `ty_server::Db` trait (astral-sh#21241) [ty] Refactor `Range` to/from `TextRange` conversion as prep for notebook support (astral-sh#21230) [ty] Fix playground crash when file name includes path separator (astral-sh#21151) [`refurb`] Fix false negative for underscores before sign in `Decimal` constructor (`FURB157`) (astral-sh#21190) [ty] Allow values of type `None` in type expressions (astral-sh#21263) Run codspeed benchmarks with `profiling` profile (astral-sh#21261) [ty] Update expected diagnostic count in benchmarks (astral-sh#21269) Avoid extra parentheses for long `match` patterns with `as` captures (astral-sh#21176) [ty] Update salsa (astral-sh#21265) [ty] `dict` is not assignable to `TypedDict` (astral-sh#21238) ...
Summary
For notebooks, we'll need a way to query the metadata of an arbitrary notebook when mapping
e.g. the range of a find reference operation to the reference's location.
This PR introduces a new
Dbtrait and implements it forProjectDatabase.The new
Dbtrait allows quering the document metadata by path, assumingthat the
ProjectDatabaseuses theLSPSystem(which is always true).