Skip to content

Commit

Permalink
fix(els): eliminate unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jun 23, 2023
1 parent 456cc45 commit 55cce38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions crates/els/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
.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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/els/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
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})"),
Expand Down
7 changes: 4 additions & 3 deletions crates/els/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
.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,
Expand Down

0 comments on commit 55cce38

Please sign in to comment.