-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| use crate::NotebookDocument; | ||||||
| use crate::session::index::Document; | ||||||
| use crate::system::LSPSystem; | ||||||
| use ruff_db::Db as _; | ||||||
| use ruff_db::files::{File, FilePath}; | ||||||
| use ty_project::{Db as ProjectDb, ProjectDatabase}; | ||||||
|
|
||||||
| #[salsa::db] | ||||||
| pub(crate) trait Db: ProjectDb { | ||||||
|
Comment on lines
+6
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that you can always import
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thank you. |
||||||
| /// Returns the LSP [`Document`] corresponding to `File` or | ||||||
| /// `None` if the file isn't open in the editor. | ||||||
| fn document(&self, file: File) -> Option<&Document>; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Suggested change
and similar for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find |
||||||
|
|
||||||
| /// Returns the LSP [`NotebookDocument`] corresponding to `File` or | ||||||
| /// `None` if the file isn't open in the editor or if it isn't a notebook. | ||||||
| fn notebook_document(&self, file: File) -> Option<&NotebookDocument> { | ||||||
| self.document(file)?.as_notebook() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[salsa::db] | ||||||
| impl Db for ProjectDatabase { | ||||||
| fn document(&self, file: File) -> Option<&Document> { | ||||||
| self.system() | ||||||
| .as_any() | ||||||
| .downcast_ref::<LSPSystem>() | ||||||
| .and_then(|system| match file.path(self) { | ||||||
| FilePath::System(path) => system.system_path_to_document(path), | ||||||
| FilePath::SystemVirtual(path) => system.system_virtual_path_to_document(path), | ||||||
| FilePath::Vendored(_) => None, | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
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
ProgressReporterto take aProjectDatabaseas argument because we now need aty_server::Dbinstead of aty_project::Dbin the LSP.