diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 45 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 18 | ||||
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 18 | ||||
-rw-r--r-- | crates/ra_ide/src/display/short_label.rs | 4 |
5 files changed, 40 insertions, 49 deletions
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 36eec0e60..b4a29b81b 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -12,14 +12,14 @@ wasm = [] | |||
12 | 12 | ||
13 | [dependencies] | 13 | [dependencies] |
14 | either = "1.5.3" | 14 | either = "1.5.3" |
15 | format-buf = "1.0.0" | ||
16 | indexmap = "1.3.2" | 15 | indexmap = "1.3.2" |
17 | itertools = "0.9.0" | 16 | itertools = "0.9.0" |
18 | join_to_string = "0.1.3" | ||
19 | log = "0.4.8" | 17 | log = "0.4.8" |
20 | rustc-hash = "1.1.0" | 18 | rustc-hash = "1.1.0" |
21 | rand = { version = "0.7.3", features = ["small_rng"] } | 19 | rand = { version = "0.7.3", features = ["small_rng"] } |
22 | 20 | ||
21 | stdx = { path = "../stdx" } | ||
22 | |||
23 | ra_syntax = { path = "../ra_syntax" } | 23 | ra_syntax = { path = "../ra_syntax" } |
24 | ra_text_edit = { path = "../ra_text_edit" } | 24 | ra_text_edit = { path = "../ra_text_edit" } |
25 | ra_db = { path = "../ra_db" } | 25 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 253848602..60f1b83f3 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -1,15 +1,14 @@ | |||
1 | //! This modules takes care of rendering various definitions as completion items. | 1 | //! This modules takes care of rendering various definitions as completion items. |
2 | 2 | ||
3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; | 3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; |
4 | use join_to_string::join; | ||
5 | use ra_syntax::ast::NameOwner; | 4 | use ra_syntax::ast::NameOwner; |
5 | use stdx::SepBy; | ||
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
7 | 7 | ||
8 | use crate::completion::{ | ||
9 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, | ||
10 | }; | ||
11 | |||
12 | use crate::{ | 8 | use crate::{ |
9 | completion::{ | ||
10 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, | ||
11 | }, | ||
13 | display::{const_label, macro_label, type_label, FunctionSignature}, | 12 | display::{const_label, macro_label, type_label, FunctionSignature}, |
14 | RootDatabase, | 13 | RootDatabase, |
15 | }; | 14 | }; |
@@ -221,13 +220,13 @@ impl Completions { | |||
221 | builder = builder.trigger_call_info(); | 220 | builder = builder.trigger_call_info(); |
222 | let snippet = if ctx.options.add_call_argument_snippets { | 221 | let snippet = if ctx.options.add_call_argument_snippets { |
223 | let to_skip = if has_self_param { 1 } else { 0 }; | 222 | let to_skip = if has_self_param { 1 } else { 0 }; |
224 | let function_params_snippet = join( | 223 | let function_params_snippet = function_signature |
225 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( | 224 | .parameter_names |
226 | |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), | 225 | .iter() |
227 | ), | 226 | .skip(to_skip) |
228 | ) | 227 | .enumerate() |
229 | .separator(", ") | 228 | .map(|(index, param_name)| format!("${{{}:{}}}", index + 1, param_name)) |
230 | .to_string(); | 229 | .sep_by(", "); |
231 | format!("{}({})$0", name, function_params_snippet) | 230 | format!("{}({})$0", name, function_params_snippet) |
232 | } else { | 231 | } else { |
233 | format!("{}($0)", name) | 232 | format!("{}($0)", name) |
@@ -281,18 +280,16 @@ impl Completions { | |||
281 | .into_iter() | 280 | .into_iter() |
282 | .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); | 281 | .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); |
283 | let detail = match variant.kind(ctx.db) { | 282 | let detail = match variant.kind(ctx.db) { |
284 | StructKind::Tuple | StructKind::Unit => { | 283 | StructKind::Tuple | StructKind::Unit => detail_types |
285 | join(detail_types.map(|(_, t)| t.display(ctx.db).to_string())) | 284 | .map(|(_, t)| t.display(ctx.db).to_string()) |
286 | .separator(", ") | 285 | .sep_by(", ") |
287 | .surround_with("(", ")") | 286 | .surround_with("(", ")") |
288 | .to_string() | 287 | .to_string(), |
289 | } | 288 | StructKind::Record => detail_types |
290 | StructKind::Record => { | 289 | .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string())) |
291 | join(detail_types.map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string()))) | 290 | .sep_by(", ") |
292 | .separator(", ") | 291 | .surround_with("{ ", " }") |
293 | .surround_with("{ ", " }") | 292 | .to_string(), |
294 | .to_string() | ||
295 | } | ||
296 | }; | 293 | }; |
297 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | 294 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) |
298 | .kind(CompletionItemKind::EnumVariant) | 295 | .kind(CompletionItemKind::EnumVariant) |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index a10e642db..c1d7ddaf2 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -200,8 +200,8 @@ fn check_struct_shorthand_initialization( | |||
200 | #[cfg(test)] | 200 | #[cfg(test)] |
201 | mod tests { | 201 | mod tests { |
202 | use insta::assert_debug_snapshot; | 202 | use insta::assert_debug_snapshot; |
203 | use join_to_string::join; | ||
204 | use ra_syntax::SourceFile; | 203 | use ra_syntax::SourceFile; |
204 | use stdx::SepBy; | ||
205 | use test_utils::assert_eq_text; | 205 | use test_utils::assert_eq_text; |
206 | 206 | ||
207 | use crate::mock_analysis::{analysis_and_position, single_file}; | 207 | use crate::mock_analysis::{analysis_and_position, single_file}; |
@@ -254,16 +254,12 @@ mod tests { | |||
254 | .map(|it| it.len() - it.trim_start().len()) | 254 | .map(|it| it.len() - it.trim_start().len()) |
255 | .next() | 255 | .next() |
256 | .expect("empty fixture"); | 256 | .expect("empty fixture"); |
257 | let after = join(after.lines().filter_map(|line| { | 257 | let after = after |
258 | if line.len() > margin { | 258 | .lines() |
259 | Some(&line[margin..]) | 259 | .filter_map(|line| if line.len() > margin { Some(&line[margin..]) } else { None }) |
260 | } else { | 260 | .sep_by("\n") |
261 | None | 261 | .suffix("\n") |
262 | } | 262 | .to_string(); |
263 | })) | ||
264 | .separator("\n") | ||
265 | .suffix("\n") | ||
266 | .to_string(); | ||
267 | 263 | ||
268 | assert_eq_text!(&after, &actual); | 264 | assert_eq_text!(&after, &actual); |
269 | assert!( | 265 | assert!( |
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index ec1bbd5a0..b967a6816 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -1,12 +1,14 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::fmt::{self, Display}; | 3 | use std::{ |
4 | convert::From, | ||
5 | fmt::{self, Display}, | ||
6 | }; | ||
4 | 7 | ||
5 | use hir::{Docs, Documentation, HasSource, HirDisplay}; | 8 | use hir::{Docs, Documentation, HasSource, HirDisplay}; |
6 | use join_to_string::join; | ||
7 | use ra_ide_db::RootDatabase; | 9 | use ra_ide_db::RootDatabase; |
8 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; | 10 | use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; |
9 | use std::convert::From; | 11 | use stdx::SepBy; |
10 | 12 | ||
11 | use crate::display::{generic_parameters, where_predicates}; | 13 | use crate::display::{generic_parameters, where_predicates}; |
12 | 14 | ||
@@ -227,21 +229,17 @@ impl Display for FunctionSignature { | |||
227 | } | 229 | } |
228 | 230 | ||
229 | if !self.generic_parameters.is_empty() { | 231 | if !self.generic_parameters.is_empty() { |
230 | join(self.generic_parameters.iter()) | 232 | write!(f, "{}", self.generic_parameters.iter().sep_by(", ").surround_with("<", ">"))?; |
231 | .separator(", ") | ||
232 | .surround_with("<", ">") | ||
233 | .to_fmt(f)?; | ||
234 | } | 233 | } |
235 | 234 | ||
236 | join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?; | 235 | write!(f, "{}", self.parameters.iter().sep_by(", ").surround_with("(", ")"))?; |
237 | 236 | ||
238 | if let Some(t) = &self.ret_type { | 237 | if let Some(t) = &self.ret_type { |
239 | write!(f, " -> {}", t)?; | 238 | write!(f, " -> {}", t)?; |
240 | } | 239 | } |
241 | 240 | ||
242 | if !self.where_predicates.is_empty() { | 241 | if !self.where_predicates.is_empty() { |
243 | write!(f, "\nwhere ")?; | 242 | write!(f, "\nwhere {}", self.where_predicates.iter().sep_by(",\n "))?; |
244 | join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?; | ||
245 | } | 243 | } |
246 | 244 | ||
247 | Ok(()) | 245 | Ok(()) |
diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 9ffc9b980..4b081bf6c 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use format_buf::format; | ||
4 | use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; | 3 | use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; |
4 | use stdx::format_to; | ||
5 | 5 | ||
6 | pub(crate) trait ShortLabel { | 6 | pub(crate) trait ShortLabel { |
7 | fn short_label(&self) -> Option<String>; | 7 | fn short_label(&self) -> Option<String>; |
@@ -80,7 +80,7 @@ where | |||
80 | let mut buf = short_label_from_node(node, prefix)?; | 80 | let mut buf = short_label_from_node(node, prefix)?; |
81 | 81 | ||
82 | if let Some(type_ref) = node.ascribed_type() { | 82 | if let Some(type_ref) = node.ascribed_type() { |
83 | format!(buf, ": {}", type_ref.syntax()); | 83 | format_to!(buf, ": {}", type_ref.syntax()); |
84 | } | 84 | } |
85 | 85 | ||
86 | Some(buf) | 86 | Some(buf) |