mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
add 'for' postfix completion
This commit is contained in:
parent
60e304c7b6
commit
7bae9c9187
2 changed files with 20 additions and 1 deletions
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
mod format_like;
|
mod format_like;
|
||||||
|
|
||||||
use ide_db::{helpers::SnippetCap, ty_filter::TryEnum};
|
use ide_db::{
|
||||||
|
helpers::{FamousDefs, SnippetCap},
|
||||||
|
ty_filter::TryEnum,
|
||||||
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AstToken},
|
ast::{self, AstNode, AstToken},
|
||||||
SyntaxKind::{BLOCK_EXPR, EXPR_STMT},
|
SyntaxKind::{BLOCK_EXPR, EXPR_STMT},
|
||||||
|
@ -110,6 +113,18 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
postfix_snippet(ctx, cap, dot_receiver, "not", "!expr", &format!("!{}", receiver_text))
|
postfix_snippet(ctx, cap, dot_receiver, "not", "!expr", &format!("!{}", receiver_text))
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
|
} else if let Some(trait_) = FamousDefs(&ctx.sema, ctx.krate).core_iter_IntoIterator() {
|
||||||
|
if receiver_ty.impls_trait(ctx.db, trait_, &[]) {
|
||||||
|
postfix_snippet(
|
||||||
|
ctx,
|
||||||
|
cap,
|
||||||
|
dot_receiver,
|
||||||
|
"for",
|
||||||
|
"for ele in expr {}",
|
||||||
|
&format!("for ele in {} {{\n $0\n}}", receiver_text),
|
||||||
|
)
|
||||||
|
.add_to(acc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postfix_snippet(ctx, cap, dot_receiver, "ref", "&expr", &format!("&{}", receiver_text))
|
postfix_snippet(ctx, cap, dot_receiver, "ref", "&expr", &format!("&{}", receiver_text))
|
||||||
|
|
|
@ -134,6 +134,10 @@ impl FamousDefs<'_, '_> {
|
||||||
self.find_trait("core:iter:traits:iterator:Iterator")
|
self.find_trait("core:iter:traits:iterator:Iterator")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn core_iter_IntoIterator(&self) -> Option<Trait> {
|
||||||
|
self.find_trait("core:iter:traits:collect:IntoIterator")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn core_iter(&self) -> Option<Module> {
|
pub fn core_iter(&self) -> Option<Module> {
|
||||||
self.find_module("core:iter")
|
self.find_module("core:iter")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue