From 94603d984808f140931fe517d500bc61d871ea24 Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 25 Feb 2020 23:35:16 +0100 Subject: save comments as ra_syntax::ast::Comment --- crates/ra_ide/src/ssr.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 83c212494..74fb6bab6 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -3,7 +3,8 @@ use crate::source_change::SourceFileEdit; use ra_ide_db::RootDatabase; use ra_syntax::ast::make::expr_from_text; -use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken}; +use ra_syntax::ast::{AstToken, Comment}; +use ra_syntax::{AstNode, SyntaxElement, SyntaxNode}; use ra_text_edit::{TextEdit, TextEditBuilder}; use rustc_hash::FxHashMap; use std::collections::HashMap; @@ -70,7 +71,7 @@ type Binding = HashMap; struct Match { place: SyntaxNode, binding: Binding, - ignored_comments: Vec, + ignored_comments: Vec, } #[derive(Debug)] @@ -199,12 +200,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches { let mut code_children = code.children_with_tokens().filter(|element| !element.kind().is_trivia()); let new_ignored_comments = code.children_with_tokens().filter_map(|element| { - if let SyntaxElement::Token(token) = element { - if token.kind() == SyntaxKind::COMMENT { - return Some(token.clone()); - } - } - None + element.as_token().and_then(|token| Comment::cast(token.clone())) }); match_.ignored_comments.extend(new_ignored_comments); let match_from_children = pattern_children @@ -254,7 +250,7 @@ fn replace(matches: &SsrMatches, template: &SsrTemplate) -> TextEdit { fn render_replace( binding: &Binding, - ignored_comments: &Vec, + ignored_comments: &Vec, template: &SsrTemplate, ) -> String { let mut builder = TextEditBuilder::default(); @@ -264,7 +260,7 @@ fn render_replace( } } for comment in ignored_comments { - builder.insert(template.template.text_range().end(), comment.to_string()) + builder.insert(template.template.text_range().end(), comment.syntax().to_string()) } builder.finish().apply(&template.template.text().to_string()) } -- cgit v1.2.3