diff --git a/crates/cairo-lang-language-server/src/lib.rs b/crates/cairo-lang-language-server/src/lib.rs index dd358218dc4..109e57b4858 100644 --- a/crates/cairo-lang-language-server/src/lib.rs +++ b/crates/cairo-lang-language-server/src/lib.rs @@ -52,8 +52,7 @@ use cairo_lang_filesystem::ids::FileLongId; use cairo_lang_project::ProjectConfig; use cairo_lang_semantic::plugin::PluginSuite; use lsp_server::Message; -use lsp_types::{ClientCapabilities, RegistrationParams}; -use server::connection::ClientSender; +use lsp_types::RegistrationParams; use tracing::{debug, error, info, warn}; use crate::config::Config; @@ -67,7 +66,7 @@ use crate::lsp::result::LSPResult; use crate::project::ProjectManifestPath; use crate::project::scarb::update_crate_roots; use crate::project::unmanaged_core_crate::try_to_init_unmanaged_core; -use crate::server::client::{Client, Notifier, Requester, Responder}; +use crate::server::client::{Notifier, Requester, Responder}; use crate::server::connection::{Connection, ConnectionInitializer}; use crate::server::panic::is_cancelled; use crate::server::schedule::thread::JoinHandle; @@ -268,23 +267,11 @@ impl Backend { let server_capabilities = collect_server_capabilities(&client_capabilities); let connection = connection_initializer.initialize_finish(id, server_capabilities)?; - let state = Self::create_state(connection.make_sender(), client_capabilities, tricks); + let state = State::new(connection.make_sender(), client_capabilities, tricks); Ok(Self { connection, state }) } - fn create_state( - sender: ClientSender, - client_capabilities: ClientCapabilities, - tricks: Tricks, - ) -> State { - let db = AnalysisDatabase::new(&tricks); - let notifier = Client::new(sender).notifier(); - let scarb_toolchain = ScarbToolchain::new(notifier); - - State::new(db, client_capabilities, scarb_toolchain, tricks) - } - /// Runs the main event loop thread and wait for its completion. fn run(self) -> Result>> { event_loop_thread(move || { diff --git a/crates/cairo-lang-language-server/src/state.rs b/crates/cairo-lang-language-server/src/state.rs index 0cbb80d7646..60b1bf5ddf1 100644 --- a/crates/cairo-lang-language-server/src/state.rs +++ b/crates/cairo-lang-language-server/src/state.rs @@ -13,6 +13,8 @@ use crate::Tricks; use crate::config::Config; use crate::lang::db::{AnalysisDatabase, AnalysisDatabaseSwapper}; use crate::lang::diagnostics::DiagnosticsController; +use crate::server::client::Client; +use crate::server::connection::ClientSender; use crate::toolchain::scarb::ScarbToolchain; /// State of Language server. @@ -43,14 +45,16 @@ impl std::panic::UnwindSafe for FileDiagnostics {} impl State { pub fn new( - db: AnalysisDatabase, + sender: ClientSender, client_capabilities: ClientCapabilities, - scarb_toolchain: ScarbToolchain, tricks: Tricks, ) -> Self { + let notifier = Client::new(sender).notifier(); + let scarb_toolchain = ScarbToolchain::new(notifier); let db_swapper = AnalysisDatabaseSwapper::new(scarb_toolchain.clone()); + Self { - db, + db: AnalysisDatabase::new(&tricks), open_files: Default::default(), config: Default::default(), client_capabilities: Owned::new(client_capabilities.into()),