From 2c8bf7ca1018129dec994a5de00b818117fba2f0 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 18 Feb 2024 11:26:15 +0900 Subject: [PATCH 1/3] chore: `Server::get_visitor` get or init --- crates/els/diagnostics.rs | 16 ++++++---------- crates/els/rename.rs | 2 +- crates/els/server.rs | 23 +++++++++++------------ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/crates/els/diagnostics.rs b/crates/els/diagnostics.rs index 409ff6890..69ed5b419 100644 --- a/crates/els/diagnostics.rs +++ b/crates/els/diagnostics.rs @@ -87,7 +87,7 @@ impl Server { } pub(crate) fn recheck_file( - &mut self, + &self, uri: NormalizedUrl, code: impl Into, ) -> ELSResult<()> { @@ -99,11 +99,7 @@ impl Server { self.check_file(uri, code) } - pub(crate) fn check_file( - &mut self, - uri: NormalizedUrl, - code: impl Into, - ) -> ELSResult<()> { + pub(crate) fn check_file(&self, uri: NormalizedUrl, code: impl Into) -> ELSResult<()> { _log!(self, "checking {uri}"); if self.file_cache.editing.borrow().contains(&uri) { _log!(self, "skipped: {uri}"); @@ -182,7 +178,7 @@ impl Server { } // TODO: reset mutable dependent types - pub(crate) fn quick_check_file(&mut self, uri: NormalizedUrl) -> ELSResult<()> { + pub(crate) fn quick_check_file(&self, uri: NormalizedUrl) -> ELSResult<()> { if self.file_cache.editing.borrow().contains(&uri) { _log!(self, "skipped: {uri}"); return Ok(()); @@ -213,7 +209,7 @@ impl Server { Ok(()) } - fn make_uri_and_diags(&mut self, errors: CompileErrors) -> Vec<(Url, Vec)> { + fn make_uri_and_diags(&self, errors: CompileErrors) -> Vec<(Url, Vec)> { let mut uri_and_diags: Vec<(Url, Vec)> = vec![]; for err in errors.into_iter() { let loc = err.core.get_loc_with_fallback(); @@ -297,7 +293,7 @@ impl Server { /// Periodically send diagnostics without a request from the server. /// This is necessary to perform reactive error highlighting in editors such as Vim, where no action is taken until the buffer is saved. - pub(crate) fn start_auto_diagnostics(&mut self) { + pub(crate) fn start_auto_diagnostics(&self) { let mut _self = self.clone(); spawn_new_thread( move || { @@ -357,7 +353,7 @@ impl Server { uris } - pub(crate) fn start_workspace_diagnostics(&mut self) { + pub(crate) fn start_workspace_diagnostics(&self) { let mut _self = self.clone(); spawn_new_thread( move || { diff --git a/crates/els/rename.rs b/crates/els/rename.rs index 0fb2e80e6..a7cfe35be 100644 --- a/crates/els/rename.rs +++ b/crates/els/rename.rs @@ -27,7 +27,7 @@ use crate::server::{ELSResult, RedirectableStdout, Server}; use crate::util::{self, NormalizedUrl}; impl Server { - pub(crate) fn rename(&mut self, msg: &Value) -> ELSResult<()> { + pub(crate) fn rename(&self, msg: &Value) -> ELSResult<()> { let params = RenameParams::deserialize(&msg["params"])?; let id = msg["id"].as_i64().unwrap(); self.send_log(format!("rename request: {params:?}"))?; diff --git a/crates/els/server.rs b/crates/els/server.rs index cb30305fd..73b810328 100644 --- a/crates/els/server.rs +++ b/crates/els/server.rs @@ -790,7 +790,7 @@ impl Server { } } - fn handle_notification(&mut self, msg: &Value, method: &str) -> ELSResult<()> { + fn handle_notification(&self, msg: &Value, method: &str) -> ELSResult<()> { match method { "initialized" => { self.flags.client_initialized.store(true, Ordering::Relaxed); @@ -845,7 +845,7 @@ impl Server { } } - fn handle_response(&mut self, id: i64, msg: &Value) -> ELSResult<()> { + fn handle_response(&self, id: i64, msg: &Value) -> ELSResult<()> { match id { HEALTH_CHECKER_ID => { self.channels @@ -887,7 +887,7 @@ impl Server { Checker::inherit(self.cfg.inherit(path), shared) } - pub(crate) fn steal_lowerer(&mut self, uri: &NormalizedUrl) -> Option<(ASTLowerer, IRs)> { + pub(crate) fn steal_lowerer(&self, uri: &NormalizedUrl) -> Option<(ASTLowerer, IRs)> { let path = uri.to_file_path().ok()?; let module = self.shared.remove_module(&path)?; let lowerer = ASTLowerer::new_with_ctx(module.module); @@ -897,12 +897,7 @@ impl Server { )) } - pub(crate) fn restore_lowerer( - &mut self, - uri: NormalizedUrl, - mut lowerer: ASTLowerer, - irs: IRs, - ) { + pub(crate) fn restore_lowerer(&self, uri: NormalizedUrl, mut lowerer: ASTLowerer, irs: IRs) { let module = lowerer.pop_mod_ctx().unwrap(); let entry = ModuleEntry::new(irs.id, irs.ast, irs.hir, module, irs.status); self.restore_entry(uri, entry); @@ -910,6 +905,10 @@ impl Server { pub(crate) fn get_visitor(&self, uri: &NormalizedUrl) -> Option { let path = uri.to_file_path().ok()?; + if self.shared.get_module(&path).is_none() && path.exists() { + let code = self.file_cache.get_entire_code(uri).ok()?; + let _ = self.check_file(uri.clone(), code); + } let Some(ent) = self.shared.get_module(&path) else { _log!(self, "module not found: {uri}"); return None; @@ -1037,7 +1036,7 @@ impl Server { self.shared.raw_ref_builtins_ctx().map(|mc| &mc.context) } - pub(crate) fn clear_cache(&mut self, uri: &NormalizedUrl) { + pub(crate) fn clear_cache(&self, uri: &NormalizedUrl) { let path = NormalizedPathBuf::from(util::uri_to_path(uri)); self.shared.clear(&path); } @@ -1047,12 +1046,12 @@ impl Server { &self.file_cache } - pub fn remove_module_entry(&mut self, uri: &NormalizedUrl) -> Option { + pub fn remove_module_entry(&self, uri: &NormalizedUrl) -> Option { let path = uri.to_file_path().ok()?; self.shared.remove_module(&path) } - pub fn insert_module_entry(&mut self, uri: NormalizedUrl, entry: ModuleEntry) { + pub fn insert_module_entry(&self, uri: NormalizedUrl, entry: ModuleEntry) { let Ok(path) = uri.to_file_path() else { return; }; From 3ae5206f35182eee860c4a74ed7ab492accd043d Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 18 Feb 2024 11:48:11 +0900 Subject: [PATCH 2/3] chore: relax timeout with debug-release --- crates/erg_common/shared.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/erg_common/shared.rs b/crates/erg_common/shared.rs index 46650cb96..59d8f7b45 100644 --- a/crates/erg_common/shared.rs +++ b/crates/erg_common/shared.rs @@ -12,8 +12,16 @@ use std::time::Duration; use thread_local::ThreadLocal; -const GET_TIMEOUT: Duration = Duration::from_secs(4); -const SET_TIMEOUT: Duration = Duration::from_secs(8); +const GET_TIMEOUT: Duration = if cfg!(debug_assertions) { + Duration::from_secs(32) +} else { + Duration::from_secs(4) +}; +const SET_TIMEOUT: Duration = if cfg!(debug_assertions) { + Duration::from_secs(64) +} else { + Duration::from_secs(8) +}; #[derive(Debug)] pub struct BorrowInfo { From 61cc9d17753d6486473fca6cb4be1255cdd97b9a Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 18 Feb 2024 12:02:07 +0900 Subject: [PATCH 3/3] Revert "chore: relax timeout with debug-release" This reverts commit 3ae5206f35182eee860c4a74ed7ab492accd043d. --- crates/erg_common/shared.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/erg_common/shared.rs b/crates/erg_common/shared.rs index 59d8f7b45..46650cb96 100644 --- a/crates/erg_common/shared.rs +++ b/crates/erg_common/shared.rs @@ -12,16 +12,8 @@ use std::time::Duration; use thread_local::ThreadLocal; -const GET_TIMEOUT: Duration = if cfg!(debug_assertions) { - Duration::from_secs(32) -} else { - Duration::from_secs(4) -}; -const SET_TIMEOUT: Duration = if cfg!(debug_assertions) { - Duration::from_secs(64) -} else { - Duration::from_secs(8) -}; +const GET_TIMEOUT: Duration = Duration::from_secs(4); +const SET_TIMEOUT: Duration = Duration::from_secs(8); #[derive(Debug)] pub struct BorrowInfo {