From 3d9997889bfe536a96e70535ab208a6e7ff3bc12 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Tue, 23 Jun 2020 19:07:42 +1000 Subject: SSR: Add initial support for placeholder constraints --- crates/ra_ide/src/ssr.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 9f8e540c0..b3e9e5dfe 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -10,6 +10,18 @@ use ra_ssr::{MatchFinder, SsrError, SsrRule}; // The syntax for a structural search replace command is ` ==>> `. // A `$` placeholder in the search pattern will match any AST node and `$` will reference it in the replacement. // Within a macro call, a placeholder will match up until whatever token follows the placeholder. +// +// Placeholders may be given constraints by writing them as `${::...}`. +// +// Supported constraints: +// +// |=== +// | Constraint | Restricts placeholder +// +// | kind(literal) | Is a literal (e.g. `42` or `"forty two"`) +// | not(a) | Negates the constraint `a` +// |=== +// // Available via the command `rust-analyzer.ssr`. // // ```rust -- cgit v1.2.3 From 0bbd6428ad786cf60d5c79d0ac2aae6dac7dc1a5 Mon Sep 17 00:00:00 2001 From: BGluth Date: Fri, 26 Jun 2020 12:30:00 -0600 Subject: Added tests for no auto-completion on comments --- crates/ra_ide/src/completion/presentation.rs | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 4fdc2f0bb..b18279746 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -1516,4 +1516,54 @@ mod tests { "### ); } + + #[test] + fn no_keyword_autocompletion_on_line_comments() { + assert_debug_snapshot!( + do_completion( + r" + fn test() { + let x = 2; // A comment<|> + } + ", + CompletionKind::Keyword + ), + @r###" + [] + "### + ); + } + + #[test] + fn no_keyword_autocompletion_on_multi_line_comments() { + assert_debug_snapshot!( + do_completion( + r" + /* + Some multi-line comment<|> + */ + ", + CompletionKind::Keyword + ), + @r###" + [] + "### + ); + } + + #[test] + fn no_keyword_autocompletion_on_doc_comments() { + assert_debug_snapshot!( + do_completion( + r" + /// Some doc comment + /// let test<|> = 1 + ", + CompletionKind::Keyword + ), + @r###" + [] + "### + ); + } } -- cgit v1.2.3 From cc77bdf59ad99d3522663ebdb80be553f2767290 Mon Sep 17 00:00:00 2001 From: BGluth Date: Fri, 26 Jun 2020 20:09:11 -0600 Subject: Auto-completion no longer occurs on comments --- crates/ra_ide/src/completion/complete_keyword.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index 3b174f916..e599cc3d1 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use ra_syntax::ast; +use ra_syntax::{ast, SyntaxKind}; use crate::completion::{ CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, @@ -37,6 +37,10 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC } pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { + if ctx.token.kind() == SyntaxKind::COMMENT { + return; + } + let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent; if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { add_keyword(ctx, acc, "where", "where "); -- cgit v1.2.3 From f1986be8fdcdc01c580b2d6e43574ae980d38e4b Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Thu, 2 Jul 2020 11:06:00 +0800 Subject: fix: correct pd/ppd/tfn/tmod completion doc https://github.com/rust-analyzer/rust-analyzer/blob/a33eefa3b26000b3018e6bb873f18dbe15ab4ab7/crates/ra_ide/src/completion/complete_snippet.rs#L23 --- crates/ra_ide/src/completion.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index 69ea754b3..9ebb8ebb7 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs @@ -63,11 +63,11 @@ pub use crate::completion::{ // There also snippet completions: // // .Expressions -// - `pd` -> `println!("{:?}")` -// - `ppd` -> `println!("{:#?}")` +// - `pd` -> `eprintln!(" = {:?}", );")` +// - `ppd` -> `eprintln!(" = {:#?}", );` // // .Items -// - `tfn` -> `#[test] fn f(){}` +// - `tfn` -> `#[test] fn feature(){}` // - `tmod` -> // ```rust // #[cfg(test)] @@ -75,7 +75,7 @@ pub use crate::completion::{ // use super::*; // // #[test] -// fn test_fn() {} +// fn test_name() {} // } // ``` -- cgit v1.2.3