aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/Cargo.toml4
-rw-r--r--crates/ra_ide/src/completion/presentation.rs45
-rw-r--r--crates/ra_ide/src/diagnostics.rs18
-rw-r--r--crates/ra_ide/src/display.rs13
-rw-r--r--crates/ra_ide/src/display/function_signature.rs18
-rw-r--r--crates/ra_ide/src/display/short_label.rs4
6 files changed, 47 insertions, 55 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]
14either = "1.5.3" 14either = "1.5.3"
15format-buf = "1.0.0"
16indexmap = "1.3.2" 15indexmap = "1.3.2"
17itertools = "0.9.0" 16itertools = "0.9.0"
18join_to_string = "0.1.3"
19log = "0.4.8" 17log = "0.4.8"
20rustc-hash = "1.1.0" 18rustc-hash = "1.1.0"
21rand = { version = "0.7.3", features = ["small_rng"] } 19rand = { version = "0.7.3", features = ["small_rng"] }
22 20
21stdx = { path = "../stdx" }
22
23ra_syntax = { path = "../ra_syntax" } 23ra_syntax = { path = "../ra_syntax" }
24ra_text_edit = { path = "../ra_text_edit" } 24ra_text_edit = { path = "../ra_text_edit" }
25ra_db = { path = "../ra_db" } 25ra_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
3use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; 3use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
4use join_to_string::join;
5use ra_syntax::ast::NameOwner; 4use ra_syntax::ast::NameOwner;
5use stdx::SepBy;
6use test_utils::tested_by; 6use test_utils::tested_by;
7 7
8use crate::completion::{
9 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
10};
11
12use crate::{ 8use 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)]
201mod tests { 201mod 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.rs b/crates/ra_ide/src/display.rs
index c395057a7..722092de9 100644
--- a/crates/ra_ide/src/display.rs
+++ b/crates/ra_ide/src/display.rs
@@ -6,12 +6,13 @@ mod navigation_target;
6mod structure; 6mod structure;
7mod short_label; 7mod short_label;
8 8
9use std::fmt::{Display, Write}; 9use std::fmt::Display;
10 10
11use ra_syntax::{ 11use ra_syntax::{
12 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, 12 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner},
13 SyntaxKind::{ATTR, COMMENT}, 13 SyntaxKind::{ATTR, COMMENT},
14}; 14};
15use stdx::format_to;
15 16
16pub use function_signature::FunctionSignature; 17pub use function_signature::FunctionSignature;
17pub use navigation_target::NavigationTarget; 18pub use navigation_target::NavigationTarget;
@@ -78,18 +79,18 @@ pub(crate) fn rust_code_markup_with_doc(
78 doc: Option<&str>, 79 doc: Option<&str>,
79 mod_path: Option<&str>, 80 mod_path: Option<&str>,
80) -> String { 81) -> String {
81 let mut markup = "```rust\n".to_owned(); 82 let mut buf = "```rust\n".to_owned();
82 83
83 if let Some(mod_path) = mod_path { 84 if let Some(mod_path) = mod_path {
84 if !mod_path.is_empty() { 85 if !mod_path.is_empty() {
85 write!(markup, "{}\n", mod_path).unwrap(); 86 format_to!(buf, "{}\n", mod_path);
86 } 87 }
87 } 88 }
88 write!(markup, "{}\n```", code).unwrap(); 89 format_to!(buf, "{}\n```", code);
89 90
90 if let Some(doc) = doc { 91 if let Some(doc) = doc {
91 write!(markup, "\n\n{}", doc).unwrap(); 92 format_to!(buf, "\n\n{}", doc);
92 } 93 }
93 94
94 markup 95 buf
95} 96}
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
3use std::fmt::{self, Display}; 3use std::{
4 convert::From,
5 fmt::{self, Display},
6};
4 7
5use hir::{Docs, Documentation, HasSource, HirDisplay}; 8use hir::{Docs, Documentation, HasSource, HirDisplay};
6use join_to_string::join;
7use ra_ide_db::RootDatabase; 9use ra_ide_db::RootDatabase;
8use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; 10use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
9use std::convert::From; 11use stdx::SepBy;
10 12
11use crate::display::{generic_parameters, where_predicates}; 13use 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
3use format_buf::format;
4use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 3use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
4use stdx::format_to;
5 5
6pub(crate) trait ShortLabel { 6pub(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)