mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
use ctry
This commit is contained in:
parent
f4860870da
commit
aa7fd563a4
4 changed files with 13 additions and 22 deletions
|
@ -38,10 +38,7 @@ pub(crate) fn completions(
|
||||||
original_file.reparse(&edit)
|
original_file.reparse(&edit)
|
||||||
};
|
};
|
||||||
|
|
||||||
let module = match ModuleDescriptor::guess_from_position(db, position)? {
|
let module = ctry!(ModuleDescriptor::guess_from_position(db, position)?);
|
||||||
None => return Ok(None),
|
|
||||||
Some(it) => it,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut has_completions = false;
|
let mut has_completions = false;
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
descriptors::{Path, PathKind, DescriptorDatabase},
|
descriptors::{Path, PathKind, DescriptorDatabase},
|
||||||
input::SourceRootId,
|
input::SourceRootId,
|
||||||
arena::{Arena, Id},
|
arena::{Arena, Id},
|
||||||
loc2id::DefLoc,
|
loc2id::{DefLoc, DefId},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use self::nameres::ModuleScope;
|
pub(crate) use self::nameres::ModuleScope;
|
||||||
|
@ -153,15 +153,6 @@ impl ModuleDescriptor {
|
||||||
db: &impl DescriptorDatabase,
|
db: &impl DescriptorDatabase,
|
||||||
path: Path,
|
path: Path,
|
||||||
) -> Cancelable<Option<ModuleDescriptor>> {
|
) -> Cancelable<Option<ModuleDescriptor>> {
|
||||||
macro_rules! ctry {
|
|
||||||
($expr:expr) => {
|
|
||||||
match $expr {
|
|
||||||
None => return Ok(None),
|
|
||||||
Some(it) => it,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut curr = match path.kind {
|
let mut curr = match path.kind {
|
||||||
PathKind::Crate => self.crate_root(),
|
PathKind::Crate => self.crate_root(),
|
||||||
PathKind::Self_ | PathKind::Plain => self.clone(),
|
PathKind::Self_ | PathKind::Plain => self.clone(),
|
||||||
|
|
|
@ -450,14 +450,8 @@ impl AnalysisImpl {
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
|
|
||||||
// Find the calling expression and it's NameRef
|
// Find the calling expression and it's NameRef
|
||||||
let calling_node = match FnCallNode::with_node(syntax, position.offset) {
|
let calling_node = ctry!(FnCallNode::with_node(syntax, position.offset));
|
||||||
Some(node) => node,
|
let name_ref = ctry!(calling_node.name_ref());
|
||||||
None => return Ok(None),
|
|
||||||
};
|
|
||||||
let name_ref = match calling_node.name_ref() {
|
|
||||||
Some(name) => name,
|
|
||||||
None => return Ok(None),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
||||||
let file_symbols = self.index_resolve(name_ref)?;
|
let file_symbols = self.index_resolve(name_ref)?;
|
||||||
|
|
|
@ -9,6 +9,15 @@ extern crate relative_path;
|
||||||
extern crate rustc_hash;
|
extern crate rustc_hash;
|
||||||
extern crate salsa;
|
extern crate salsa;
|
||||||
|
|
||||||
|
macro_rules! ctry {
|
||||||
|
($expr:expr) => {
|
||||||
|
match $expr {
|
||||||
|
None => return Ok(None),
|
||||||
|
Some(it) => it,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
mod arena;
|
mod arena;
|
||||||
mod db;
|
mod db;
|
||||||
mod loc2id;
|
mod loc2id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue