Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ELS crash with debug build #491

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions crates/els/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}

pub(crate) fn recheck_file(
&mut self,
&self,
uri: NormalizedUrl,
code: impl Into<String>,
) -> ELSResult<()> {
Expand All @@ -99,11 +99,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
self.check_file(uri, code)
}

pub(crate) fn check_file(
&mut self,
uri: NormalizedUrl,
code: impl Into<String>,
) -> ELSResult<()> {
pub(crate) fn check_file(&self, uri: NormalizedUrl, code: impl Into<String>) -> ELSResult<()> {
_log!(self, "checking {uri}");
if self.file_cache.editing.borrow().contains(&uri) {
_log!(self, "skipped: {uri}");
Expand Down Expand Up @@ -182,7 +178,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}

// 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(());
Expand Down Expand Up @@ -213,7 +209,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
Ok(())
}

fn make_uri_and_diags(&mut self, errors: CompileErrors) -> Vec<(Url, Vec<Diagnostic>)> {
fn make_uri_and_diags(&self, errors: CompileErrors) -> Vec<(Url, Vec<Diagnostic>)> {
let mut uri_and_diags: Vec<(Url, Vec<Diagnostic>)> = vec![];
for err in errors.into_iter() {
let loc = err.core.get_loc_with_fallback();
Expand Down Expand Up @@ -297,7 +293,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {

/// 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 || {
Expand Down Expand Up @@ -357,7 +353,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
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 || {
Expand Down
2 changes: 1 addition & 1 deletion crates/els/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::server::{ELSResult, RedirectableStdout, Server};
use crate::util::{self, NormalizedUrl};

impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
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:?}"))?;
Expand Down
23 changes: 11 additions & 12 deletions crates/els/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}
}

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);
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}
}

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
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
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);
Expand All @@ -902,19 +902,18 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
))
}

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);
}

pub(crate) fn get_visitor(&self, uri: &NormalizedUrl) -> Option<HIRVisitor> {
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;
Expand Down Expand Up @@ -1048,7 +1047,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
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);
}
Expand All @@ -1058,12 +1057,12 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
&self.file_cache
}

pub fn remove_module_entry(&mut self, uri: &NormalizedUrl) -> Option<ModuleEntry> {
pub fn remove_module_entry(&self, uri: &NormalizedUrl) -> Option<ModuleEntry> {
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;
};
Expand Down
Loading