From fc01c7846d5c6970e194dd223e49b863b3189432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 11 Aug 2020 09:54:33 +0300 Subject: Use Hygiene in completion --- crates/ra_ide/src/completion/completion_context.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 6b03b30bb..4aa761148 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -27,7 +27,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) scope: SemanticsScope<'a>, pub(super) db: &'a RootDatabase, pub(super) config: &'a CompletionConfig, - pub(super) offset: TextSize, + pub(super) position: FilePosition, /// The token before the cursor, in the original file. pub(super) original_token: SyntaxToken, /// The token before the cursor, in the macro-expanded file. @@ -117,7 +117,7 @@ impl<'a> CompletionContext<'a> { config, original_token, token, - offset: position.offset, + position, krate, expected_type: None, name_ref_syntax: None, @@ -209,7 +209,7 @@ impl<'a> CompletionContext<'a> { mark::hit!(completes_if_prefix_is_keyword); self.original_token.text_range() } else { - TextRange::empty(self.offset) + TextRange::empty(self.position.offset) } } @@ -379,8 +379,8 @@ impl<'a> CompletionContext<'a> { self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); self.has_type_args = segment.generic_arg_list().is_some(); - #[allow(deprecated)] - if let Some(path) = hir::Path::from_ast(path.clone()) { + let hygiene = hir::Hygiene::new(self.db, self.position.file_id.into()); + if let Some(path) = hir::Path::from_src(path.clone(), &hygiene) { if let Some(path_prefix) = path.qualifier() { self.path_prefix = Some(path_prefix); return; -- cgit v1.2.3 From 7543b06d301024d10b803f4c2bc269af9d481296 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 11 Aug 2020 22:33:17 +0300 Subject: Display snippet in the completion label --- crates/ra_ide/src/completion/complete_snippet.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs index 28d8f7876..4368e4eec 100644 --- a/crates/ra_ide/src/completion/complete_snippet.rs +++ b/crates/ra_ide/src/completion/complete_snippet.rs @@ -36,7 +36,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte snippet( ctx, cap, - "Test module", + "tmod (Test module)", "\ #[cfg(test)] mod tests { @@ -54,7 +54,7 @@ mod tests { snippet( ctx, cap, - "Test function", + "tfn (Test function)", "\ #[test] fn ${1:feature}() { @@ -106,10 +106,10 @@ mod tests { } "#, expect![[r#" - sn Test function - sn Test module sn macro_rules sn pub(crate) + sn tfn (Test function) + sn tmod (Test module) "#]], ) } -- cgit v1.2.3 From 1c359ab634edb81b51e3c7eadfb83d46c926e890 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 15:04:06 +0200 Subject: Replace SepBy with Itertools --- crates/ra_ide/src/completion/presentation.rs | 31 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 9a94ff476..59f1b1424 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -2,8 +2,8 @@ //! It also handles scoring (sorting) completions. use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; +use itertools::Itertools; use ra_syntax::ast::NameOwner; -use stdx::SepBy; use test_utils::mark; use crate::{ @@ -289,16 +289,16 @@ impl Completions { .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); let variant_kind = variant.kind(ctx.db); let detail = match variant_kind { - StructKind::Tuple | StructKind::Unit => detail_types - .map(|(_, t)| t.display(ctx.db).to_string()) - .sep_by(", ") - .surround_with("(", ")") - .to_string(), - StructKind::Record => detail_types - .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string())) - .sep_by(", ") - .surround_with("{ ", " }") - .to_string(), + StructKind::Tuple | StructKind::Unit => format!( + "({})", + detail_types.map(|(_, t)| t.display(ctx.db).to_string()).format(", ") + ), + StructKind::Record => format!( + "{{ {} }}", + detail_types + .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string())) + .format(", ") + ), }; let mut res = CompletionItem::new( CompletionKind::Reference, @@ -412,11 +412,10 @@ impl Builder { self = self.trigger_call_info(); let snippet = match (ctx.config.add_call_argument_snippets, params) { (true, Params::Named(params)) => { - let function_params_snippet = params - .iter() - .enumerate() - .map(|(index, param_name)| format!("${{{}:{}}}", index + 1, param_name)) - .sep_by(", "); + let function_params_snippet = + params.iter().enumerate().format_with(", ", |(index, param_name), f| { + f(&format_args!("${{{}:{}}}", index + 1, param_name)) + }); format!("{}({})$0", name, function_params_snippet) } _ => { -- cgit v1.2.3