mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
fix: remove unwrap
This commit is contained in:
parent
a7f77d89a9
commit
45ee88f9cb
1 changed files with 31 additions and 24 deletions
|
@ -89,31 +89,38 @@ fn add_import(
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
edit: &mut ide_db::source_change::SourceChangeBuilder,
|
edit: &mut ide_db::source_change::SourceChangeBuilder,
|
||||||
) {
|
) {
|
||||||
// for `<i32 as std::ops::Add>`
|
if let Some(path_segment) = qualifier.segment() {
|
||||||
let path_type =
|
// for `<i32 as std::ops::Add>`
|
||||||
qualifier.segment().unwrap().syntax().children().filter_map(ast::PathType::cast).last();
|
let path_type = path_segment.syntax().children().filter_map(ast::PathType::cast).last();
|
||||||
let import = match path_type {
|
let import = match path_type {
|
||||||
Some(it) => it.path().unwrap(),
|
Some(it) => {
|
||||||
None => qualifier,
|
if let Some(path) = it.path() {
|
||||||
};
|
path
|
||||||
|
} else {
|
||||||
// in case for `<_>`
|
return;
|
||||||
if import.coloncolon_token().is_none() {
|
}
|
||||||
return;
|
}
|
||||||
}
|
None => qualifier,
|
||||||
|
|
||||||
let scope = ide_db::imports::insert_use::ImportScope::find_insert_use_container(
|
|
||||||
import.syntax(),
|
|
||||||
&ctx.sema,
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(scope) = scope {
|
|
||||||
let scope = match scope {
|
|
||||||
ImportScope::File(it) => ImportScope::File(edit.make_mut(it)),
|
|
||||||
ImportScope::Module(it) => ImportScope::Module(edit.make_mut(it)),
|
|
||||||
ImportScope::Block(it) => ImportScope::Block(edit.make_mut(it)),
|
|
||||||
};
|
};
|
||||||
ide_db::imports::insert_use::insert_use(&scope, import, &ctx.config.insert_use);
|
|
||||||
|
// in case for `<_>`
|
||||||
|
if import.coloncolon_token().is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let scope = ide_db::imports::insert_use::ImportScope::find_insert_use_container(
|
||||||
|
import.syntax(),
|
||||||
|
&ctx.sema,
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(scope) = scope {
|
||||||
|
let scope = match scope {
|
||||||
|
ImportScope::File(it) => ImportScope::File(edit.make_mut(it)),
|
||||||
|
ImportScope::Module(it) => ImportScope::Module(edit.make_mut(it)),
|
||||||
|
ImportScope::Block(it) => ImportScope::Block(edit.make_mut(it)),
|
||||||
|
};
|
||||||
|
ide_db::imports::insert_use::insert_use(&scope, import, &ctx.config.insert_use);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue