mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
place complete_use_tree_keyword in the same mod with complete_expr_keyword
This commit is contained in:
parent
9895529d5c
commit
39dab68404
3 changed files with 67 additions and 77 deletions
|
@ -7,7 +7,6 @@ mod complete_keyword;
|
||||||
mod complete_snippet;
|
mod complete_snippet;
|
||||||
mod complete_path;
|
mod complete_path;
|
||||||
mod complete_scope;
|
mod complete_scope;
|
||||||
mod complete_use_tree;
|
|
||||||
|
|
||||||
use ra_db::SyntaxDatabase;
|
use ra_db::SyntaxDatabase;
|
||||||
|
|
||||||
|
@ -41,12 +40,12 @@ pub(crate) fn completions(
|
||||||
|
|
||||||
complete_fn_param::complete_fn_param(&mut acc, &ctx);
|
complete_fn_param::complete_fn_param(&mut acc, &ctx);
|
||||||
complete_keyword::complete_expr_keyword(&mut acc, &ctx);
|
complete_keyword::complete_expr_keyword(&mut acc, &ctx);
|
||||||
|
complete_keyword::complete_use_tree_keyword(&mut acc, &ctx);
|
||||||
complete_snippet::complete_expr_snippet(&mut acc, &ctx);
|
complete_snippet::complete_expr_snippet(&mut acc, &ctx);
|
||||||
complete_snippet::complete_item_snippet(&mut acc, &ctx);
|
complete_snippet::complete_item_snippet(&mut acc, &ctx);
|
||||||
complete_path::complete_path(&mut acc, &ctx)?;
|
complete_path::complete_path(&mut acc, &ctx)?;
|
||||||
complete_scope::complete_scope(&mut acc, &ctx)?;
|
complete_scope::complete_scope(&mut acc, &ctx)?;
|
||||||
complete_dot::complete_dot(&mut acc, &ctx)?;
|
complete_dot::complete_dot(&mut acc, &ctx)?;
|
||||||
complete_use_tree::complete_use_tree_keyword(&mut acc, &ctx);
|
|
||||||
|
|
||||||
Ok(Some(acc))
|
Ok(Some(acc))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,38 @@ use ra_syntax::{
|
||||||
|
|
||||||
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
|
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
|
||||||
|
|
||||||
|
pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
|
// complete keyword "crate" in use stmt
|
||||||
|
match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) {
|
||||||
|
(Some(_), None) => {
|
||||||
|
CompletionItem::new(CompletionKind::Keyword, "crate")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.lookup_by("crate")
|
||||||
|
.snippet("crate::")
|
||||||
|
.add_to(acc);
|
||||||
|
CompletionItem::new(CompletionKind::Keyword, "self")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.lookup_by("self")
|
||||||
|
.add_to(acc);
|
||||||
|
CompletionItem::new(CompletionKind::Keyword, "super")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.lookup_by("super")
|
||||||
|
.add_to(acc);
|
||||||
|
}
|
||||||
|
(Some(_), Some(_)) => {
|
||||||
|
CompletionItem::new(CompletionKind::Keyword, "self")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.lookup_by("self")
|
||||||
|
.add_to(acc);
|
||||||
|
CompletionItem::new(CompletionKind::Keyword, "super")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.lookup_by("super")
|
||||||
|
.add_to(acc);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
||||||
CompletionItem::new(CompletionKind::Keyword, kw)
|
CompletionItem::new(CompletionKind::Keyword, kw)
|
||||||
.kind(CompletionItemKind::Keyword)
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
@ -80,6 +112,40 @@ mod tests {
|
||||||
check_completion(code, expected_completions, CompletionKind::Keyword);
|
check_completion(code, expected_completions, CompletionKind::Keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn completes_keywords_in_use_stmt() {
|
||||||
|
check_keyword_completion(
|
||||||
|
r"
|
||||||
|
use <|>
|
||||||
|
",
|
||||||
|
r#"
|
||||||
|
crate "crate" "crate::"
|
||||||
|
self "self"
|
||||||
|
super "super"
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
check_keyword_completion(
|
||||||
|
r"
|
||||||
|
use a::<|>
|
||||||
|
",
|
||||||
|
r#"
|
||||||
|
self "self"
|
||||||
|
super "super"
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
check_keyword_completion(
|
||||||
|
r"
|
||||||
|
use a::{b, <|>}
|
||||||
|
",
|
||||||
|
r#"
|
||||||
|
self "self"
|
||||||
|
super "super"
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_various_keywords_in_function() {
|
fn completes_various_keywords_in_function() {
|
||||||
check_keyword_completion(
|
check_keyword_completion(
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
|
|
||||||
|
|
||||||
pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) {
|
|
||||||
// complete keyword "crate" in use stmt
|
|
||||||
match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) {
|
|
||||||
(Some(_), None) => {
|
|
||||||
CompletionItem::new(CompletionKind::Keyword, "crate")
|
|
||||||
.kind(CompletionItemKind::Keyword)
|
|
||||||
.lookup_by("crate")
|
|
||||||
.snippet("crate::")
|
|
||||||
.add_to(acc);
|
|
||||||
CompletionItem::new(CompletionKind::Keyword, "self")
|
|
||||||
.kind(CompletionItemKind::Keyword)
|
|
||||||
.lookup_by("self")
|
|
||||||
.add_to(acc);
|
|
||||||
CompletionItem::new(CompletionKind::Keyword, "super")
|
|
||||||
.kind(CompletionItemKind::Keyword)
|
|
||||||
.lookup_by("super")
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
|
||||||
(Some(_), Some(_)) => {
|
|
||||||
CompletionItem::new(CompletionKind::Keyword, "self")
|
|
||||||
.kind(CompletionItemKind::Keyword)
|
|
||||||
.lookup_by("self")
|
|
||||||
.add_to(acc);
|
|
||||||
CompletionItem::new(CompletionKind::Keyword, "super")
|
|
||||||
.kind(CompletionItemKind::Keyword)
|
|
||||||
.lookup_by("super")
|
|
||||||
.add_to(acc);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::completion::{CompletionKind, check_completion};
|
|
||||||
fn check_keyword_completion(code: &str, expected_completions: &str) {
|
|
||||||
check_completion(code, expected_completions, CompletionKind::Keyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_keywords_in_use_stmt() {
|
|
||||||
check_keyword_completion(
|
|
||||||
r"
|
|
||||||
use <|>
|
|
||||||
",
|
|
||||||
r#"
|
|
||||||
crate "crate" "crate::"
|
|
||||||
self "self"
|
|
||||||
super "super"
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
|
|
||||||
check_keyword_completion(
|
|
||||||
r"
|
|
||||||
use a::<|>
|
|
||||||
",
|
|
||||||
r#"
|
|
||||||
self "self"
|
|
||||||
super "super"
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
|
|
||||||
check_keyword_completion(
|
|
||||||
r"
|
|
||||||
use a::{b, <|>}
|
|
||||||
",
|
|
||||||
r#"
|
|
||||||
self "self"
|
|
||||||
super "super"
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue