aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/ssr.rs16
1 files changed, 6 insertions, 10 deletions
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 @@
3use crate::source_change::SourceFileEdit; 3use crate::source_change::SourceFileEdit;
4use ra_ide_db::RootDatabase; 4use ra_ide_db::RootDatabase;
5use ra_syntax::ast::make::expr_from_text; 5use ra_syntax::ast::make::expr_from_text;
6use ra_syntax::{AstNode, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken}; 6use ra_syntax::ast::{AstToken, Comment};
7use ra_syntax::{AstNode, SyntaxElement, SyntaxNode};
7use ra_text_edit::{TextEdit, TextEditBuilder}; 8use ra_text_edit::{TextEdit, TextEditBuilder};
8use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
9use std::collections::HashMap; 10use std::collections::HashMap;
@@ -70,7 +71,7 @@ type Binding = HashMap<Var, SyntaxNode>;
70struct Match { 71struct Match {
71 place: SyntaxNode, 72 place: SyntaxNode,
72 binding: Binding, 73 binding: Binding,
73 ignored_comments: Vec<SyntaxToken>, 74 ignored_comments: Vec<Comment>,
74} 75}
75 76
76#[derive(Debug)] 77#[derive(Debug)]
@@ -199,12 +200,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
199 let mut code_children = 200 let mut code_children =
200 code.children_with_tokens().filter(|element| !element.kind().is_trivia()); 201 code.children_with_tokens().filter(|element| !element.kind().is_trivia());
201 let new_ignored_comments = code.children_with_tokens().filter_map(|element| { 202 let new_ignored_comments = code.children_with_tokens().filter_map(|element| {
202 if let SyntaxElement::Token(token) = element { 203 element.as_token().and_then(|token| Comment::cast(token.clone()))
203 if token.kind() == SyntaxKind::COMMENT {
204 return Some(token.clone());
205 }
206 }
207 None
208 }); 204 });
209 match_.ignored_comments.extend(new_ignored_comments); 205 match_.ignored_comments.extend(new_ignored_comments);
210 let match_from_children = pattern_children 206 let match_from_children = pattern_children
@@ -254,7 +250,7 @@ fn replace(matches: &SsrMatches, template: &SsrTemplate) -> TextEdit {
254 250
255fn render_replace( 251fn render_replace(
256 binding: &Binding, 252 binding: &Binding,
257 ignored_comments: &Vec<SyntaxToken>, 253 ignored_comments: &Vec<Comment>,
258 template: &SsrTemplate, 254 template: &SsrTemplate,
259) -> String { 255) -> String {
260 let mut builder = TextEditBuilder::default(); 256 let mut builder = TextEditBuilder::default();
@@ -264,7 +260,7 @@ fn render_replace(
264 } 260 }
265 } 261 }
266 for comment in ignored_comments { 262 for comment in ignored_comments {
267 builder.insert(template.template.text_range().end(), comment.to_string()) 263 builder.insert(template.template.text_range().end(), comment.syntax().to_string())
268 } 264 }
269 builder.finish().apply(&template.template.text().to_string()) 265 builder.finish().apply(&template.template.text().to_string())
270} 266}