Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/generate_function.rs')
-rw-r--r--crates/ide-assists/src/handlers/generate_function.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs
index 7af2a2e1e6..824380253a 100644
--- a/crates/ide-assists/src/handlers/generate_function.rs
+++ b/crates/ide-assists/src/handlers/generate_function.rs
@@ -1,28 +1,29 @@
use hir::{
- Adt, AsAssocItem, HasSource, HirDisplay, HirFileIdExt, Module, PathResolution, Semantics,
- StructKind, Type, TypeInfo,
+ Adt, AsAssocItem, HasSource, HirDisplay, Module, PathResolution, Semantics, StructKind, Type,
+ TypeInfo,
};
use ide_db::{
+ FileId, FxHashMap, FxHashSet, RootDatabase, SnippetCap,
defs::{Definition, NameRefClass},
famous_defs::FamousDefs,
helpers::is_editable_crate,
path_transform::PathTransform,
source_change::SourceChangeBuilder,
- FileId, FxHashMap, FxHashSet, RootDatabase, SnippetCap,
};
use itertools::Itertools;
use stdx::to_lower_snake_case;
use syntax::{
+ Edition, SyntaxKind, SyntaxNode, T, TextRange,
ast::{
- self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, BlockExpr, CallExpr,
- HasArgList, HasGenericParams, HasModuleItem, HasTypeBounds,
+ self, AstNode, BlockExpr, CallExpr, HasArgList, HasGenericParams, HasModuleItem,
+ HasTypeBounds, edit::IndentLevel, edit_in_place::Indent, make,
},
- ted, Edition, SyntaxKind, SyntaxNode, TextRange, T,
+ ted,
};
use crate::{
+ AssistContext, AssistId, Assists,
utils::{convert_reference_type, find_struct_impl},
- AssistContext, AssistId, AssistKind, Assists,
};
// Assist: generate_function
@@ -171,16 +172,15 @@ fn add_func_to_accumulator(
adt_info: Option<AdtInfo>,
label: String,
) -> Option<()> {
- acc.add(AssistId("generate_function", AssistKind::Generate), label, text_range, |edit| {
+ acc.add(AssistId::generate("generate_function"), label, text_range, |edit| {
edit.edit_file(file);
let target = function_builder.target.clone();
let edition = function_builder.target_edition;
let func = function_builder.render(ctx.config.snippet_cap, edit);
- if let Some(adt) =
- adt_info
- .and_then(|adt_info| if adt_info.impl_exists { None } else { Some(adt_info.adt) })
+ if let Some(adt) = adt_info
+ .and_then(|adt_info| if adt_info.impl_exists { None } else { Some(adt_info.adt) })
{
let name = make::ty_path(make::ext::ident_path(&format!(
"{}",
@@ -205,11 +205,12 @@ fn get_adt_source(
fn_name: &str,
) -> Option<(Option<ast::Impl>, FileId)> {
let range = adt.source(ctx.sema.db)?.syntax().original_file_range_rooted(ctx.sema.db);
+
let file = ctx.sema.parse(range.file_id);
let adt_source =
ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?;
find_struct_impl(ctx, &adt_source, &[fn_name.to_owned()])
- .map(|impl_| (impl_, range.file_id.file_id()))
+ .map(|impl_| (impl_, range.file_id.file_id(ctx.db())))
}
struct FunctionBuilder {
@@ -470,7 +471,7 @@ fn make_fn_body_as_new_function(
.map(|_| placeholder_expr.clone())
.collect::<Vec<_>>();
- make::expr_call(make::expr_path(path_self), make::arg_list(args))
+ make::expr_call(make::expr_path(path_self), make::arg_list(args)).into()
}
StructKind::Unit => make::expr_path(path_self),
}
@@ -496,7 +497,7 @@ fn get_fn_target(
target_module: Option<Module>,
call: CallExpr,
) -> Option<(GeneratedFunctionTarget, FileId)> {
- let mut file = ctx.file_id().into();
+ let mut file = ctx.vfs_file_id();
let target = match target_module {
Some(target_module) => {
let (in_file, target) = next_space_for_fn_in_module(ctx.db(), target_module);
@@ -1161,7 +1162,7 @@ fn next_space_for_fn_in_module(
target_module: hir::Module,
) -> (FileId, GeneratedFunctionTarget) {
let module_source = target_module.definition_source(db);
- let file = module_source.file_id.original_file(db.upcast());
+ let file = module_source.file_id.original_file(db);
let assist_item = match &module_source.value {
hir::ModuleSource::SourceFile(it) => match it.items().last() {
Some(last_item) => GeneratedFunctionTarget::AfterItem(last_item.syntax().clone()),
@@ -1186,7 +1187,7 @@ fn next_space_for_fn_in_module(
}
};
- (file.file_id(), assist_item)
+ (file.file_id(db), assist_item)
}
#[derive(Clone, Copy)]