Minor refactoring
This commit is contained in:
parent
b75803ad31
commit
0df70d37fc
@ -3139,15 +3139,15 @@ impl Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_closure(&self) -> bool {
|
pub fn is_closure(&self) -> bool {
|
||||||
matches!(&self.ty.kind(Interner), TyKind::Closure { .. })
|
matches!(self.ty.kind(Interner), TyKind::Closure { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_fn(&self) -> bool {
|
pub fn is_fn(&self) -> bool {
|
||||||
matches!(&self.ty.kind(Interner), TyKind::FnDef(..) | TyKind::Function { .. })
|
matches!(self.ty.kind(Interner), TyKind::FnDef(..) | TyKind::Function { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_array(&self) -> bool {
|
pub fn is_array(&self) -> bool {
|
||||||
matches!(&self.ty.kind(Interner), TyKind::Array(..))
|
matches!(self.ty.kind(Interner), TyKind::Array(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
|
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
|
||||||
@ -3164,7 +3164,7 @@ impl Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_raw_ptr(&self) -> bool {
|
pub fn is_raw_ptr(&self) -> bool {
|
||||||
matches!(&self.ty.kind(Interner), TyKind::Raw(..))
|
matches!(self.ty.kind(Interner), TyKind::Raw(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_unknown(&self) -> bool {
|
pub fn contains_unknown(&self) -> bool {
|
||||||
|
@ -1319,10 +1319,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
let _p = profile::span("Semantics::analyze_impl");
|
let _p = profile::span("Semantics::analyze_impl");
|
||||||
let node = self.find_file(node);
|
let node = self.find_file(node);
|
||||||
|
|
||||||
let container = match self.with_ctx(|ctx| ctx.find_container(node)) {
|
let container = self.with_ctx(|ctx| ctx.find_container(node))?;
|
||||||
Some(it) => it,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let resolver = match container {
|
let resolver = match container {
|
||||||
ChildContainer::DefWithBodyId(def) => {
|
ChildContainer::DefWithBodyId(def) => {
|
||||||
@ -1582,7 +1579,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
|
|||||||
node.ancestors().last().unwrap()
|
node.ancestors().last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `SemanticScope` encapsulates the notion of a scope (the set of visible
|
/// `SemanticsScope` encapsulates the notion of a scope (the set of visible
|
||||||
/// names) at a particular program point.
|
/// names) at a particular program point.
|
||||||
///
|
///
|
||||||
/// It is a bit tricky, as scopes do not really exist inside the compiler.
|
/// It is a bit tricky, as scopes do not really exist inside the compiler.
|
||||||
|
@ -16,8 +16,7 @@ use syntax::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::convert_reference_type,
|
utils::{convert_reference_type, find_struct_impl, render_snippet, Cursor},
|
||||||
utils::{find_struct_impl, render_snippet, Cursor},
|
|
||||||
AssistContext, AssistId, AssistKind, Assists,
|
AssistContext, AssistId, AssistKind, Assists,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ fn fn_target_info(
|
|||||||
match path.qualifier() {
|
match path.qualifier() {
|
||||||
Some(qualifier) => match ctx.sema.resolve_path(&qualifier) {
|
Some(qualifier) => match ctx.sema.resolve_path(&qualifier) {
|
||||||
Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) => {
|
Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) => {
|
||||||
get_fn_target_info(ctx, &Some(module), call.clone())
|
get_fn_target_info(ctx, Some(module), call.clone())
|
||||||
}
|
}
|
||||||
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
|
Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) => {
|
||||||
if let hir::Adt::Enum(_) = adt {
|
if let hir::Adt::Enum(_) = adt {
|
||||||
@ -125,7 +124,7 @@ fn fn_target_info(
|
|||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => get_fn_target_info(ctx, &None, call.clone()),
|
_ => get_fn_target_info(ctx, None, call.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,16 +395,16 @@ fn make_return_type(
|
|||||||
|
|
||||||
fn get_fn_target_info(
|
fn get_fn_target_info(
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
target_module: &Option<Module>,
|
target_module: Option<Module>,
|
||||||
call: CallExpr,
|
call: CallExpr,
|
||||||
) -> Option<TargetInfo> {
|
) -> Option<TargetInfo> {
|
||||||
let (target, file, insert_offset) = get_fn_target(ctx, target_module, call)?;
|
let (target, file, insert_offset) = get_fn_target(ctx, target_module, call)?;
|
||||||
Some(TargetInfo::new(*target_module, None, target, file, insert_offset))
|
Some(TargetInfo::new(target_module, None, target, file, insert_offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fn_target(
|
fn get_fn_target(
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
target_module: &Option<Module>,
|
target_module: Option<Module>,
|
||||||
call: CallExpr,
|
call: CallExpr,
|
||||||
) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> {
|
) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> {
|
||||||
let mut file = ctx.file_id();
|
let mut file = ctx.file_id();
|
||||||
@ -640,10 +639,11 @@ fn next_space_for_fn_in_module(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option<GeneratedFunctionTarget> {
|
fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option<GeneratedFunctionTarget> {
|
||||||
if let Some(last_item) = impl_.assoc_item_list().and_then(|it| it.assoc_items().last()) {
|
let assoc_item_list = impl_.assoc_item_list()?;
|
||||||
|
if let Some(last_item) = assoc_item_list.assoc_items().last() {
|
||||||
Some(GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()))
|
Some(GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()))
|
||||||
} else {
|
} else {
|
||||||
Some(GeneratedFunctionTarget::InEmptyItemList(impl_.assoc_item_list()?.syntax().clone()))
|
Some(GeneratedFunctionTarget::InEmptyItemList(assoc_item_list.syntax().clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user