Skip to content

Commit

Permalink
LS: Remove Backend::create_state in favour of State::new (#6599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Draggu authored Nov 6, 2024
1 parent 2d2352f commit 5954d24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
19 changes: 3 additions & 16 deletions crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<JoinHandle<Result<()>>> {
event_loop_thread(move || {
Expand Down
10 changes: 7 additions & 3 deletions crates/cairo-lang-language-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()),
Expand Down

0 comments on commit 5954d24

Please sign in to comment.