mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #5219
5219: Cleanup dot completiont tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
9f754e0518
6 changed files with 697 additions and 1303 deletions
File diff suppressed because it is too large
Load diff
|
@ -35,6 +35,19 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Suggest .await syntax for types that implement Future trait
|
||||
if let Some(receiver) = &ctx.dot_receiver {
|
||||
if let Some(ty) = ctx.sema.type_of_expr(receiver) {
|
||||
if ty.impls_future(ctx.db) {
|
||||
CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
|
||||
.kind(CompletionItemKind::Keyword)
|
||||
.detail("expr.await")
|
||||
.insert_text("await")
|
||||
.add_to(acc);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
|
@ -490,4 +503,26 @@ Some multi-line comment<|>
|
|||
expect![[""]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_completion_await_impls_future() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs
|
||||
use std::future::*;
|
||||
struct A {}
|
||||
impl Future for A {}
|
||||
fn foo(a: A) { a.<|> }
|
||||
|
||||
//- /std/lib.rs
|
||||
pub mod future {
|
||||
#[lang = "future_trait"]
|
||||
pub trait Future {}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
kw await expr.await
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1205,6 +1205,45 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_super_super_completion() {
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
mod a {
|
||||
const A: usize = 0;
|
||||
|
||||
mod b {
|
||||
const B: usize = 0;
|
||||
|
||||
mod c {
|
||||
use super::super::<|>
|
||||
}
|
||||
}
|
||||
}
|
||||
",
|
||||
),
|
||||
@r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "A",
|
||||
source_range: 120..120,
|
||||
delete: 120..120,
|
||||
insert: "A",
|
||||
kind: Const,
|
||||
},
|
||||
CompletionItem {
|
||||
label: "b",
|
||||
source_range: 120..120,
|
||||
delete: 120..120,
|
||||
insert: "b",
|
||||
kind: Module,
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_reexported_items_under_correct_name() {
|
||||
assert_debug_snapshot!(
|
||||
|
|
|
@ -95,7 +95,7 @@ impl fmt::Debug for CompletionItem {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum CompletionScore {
|
||||
/// If only type match
|
||||
TypeMatch,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,15 +13,15 @@ use crate::{
|
|||
};
|
||||
|
||||
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
|
||||
do_completion_with_options(code, kind, &CompletionConfig::default())
|
||||
do_completion_with_config(code, kind, &CompletionConfig::default())
|
||||
}
|
||||
|
||||
pub(crate) fn do_completion_with_options(
|
||||
pub(crate) fn do_completion_with_config(
|
||||
code: &str,
|
||||
kind: CompletionKind,
|
||||
options: &CompletionConfig,
|
||||
config: &CompletionConfig,
|
||||
) -> Vec<CompletionItem> {
|
||||
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, options)
|
||||
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config)
|
||||
.into_iter()
|
||||
.filter(|c| c.completion_kind == kind)
|
||||
.collect();
|
||||
|
@ -30,15 +30,15 @@ pub(crate) fn do_completion_with_options(
|
|||
}
|
||||
|
||||
pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String {
|
||||
completion_list_with_options(code, kind, &CompletionConfig::default())
|
||||
completion_list_with_config(code, kind, &CompletionConfig::default())
|
||||
}
|
||||
|
||||
pub(crate) fn completion_list_with_options(
|
||||
pub(crate) fn completion_list_with_config(
|
||||
code: &str,
|
||||
kind: CompletionKind,
|
||||
options: &CompletionConfig,
|
||||
config: &CompletionConfig,
|
||||
) -> String {
|
||||
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, options)
|
||||
let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config)
|
||||
.into_iter()
|
||||
.filter(|c| c.completion_kind == kind)
|
||||
.collect();
|
||||
|
@ -92,7 +92,10 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec<CompletionItem> {
|
||||
pub(crate) fn get_all_completion_items(
|
||||
code: &str,
|
||||
options: &CompletionConfig,
|
||||
) -> Vec<CompletionItem> {
|
||||
let (analysis, position) = analysis_and_position(code);
|
||||
analysis.completions(options, position).unwrap().unwrap().into()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue