mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-15 06:45:23 +00:00
wip
This commit is contained in:
parent
48dacb277c
commit
588b38c8c6
3 changed files with 0 additions and 65 deletions
|
@ -1,22 +0,0 @@
|
||||||
use salsa::Database;
|
|
||||||
|
|
||||||
#[salsa::db]
|
|
||||||
#[derive(Clone, Default)]
|
|
||||||
pub struct ServerDatabase {
|
|
||||||
storage: salsa::Storage<Self>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ServerDatabase {
|
|
||||||
/// Create a new database from storage
|
|
||||||
pub fn new(storage: salsa::Storage<Self>) -> 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 {}
|
|
|
@ -1,5 +1,4 @@
|
||||||
mod client;
|
mod client;
|
||||||
mod db;
|
|
||||||
mod logging;
|
mod logging;
|
||||||
mod queue;
|
mod queue;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use djls_conf::Settings;
|
use djls_conf::Settings;
|
||||||
use djls_project::DjangoProject;
|
use djls_project::DjangoProject;
|
||||||
use salsa::StorageHandle;
|
|
||||||
use tower_lsp_server::lsp_types::ClientCapabilities;
|
use tower_lsp_server::lsp_types::ClientCapabilities;
|
||||||
use tower_lsp_server::lsp_types::InitializeParams;
|
use tower_lsp_server::lsp_types::InitializeParams;
|
||||||
|
|
||||||
use crate::db::ServerDatabase;
|
|
||||||
use crate::workspace::Store;
|
use crate::workspace::Store;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -15,36 +13,6 @@ pub struct Session {
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
client_capabilities: ClientCapabilities,
|
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<ServerDatabase>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
|
@ -67,7 +35,6 @@ impl Session {
|
||||||
project,
|
project,
|
||||||
documents: Store::default(),
|
documents: Store::default(),
|
||||||
settings,
|
settings,
|
||||||
db_handle: StorageHandle::new(None),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +61,4 @@ impl Session {
|
||||||
pub fn set_settings(&mut self, settings: Settings) {
|
pub fn set_settings(&mut self, settings: Settings) {
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue