mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-27 04:19:22 +00:00
change server session to be an option and create on init (#154)
This commit is contained in:
parent
11ef05dddf
commit
b71dfe5eb7
2 changed files with 135 additions and 114 deletions
|
@ -2,17 +2,20 @@ 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::documents::Store;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Session {
|
||||
client_capabilities: Option<ClientCapabilities>,
|
||||
project: Option<DjangoProject>,
|
||||
documents: Store,
|
||||
settings: Settings,
|
||||
|
||||
#[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)
|
||||
|
@ -45,8 +48,27 @@ pub struct Session {
|
|||
}
|
||||
|
||||
impl Session {
|
||||
pub fn set_client_capabilities(&mut self, client_capabilities: ClientCapabilities) {
|
||||
self.client_capabilities = Some(client_capabilities);
|
||||
pub fn new(params: &InitializeParams) -> Self {
|
||||
let project_path = crate::workspace::get_project_path(params);
|
||||
|
||||
let (project, settings) = if let Some(path) = &project_path {
|
||||
let settings =
|
||||
djls_conf::Settings::new(path).unwrap_or_else(|_| djls_conf::Settings::default());
|
||||
|
||||
let project = Some(djls_project::DjangoProject::new(path.clone()));
|
||||
|
||||
(project, settings)
|
||||
} else {
|
||||
(None, Settings::default())
|
||||
};
|
||||
|
||||
Self {
|
||||
client_capabilities: params.capabilities.clone(),
|
||||
project,
|
||||
documents: Store::default(),
|
||||
settings,
|
||||
db_handle: StorageHandle::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn project(&self) -> Option<&DjangoProject> {
|
||||
|
@ -56,9 +78,6 @@ impl Session {
|
|||
pub fn project_mut(&mut self) -> &mut Option<DjangoProject> {
|
||||
&mut self.project
|
||||
}
|
||||
pub fn set_project(&mut self, project: DjangoProject) {
|
||||
self.project = Some(project);
|
||||
}
|
||||
|
||||
pub fn documents(&self) -> &Store {
|
||||
&self.documents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue