diff options
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index cef3a12f9..684b8243a 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -1,7 +1,3 @@ | |||
1 | use std::{ | ||
2 | fmt::{self, Write}, | ||
3 | }; | ||
4 | |||
5 | use join_to_string::join; | 1 | use join_to_string::join; |
6 | 2 | ||
7 | use libsyntax2::{ | 3 | use libsyntax2::{ |
@@ -78,17 +74,15 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> | |||
78 | let mut buf = String::new(); | 74 | let mut buf = String::new(); |
79 | buf.push_str("\n\nimpl"); | 75 | buf.push_str("\n\nimpl"); |
80 | if let Some(type_params) = type_params { | 76 | if let Some(type_params) = type_params { |
81 | buf.push_display(&type_params.syntax().text()); | 77 | type_params.syntax().text() |
78 | .push_to(&mut buf); | ||
82 | } | 79 | } |
83 | buf.push_str(" "); | 80 | buf.push_str(" "); |
84 | buf.push_str(name.text().as_str()); | 81 | buf.push_str(name.text().as_str()); |
85 | if let Some(type_params) = type_params { | 82 | if let Some(type_params) = type_params { |
86 | comma_list( | 83 | join(type_params.type_params().filter_map(|it| it.name()).map(|it| it.text())) |
87 | &mut buf, "<", ">", | 84 | .surround_with("<", ">") |
88 | type_params.type_params() | 85 | .to_buf(&mut buf); |
89 | .filter_map(|it| it.name()) | ||
90 | .map(|it| it.text()) | ||
91 | ); | ||
92 | } | 86 | } |
93 | buf.push_str(" {\n"); | 87 | buf.push_str(" {\n"); |
94 | let offset = start_offset + TextUnit::of_str(&buf); | 88 | let offset = start_offset + TextUnit::of_str(&buf); |
@@ -107,30 +101,6 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta | |||
107 | .find(|node| !node.kind().is_trivia()) | 101 | .find(|node| !node.kind().is_trivia()) |
108 | } | 102 | } |
109 | 103 | ||
110 | fn comma_list(buf: &mut String, bra: &str, ket: &str, items: impl Iterator<Item=impl fmt::Display>) { | ||
111 | buf.push_str(bra); | ||
112 | let mut first = true; | ||
113 | for item in items { | ||
114 | if !first { | ||
115 | buf.push_str(", "); | ||
116 | } | ||
117 | first = false; | ||
118 | write!(buf, "{}", item).unwrap(); | ||
119 | } | ||
120 | buf.push_str(ket); | ||
121 | } | ||
122 | |||
123 | trait PushDisplay { | ||
124 | fn push_display<T: fmt::Display>(&mut self, item: &T); | ||
125 | } | ||
126 | |||
127 | impl PushDisplay for String { | ||
128 | fn push_display<T: fmt::Display>(&mut self, item: &T) { | ||
129 | use std::fmt::Write; | ||
130 | write!(self, "{}", item).unwrap() | ||
131 | } | ||
132 | } | ||
133 | |||
134 | #[cfg(test)] | 104 | #[cfg(test)] |
135 | mod tests { | 105 | mod tests { |
136 | use super::*; | 106 | use super::*; |