mirror of https://github.com/rust-lang/rust.git
cleanup
This commit is contained in:
parent
25dda42f37
commit
284e894069
|
@ -5,7 +5,13 @@ use ra_syntax::{
|
|||
SyntaxKind::*, SyntaxNodeRef,
|
||||
};
|
||||
|
||||
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind::*};
|
||||
use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind};
|
||||
|
||||
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
||||
CompletionItem::new(CompletionKind::Keyword, kw)
|
||||
.snippet(snippet)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
if !ctx.is_trivial_path {
|
||||
|
@ -60,10 +66,6 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option<CompletionItem>
|
|||
Some(keyword("return", snip))
|
||||
}
|
||||
|
||||
fn keyword(kw: &str, snippet: &str) -> CompletionItem {
|
||||
CompletionItem::new(Keyword, kw).snippet(snippet).build()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::completion::{CompletionKind, check_completion};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
Cancelable,
|
||||
completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext},
|
||||
completion::{CompletionItem, Completions, CompletionKind, CompletionContext},
|
||||
};
|
||||
|
||||
pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> {
|
||||
|
@ -17,9 +17,9 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
|
|||
_ => return Ok(()),
|
||||
};
|
||||
let module_scope = target_module.scope(ctx.db)?;
|
||||
module_scope
|
||||
.entries()
|
||||
.for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc));
|
||||
module_scope.entries().for_each(|(name, _res)| {
|
||||
CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc)
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use ra_syntax::TextUnit;
|
|||
|
||||
use crate::{
|
||||
Cancelable,
|
||||
completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext},
|
||||
completion::{CompletionItem, Completions, CompletionKind, CompletionContext},
|
||||
};
|
||||
|
||||
pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> {
|
||||
|
@ -29,7 +29,9 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
|
|||
}
|
||||
}
|
||||
})
|
||||
.for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc));
|
||||
.for_each(|(name, _res)| {
|
||||
CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc)
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -41,9 +43,11 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit)
|
|||
.scope_chain_for_offset(offset)
|
||||
.flat_map(|scope| scopes.entries(scope).iter())
|
||||
.filter(|entry| shadowed.insert(entry.name()))
|
||||
.for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc));
|
||||
.for_each(|entry| {
|
||||
CompletionItem::new(CompletionKind::Reference, entry.name().to_string()).add_to(acc)
|
||||
});
|
||||
if scopes.self_param.is_some() {
|
||||
CompletionItem::new(Reference, "self").add_to(acc);
|
||||
CompletionItem::new(CompletionKind::Reference, "self").add_to(acc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,33 @@
|
|||
use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext};
|
||||
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder};
|
||||
|
||||
fn snippet(label: &str, snippet: &str) -> Builder {
|
||||
CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet)
|
||||
}
|
||||
|
||||
pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) {
|
||||
return;
|
||||
}
|
||||
CompletionItem::new(Snippet, "pd")
|
||||
.snippet("eprintln!(\"$0 = {:?}\", $0);")
|
||||
.add_to(acc);
|
||||
CompletionItem::new(Snippet, "ppd")
|
||||
.snippet("eprintln!(\"$0 = {:#?}\", $0);")
|
||||
.add_to(acc);
|
||||
snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc);
|
||||
snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc);
|
||||
}
|
||||
|
||||
pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
if !ctx.is_new_item {
|
||||
return;
|
||||
}
|
||||
CompletionItem::new(Snippet, "Test function")
|
||||
.lookup_by("tfn")
|
||||
.snippet(
|
||||
snippet(
|
||||
"Test function",
|
||||
"\
|
||||
#[test]
|
||||
fn ${1:feature}() {
|
||||
$0
|
||||
}",
|
||||
)
|
||||
.lookup_by("tfn")
|
||||
.add_to(acc);
|
||||
CompletionItem::new(Snippet, "pub(crate)")
|
||||
.snippet("pub(crate) $0")
|
||||
.add_to(acc);
|
||||
|
||||
snippet("pub(crate)", "pub(crate) $0").add_to(acc);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue