Merge #3430
3430: Fix completion snippet for reexported functions r=matklad a=flodiebold Fixes #3356. Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
ce69561be3
@ -784,4 +784,55 @@ fn main() {
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_reexported_items_under_correct_name() {
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
fn foo() {
|
||||
self::m::<|>
|
||||
}
|
||||
|
||||
mod m {
|
||||
pub use super::p::wrong_fn as right_fn;
|
||||
pub use super::p::WRONG_CONST as RIGHT_CONST;
|
||||
pub use super::p::WrongType as RightType;
|
||||
}
|
||||
mod p {
|
||||
fn wrong_fn() {}
|
||||
const WRONG_CONST: u32 = 1;
|
||||
struct WrongType {};
|
||||
}
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "RIGHT_CONST",
|
||||
source_range: [57; 57),
|
||||
delete: [57; 57),
|
||||
insert: "RIGHT_CONST",
|
||||
kind: Const,
|
||||
},
|
||||
CompletionItem {
|
||||
label: "RightType",
|
||||
source_range: [57; 57),
|
||||
delete: [57; 57),
|
||||
insert: "RightType",
|
||||
kind: Struct,
|
||||
},
|
||||
CompletionItem {
|
||||
label: "right_fn()",
|
||||
source_range: [57; 57),
|
||||
delete: [57; 57),
|
||||
insert: "right_fn()$0",
|
||||
kind: Function,
|
||||
lookup: "right_fn",
|
||||
detail: "fn wrong_fn()",
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -193,11 +193,10 @@ fn add_function_with_name(
|
||||
name: Option<String>,
|
||||
func: hir::Function,
|
||||
) {
|
||||
let func_name = func.name(ctx.db);
|
||||
let has_self_param = func.has_self_param(ctx.db);
|
||||
let params = func.params(ctx.db);
|
||||
|
||||
let name = name.unwrap_or_else(|| func_name.to_string());
|
||||
let name = name.unwrap_or_else(|| func.name(ctx.db).to_string());
|
||||
let ast_node = func.source(ctx.db).value;
|
||||
let detail = function_label(&ast_node);
|
||||
|
||||
@ -219,9 +218,9 @@ fn add_function_with_name(
|
||||
{
|
||||
tested_by!(inserts_parens_for_function_calls);
|
||||
let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 {
|
||||
(format!("{}()$0", func_name), format!("{}()", name))
|
||||
(format!("{}()$0", name), format!("{}()", name))
|
||||
} else {
|
||||
(format!("{}($0)", func_name), format!("{}(…)", name))
|
||||
(format!("{}($0)", name), format!("{}(…)", name))
|
||||
};
|
||||
builder = builder.lookup_by(name).label(label).insert_snippet(snippet);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user