diff --git a/crates/djls-server/src/db.rs b/crates/djls-server/src/db.rs deleted file mode 100644 index f6e4c33..0000000 --- a/crates/djls-server/src/db.rs +++ /dev/null @@ -1,22 +0,0 @@ -use salsa::Database; - -#[salsa::db] -#[derive(Clone, Default)] -pub struct ServerDatabase { - storage: salsa::Storage, -} - -impl ServerDatabase { - /// Create a new database from storage - pub fn new(storage: salsa::Storage) -> Self { - Self { storage } - } -} - -impl std::fmt::Debug for ServerDatabase { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ServerDatabase").finish_non_exhaustive() - } -} - -impl Database for ServerDatabase {} diff --git a/crates/djls-server/src/lib.rs b/crates/djls-server/src/lib.rs index 57c433a..1ebe618 100644 --- a/crates/djls-server/src/lib.rs +++ b/crates/djls-server/src/lib.rs @@ -1,5 +1,4 @@ mod client; -mod db; mod logging; mod queue; mod server; diff --git a/crates/djls-server/src/session.rs b/crates/djls-server/src/session.rs index d4e8aaf..a5832cb 100644 --- a/crates/djls-server/src/session.rs +++ b/crates/djls-server/src/session.rs @@ -1,10 +1,8 @@ use djls_conf::Settings; use djls_project::DjangoProject; -use salsa::StorageHandle; use tower_lsp_server::lsp_types::ClientCapabilities; use tower_lsp_server::lsp_types::InitializeParams; -use crate::db::ServerDatabase; use crate::workspace::Store; #[derive(Default)] @@ -15,36 +13,6 @@ pub struct Session { #[allow(dead_code)] client_capabilities: ClientCapabilities, - - /// A thread-safe Salsa database handle that can be shared between threads. - /// - /// This implements the insight from [this Salsa Zulip discussion](https://salsa.zulipchat.com/#narrow/channel/145099-Using-Salsa/topic/.E2.9C.94.20Advice.20on.20using.20salsa.20from.20Sync.20.2B.20Send.20context/with/495497515) - /// where we're using the `StorageHandle` to create a thread-safe handle that can be - /// shared between threads. When we need to use it, we clone the handle to get a new reference. - /// - /// This handle allows us to create database instances as needed. - /// Even though we're using a single-threaded runtime, we still need - /// this to be thread-safe because of LSP trait requirements. - /// - /// Usage: - /// ```rust,ignore - /// // Use the StorageHandle in Session - /// let db_handle = StorageHandle::new(None); - /// - /// // Clone it to pass to different threads - /// let db_handle_clone = db_handle.clone(); - /// - /// // Use it in an async context - /// async_fn(move || { - /// // Get a database from the handle - /// let storage = db_handle_clone.into_storage(); - /// let db = ServerDatabase::new(storage); - /// - /// // Use the database - /// db.some_query(args) - /// }); - /// ``` - db_handle: StorageHandle, } impl Session { @@ -67,7 +35,6 @@ impl Session { project, documents: Store::default(), settings, - db_handle: StorageHandle::new(None), } } @@ -94,13 +61,4 @@ impl Session { pub fn set_settings(&mut self, settings: Settings) { self.settings = settings; } - - /// Get a database instance directly from the session - /// - /// This creates a usable database from the handle, which can be used - /// to query and update data in the database. - pub fn db(&self) -> ServerDatabase { - let storage = self.db_handle.clone().into_storage(); - ServerDatabase::new(storage) - } }