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 d9306082f..5873b2d1b 100644 --- a/crates/els/server.rs +++ b/crates/els/server.rs @@ -791,7 +791,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); @@ -846,7 +846,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 @@ -892,7 +892,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); @@ -902,12 +902,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); @@ -915,6 +910,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; @@ -1048,7 +1047,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); } @@ -1058,12 +1057,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; };