mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
Merge #608
608: Complete parens r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
81fcfc55d2
@ -8,8 +8,6 @@
|
|||||||
pub mod db;
|
pub mod db;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mock;
|
mod mock;
|
||||||
#[cfg(test)]
|
|
||||||
mod marks;
|
|
||||||
mod query_definitions;
|
mod query_definitions;
|
||||||
mod path;
|
mod path;
|
||||||
pub mod source_binder;
|
pub mod source_binder;
|
||||||
@ -29,6 +27,9 @@ mod generics;
|
|||||||
mod code_model_api;
|
mod code_model_api;
|
||||||
mod code_model_impl;
|
mod code_model_impl;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod marks;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
name::{AsName, KnownName},
|
name::{AsName, KnownName},
|
||||||
|
@ -1 +1,3 @@
|
|||||||
test_utils::mark!(name_res_works_for_broken_modules);
|
use test_utils::mark;
|
||||||
|
|
||||||
|
mark!(name_res_works_for_broken_modules);
|
||||||
|
@ -121,30 +121,4 @@ mod tests {
|
|||||||
",
|
",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_render_function_parens_in_use_item() {
|
|
||||||
check_reference_completion(
|
|
||||||
"dont_render_function_parens_in_use_item",
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
mod m { pub fn foo() {} }
|
|
||||||
use crate::m::f<|>;
|
|
||||||
",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_render_function_parens_if_already_call() {
|
|
||||||
check_reference_completion(
|
|
||||||
"dont_render_function_parens_if_already_call",
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
fn frobnicate() {}
|
|
||||||
fn main() {
|
|
||||||
frob<|>();
|
|
||||||
}
|
|
||||||
",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -175,21 +175,4 @@ mod tests {
|
|||||||
check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }")
|
check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn inserts_parens_for_function_calls() {
|
|
||||||
check_reference_completion(
|
|
||||||
"inserts_parens_for_function_calls1",
|
|
||||||
r"
|
|
||||||
fn no_args() {}
|
|
||||||
fn main() { no_<|> }
|
|
||||||
",
|
|
||||||
);
|
|
||||||
check_reference_completion(
|
|
||||||
"inserts_parens_for_function_calls2",
|
|
||||||
r"
|
|
||||||
fn with_args(x: i32, y: String) {}
|
|
||||||
fn main() { with_<|> }
|
|
||||||
",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,10 @@ use hir::PerNs;
|
|||||||
use crate::completion::completion_context::CompletionContext;
|
use crate::completion::completion_context::CompletionContext;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
TextRange
|
TextRange,
|
||||||
};
|
};
|
||||||
use ra_text_edit::TextEdit;
|
use ra_text_edit::TextEdit;
|
||||||
|
use test_utils::tested_by;
|
||||||
|
|
||||||
/// `CompletionItem` describes a single completion variant in the editor pop-up.
|
/// `CompletionItem` describes a single completion variant in the editor pop-up.
|
||||||
/// It is basically a POD with various properties. To construct a
|
/// It is basically a POD with various properties. To construct a
|
||||||
@ -255,7 +256,9 @@ impl Builder {
|
|||||||
) -> Builder {
|
) -> Builder {
|
||||||
// If not an import, add parenthesis automatically.
|
// If not an import, add parenthesis automatically.
|
||||||
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
if ctx.use_item_syntax.is_none() && !ctx.is_call {
|
||||||
if function.signature(ctx.db).params().is_empty() {
|
tested_by!(inserts_parens_for_function_calls);
|
||||||
|
let sig = function.signature(ctx.db);
|
||||||
|
if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 {
|
||||||
self.insert_text = Some(format!("{}()$0", self.label));
|
self.insert_text = Some(format!("{}()$0", self.label));
|
||||||
} else {
|
} else {
|
||||||
self.insert_text = Some(format!("{}($0)", self.label));
|
self.insert_text = Some(format!("{}($0)", self.label));
|
||||||
@ -344,3 +347,72 @@ pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind
|
|||||||
.collect();
|
.collect();
|
||||||
assert_debug_snapshot_matches!(test_name, kind_completions);
|
assert_debug_snapshot_matches!(test_name, kind_completions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use test_utils::covers;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn check_reference_completion(code: &str, expected_completions: &str) {
|
||||||
|
check_completion(code, expected_completions, CompletionKind::Reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inserts_parens_for_function_calls() {
|
||||||
|
covers!(inserts_parens_for_function_calls);
|
||||||
|
check_reference_completion(
|
||||||
|
"inserts_parens_for_function_calls1",
|
||||||
|
r"
|
||||||
|
fn no_args() {}
|
||||||
|
fn main() { no_<|> }
|
||||||
|
",
|
||||||
|
);
|
||||||
|
check_reference_completion(
|
||||||
|
"inserts_parens_for_function_calls2",
|
||||||
|
r"
|
||||||
|
fn with_args(x: i32, y: String) {}
|
||||||
|
fn main() { with_<|> }
|
||||||
|
",
|
||||||
|
);
|
||||||
|
check_reference_completion(
|
||||||
|
"inserts_parens_for_function_calls3",
|
||||||
|
r"
|
||||||
|
struct S {}
|
||||||
|
impl S {
|
||||||
|
fn foo(&self) {}
|
||||||
|
}
|
||||||
|
fn bar(s: &S) {
|
||||||
|
s.f<|>
|
||||||
|
}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dont_render_function_parens_in_use_item() {
|
||||||
|
check_reference_completion(
|
||||||
|
"dont_render_function_parens_in_use_item",
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod m { pub fn foo() {} }
|
||||||
|
use crate::m::f<|>;
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dont_render_function_parens_if_already_call() {
|
||||||
|
check_reference_completion(
|
||||||
|
"dont_render_function_parens_if_already_call",
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
fn frobnicate() {}
|
||||||
|
fn main() {
|
||||||
|
frob<|>();
|
||||||
|
}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
created: "2019-01-23T13:19:23.525922020+00:00"
|
||||||
|
creator: insta@0.5.2
|
||||||
|
expression: kind_completions
|
||||||
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
|
---
|
||||||
|
[
|
||||||
|
CompletionItem {
|
||||||
|
completion_kind: Reference,
|
||||||
|
label: "foo",
|
||||||
|
kind: Some(
|
||||||
|
Method
|
||||||
|
),
|
||||||
|
detail: Some(
|
||||||
|
"fn foo(&self)"
|
||||||
|
),
|
||||||
|
documentation: None,
|
||||||
|
lookup: None,
|
||||||
|
insert_text: Some(
|
||||||
|
"foo()$0"
|
||||||
|
),
|
||||||
|
insert_text_format: Snippet,
|
||||||
|
source_range: [139; 140),
|
||||||
|
text_edit: None
|
||||||
|
}
|
||||||
|
]
|
@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501258181+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
@ -17,7 +17,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
|||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"the_method($0)"
|
"the_method()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [144; 144),
|
source_range: [144; 144),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501353210+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
|||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"foo($0)"
|
"foo()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [126; 126),
|
source_range: [126; 126),
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
created: "2019-01-23T13:19:23.501297515+00:00"
|
||||||
creator: insta@0.4.0
|
creator: insta@0.5.2
|
||||||
expression: kind_completions
|
expression: kind_completions
|
||||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
source: crates/ra_ide_api/src/completion/completion_item.rs
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
@ -33,7 +33,7 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
|||||||
documentation: None,
|
documentation: None,
|
||||||
lookup: None,
|
lookup: None,
|
||||||
insert_text: Some(
|
insert_text: Some(
|
||||||
"foo($0)"
|
"foo()$0"
|
||||||
),
|
),
|
||||||
insert_text_format: Snippet,
|
insert_text_format: Snippet,
|
||||||
source_range: [121; 121),
|
source_range: [121; 121),
|
||||||
|
@ -26,6 +26,9 @@ mod syntax_highlighting;
|
|||||||
mod parent_module;
|
mod parent_module;
|
||||||
mod rename;
|
mod rename;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod marks;
|
||||||
|
|
||||||
use std::{fmt, sync::Arc};
|
use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
|
use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
|
||||||
|
3
crates/ra_ide_api/src/marks.rs
Normal file
3
crates/ra_ide_api/src/marks.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
use test_utils::mark;
|
||||||
|
|
||||||
|
mark!(inserts_parens_for_function_calls);
|
Loading…
Reference in New Issue
Block a user