aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/add_function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/add_function.rs')
-rw-r--r--crates/ra_assists/src/handlers/add_function.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs
index 1d9d4e638..278079665 100644
--- a/crates/ra_assists/src/handlers/add_function.rs
+++ b/crates/ra_assists/src/handlers/add_function.rs
@@ -3,9 +3,10 @@ use ra_syntax::{
3 SyntaxKind, SyntaxNode, TextSize, 3 SyntaxKind, SyntaxNode, TextSize,
4}; 4};
5 5
6use crate::{Assist, AssistCtx, AssistFile, AssistId}; 6use crate::{Assist, AssistCtx, AssistId};
7use ast::{edit::IndentLevel, ArgListOwner, ModuleItemOwner}; 7use ast::{edit::IndentLevel, ArgListOwner, ModuleItemOwner};
8use hir::HirDisplay; 8use hir::HirDisplay;
9use ra_db::FileId;
9use rustc_hash::{FxHashMap, FxHashSet}; 10use rustc_hash::{FxHashMap, FxHashSet};
10 11
11// Assist: add_function 12// Assist: add_function
@@ -70,7 +71,7 @@ struct FunctionTemplate {
70 insert_offset: TextSize, 71 insert_offset: TextSize,
71 cursor_offset: TextSize, 72 cursor_offset: TextSize,
72 fn_def: ast::SourceFile, 73 fn_def: ast::SourceFile,
73 file: AssistFile, 74 file: FileId,
74} 75}
75 76
76struct FunctionBuilder { 77struct FunctionBuilder {
@@ -78,7 +79,7 @@ struct FunctionBuilder {
78 fn_name: ast::Name, 79 fn_name: ast::Name,
79 type_params: Option<ast::TypeParamList>, 80 type_params: Option<ast::TypeParamList>,
80 params: ast::ParamList, 81 params: ast::ParamList,
81 file: AssistFile, 82 file: FileId,
82 needs_pub: bool, 83 needs_pub: bool,
83} 84}
84 85
@@ -92,7 +93,7 @@ impl FunctionBuilder {
92 target_module: Option<hir::InFile<hir::ModuleSource>>, 93 target_module: Option<hir::InFile<hir::ModuleSource>>,
93 ) -> Option<Self> { 94 ) -> Option<Self> {
94 let needs_pub = target_module.is_some(); 95 let needs_pub = target_module.is_some();
95 let mut file = AssistFile::default(); 96 let mut file = ctx.frange.file_id;
96 let target = if let Some(target_module) = target_module { 97 let target = if let Some(target_module) = target_module {
97 let (in_file, target) = next_space_for_fn_in_module(ctx.sema.db, target_module)?; 98 let (in_file, target) = next_space_for_fn_in_module(ctx.sema.db, target_module)?;
98 file = in_file; 99 file = in_file;
@@ -253,9 +254,8 @@ fn next_space_for_fn_after_call_site(expr: &ast::CallExpr) -> Option<GeneratedFu
253fn next_space_for_fn_in_module( 254fn next_space_for_fn_in_module(
254 db: &dyn hir::db::AstDatabase, 255 db: &dyn hir::db::AstDatabase,
255 module: hir::InFile<hir::ModuleSource>, 256 module: hir::InFile<hir::ModuleSource>,
256) -> Option<(AssistFile, GeneratedFunctionTarget)> { 257) -> Option<(FileId, GeneratedFunctionTarget)> {
257 let file = module.file_id.original_file(db); 258 let file = module.file_id.original_file(db);
258 let assist_file = AssistFile::TargetFile(file);
259 let assist_item = match module.value { 259 let assist_item = match module.value {
260 hir::ModuleSource::SourceFile(it) => { 260 hir::ModuleSource::SourceFile(it) => {
261 if let Some(last_item) = it.items().last() { 261 if let Some(last_item) = it.items().last() {
@@ -272,7 +272,7 @@ fn next_space_for_fn_in_module(
272 } 272 }
273 } 273 }
274 }; 274 };
275 Some((assist_file, assist_item)) 275 Some((file, assist_item))
276} 276}
277 277
278#[cfg(test)] 278#[cfg(test)]