diff --git a/crates/els/code_action.rs b/crates/els/code_action.rs index 9e5fb594e..e42006cef 100644 --- a/crates/els/code_action.rs +++ b/crates/els/code_action.rs @@ -389,9 +389,11 @@ impl Server { .and_then(|index| index.get_refs(&def.sig.ident().vi.def_loc)) { for ref_ in index.referrers.iter() { + let Some(path) = ref_.module.as_ref() else { + continue; + }; let edit = TextEdit::new(util::loc_to_range(ref_.loc).unwrap(), code.clone()); - let uri = - NormalizedUrl::new(Url::from_file_path(ref_.module.as_ref().unwrap()).unwrap()); + let uri = NormalizedUrl::new(Url::from_file_path(path).unwrap()); changes.entry(uri.raw()).or_insert(vec![]).push(edit); } } diff --git a/crates/els/completion.rs b/crates/els/completion.rs index 21526aa99..0409fd7b6 100644 --- a/crates/els/completion.rs +++ b/crates/els/completion.rs @@ -431,7 +431,9 @@ impl Server { if vi.vis.is_private() { continue; } - let path = vi.def_loc.module.as_ref().unwrap(); + let Some(path) = vi.def_loc.module.as_ref() else { + continue; + }; let path = path.file_stem().unwrap().to_string_lossy(); let mut item = CompletionItem::new_simple( format!("{name} (import from {path})"), diff --git a/crates/els/definition.rs b/crates/els/definition.rs index 2a59c2524..89c091de1 100644 --- a/crates/els/definition.rs +++ b/crates/els/definition.rs @@ -71,9 +71,10 @@ impl Server { .and_then(|ctx| ctx.get_mod_with_t(mod_t)) .and_then(|mod_ctx| mod_ctx.get_var_info(token.inspect())) { - let def_uri = - Url::from_file_path(vi.def_loc.module.as_ref().unwrap()) - .unwrap(); + let Some(path) = vi.def_loc.module.as_ref() else { + return Ok(GotoDefinitionResponse::Array(vec![])); + }; + let def_uri = Url::from_file_path(path).unwrap(); let resp = GotoDefinitionResponse::Array(vec![ lsp_types::Location::new( def_uri,