mirror of
https://github.com/tweag/nickel.git
synced 2024-10-06 16:18:08 +03:00
unwrap -> pattern matching
This commit is contained in:
parent
79a79ad742
commit
740efbad0e
@ -113,7 +113,7 @@ fn get_completion_identifiers(
|
|||||||
source: &str,
|
source: &str,
|
||||||
trigger: Option<&str>,
|
trigger: Option<&str>,
|
||||||
linearization: &Completed,
|
linearization: &Completed,
|
||||||
item: &LinearizationItem<Types>,
|
item: &LinearizationItem<Types>
|
||||||
) -> Result<Vec<CompletionItem>, ResponseError> {
|
) -> Result<Vec<CompletionItem>, ResponseError> {
|
||||||
let lin_env = &linearization.lin_env;
|
let lin_env = &linearization.lin_env;
|
||||||
let in_scope = match trigger {
|
let in_scope = match trigger {
|
||||||
@ -124,10 +124,9 @@ fn get_completion_identifiers(
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|(ident, _)| ident.label() == name)
|
.find(|(ident, _)| ident.label() == name)
|
||||||
.map(|(_, id)| *id);
|
.map(|(_, id)| *id);
|
||||||
// unsafe unwrap here
|
|
||||||
let name_id = name_id.unwrap();
|
|
||||||
|
|
||||||
linearization
|
match name_id {
|
||||||
|
Some(name_id) => linearization
|
||||||
.get_in_scope(item)
|
.get_in_scope(item)
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|i| {
|
.filter_map(|i| {
|
||||||
@ -147,7 +146,10 @@ fn get_completion_identifiers(
|
|||||||
// Get record fields from contract metadata
|
// Get record fields from contract metadata
|
||||||
TermKind::Declaration(_, _, ValueState::Known(body_id))
|
TermKind::Declaration(_, _, ValueState::Known(body_id))
|
||||||
if name_id == i.id
|
if name_id == i.id
|
||||||
&& find_record_contract(&linearization.linearization, body_id)
|
&& find_record_contract(
|
||||||
|
&linearization.linearization,
|
||||||
|
body_id,
|
||||||
|
)
|
||||||
.is_some() =>
|
.is_some() =>
|
||||||
{
|
{
|
||||||
// unwrapping is safe here because of the pattern condition.
|
// unwrapping is safe here because of the pattern condition.
|
||||||
@ -173,7 +175,9 @@ fn get_completion_identifiers(
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect(),
|
||||||
|
None => return Ok(Vec::new())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// variable name completion
|
// variable name completion
|
||||||
@ -220,6 +224,8 @@ pub fn handle_completion(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// -1 because at the current cursor position, there is no linearization item there,
|
||||||
|
// so we try to get the item just before the cursor.
|
||||||
let locator = (file_id, ByteIndex((start - 1) as u32));
|
let locator = (file_id, ByteIndex((start - 1) as u32));
|
||||||
let linearization = server.lin_cache_get(&file_id)?;
|
let linearization = server.lin_cache_get(&file_id)?;
|
||||||
// Cloning to avoid mutable borrow and shared borrow at the same time,
|
// Cloning to avoid mutable borrow and shared borrow at the same time,
|
||||||
|
Loading…
Reference in New Issue
Block a user