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/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs8
-rw-r--r--crates/ra_ide/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide/src/display/function_signature.rs5
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide/src/references.rs2
-rw-r--r--crates/ra_ide/src/ssr.rs14
7 files changed, 21 insertions, 18 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index f2b29306e..7c6322cb4 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -128,7 +128,7 @@ impl FnCallNode {
128 }), 128 }),
129 129
130 FnCallNode::MethodCallExpr(call_expr) => { 130 FnCallNode::MethodCallExpr(call_expr) => {
131 call_expr.syntax().children().filter_map(ast::NameRef::cast).nth(0) 131 call_expr.syntax().children().filter_map(ast::NameRef::cast).next()
132 } 132 }
133 133
134 FnCallNode::MacroCallExpr(call_expr) => call_expr.path()?.segment()?.name_ref(), 134 FnCallNode::MacroCallExpr(call_expr) => call_expr.path()?.segment()?.name_ref(),
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index 6ff10c017..83628e35c 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -59,7 +59,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
59 .as_ref() 59 .as_ref()
60 .and_then(|node| node.parent()) 60 .and_then(|node| node.parent())
61 .and_then(|node| node.parent()) 61 .and_then(|node| node.parent())
62 .and_then(|node| ast::ImplBlock::cast(node)); 62 .and_then(ast::ImplBlock::cast);
63 63
64 if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) { 64 if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) {
65 match trigger.kind() { 65 match trigger.kind() {
@@ -110,17 +110,17 @@ fn add_function_impl(
110 ctx: &CompletionContext, 110 ctx: &CompletionContext,
111 func: &hir::Function, 111 func: &hir::Function,
112) { 112) {
113 let display = FunctionSignature::from_hir(ctx.db, func.clone()); 113 let display = FunctionSignature::from_hir(ctx.db, *func);
114 114
115 let fn_name = func.name(ctx.db).to_string(); 115 let fn_name = func.name(ctx.db).to_string();
116 116
117 let label = if func.params(ctx.db).len() > 0 { 117 let label = if !func.params(ctx.db).is_empty() {
118 format!("fn {}(..)", fn_name) 118 format!("fn {}(..)", fn_name)
119 } else { 119 } else {
120 format!("fn {}()", fn_name) 120 format!("fn {}()", fn_name)
121 }; 121 };
122 122
123 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone()) 123 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
124 .lookup_by(fn_name) 124 .lookup_by(fn_name)
125 .set_documentation(func.docs(ctx.db)); 125 .set_documentation(func.docs(ctx.db));
126 126
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs
index 93f336370..61867c0ff 100644
--- a/crates/ra_ide/src/completion/completion_item.rs
+++ b/crates/ra_ide/src/completion/completion_item.rs
@@ -159,7 +159,7 @@ impl CompletionItem {
159 159
160 /// Short one-line additional information, like a type 160 /// Short one-line additional information, like a type
161 pub fn detail(&self) -> Option<&str> { 161 pub fn detail(&self) -> Option<&str> {
162 self.detail.as_ref().map(|it| it.as_str()) 162 self.detail.as_deref()
163 } 163 }
164 /// A doc-comment 164 /// A doc-comment
165 pub fn documentation(&self) -> Option<Documentation> { 165 pub fn documentation(&self) -> Option<Documentation> {
@@ -167,7 +167,7 @@ impl CompletionItem {
167 } 167 }
168 /// What string is used for filtering. 168 /// What string is used for filtering.
169 pub fn lookup(&self) -> &str { 169 pub fn lookup(&self) -> &str {
170 self.lookup.as_ref().map(|it| it.as_str()).unwrap_or_else(|| self.label()) 170 self.lookup.as_deref().unwrap_or_else(|| self.label())
171 } 171 }
172 172
173 pub fn kind(&self) -> Option<CompletionItemKind> { 173 pub fn kind(&self) -> Option<CompletionItemKind> {
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index c23e08e9a..b85fd8075 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -54,9 +54,8 @@ impl FunctionSignature {
54 54
55 pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> { 55 pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> {
56 let node: ast::StructDef = st.source(db).value; 56 let node: ast::StructDef = st.source(db).value;
57 match node.kind() { 57 if let ast::StructKind::Record(_) = node.kind() {
58 ast::StructKind::Record(_) => return None, 58 return None;
59 _ => (),
60 }; 59 };
61 60
62 let params = st 61 let params = st
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 906aab1eb..096c41c81 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -64,11 +64,11 @@ impl NavigationTarget {
64 } 64 }
65 65
66 pub fn docs(&self) -> Option<&str> { 66 pub fn docs(&self) -> Option<&str> {
67 self.docs.as_ref().map(String::as_str) 67 self.docs.as_deref()
68 } 68 }
69 69
70 pub fn description(&self) -> Option<&str> { 70 pub fn description(&self) -> Option<&str> {
71 self.description.as_ref().map(String::as_str) 71 self.description.as_deref()
72 } 72 }
73 73
74 /// A "most interesting" range withing the `full_range`. 74 /// A "most interesting" range withing the `full_range`.
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index de924fad2..97c08ade5 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -268,7 +268,7 @@ fn decl_access(
268 }; 268 };
269 269
270 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?; 270 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
271 if let Some(_) = stmt.initializer() { 271 if stmt.initializer().is_some() {
272 let pat = stmt.pat()?; 272 let pat = stmt.pat()?;
273 if let ast::Pat::BindPat(it) = pat { 273 if let ast::Pat::BindPat(it) = pat {
274 if it.name()?.text().as_str() == name { 274 if it.name()?.text().as_str() == name {
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 14eb0b8b2..902c29fc6 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -85,8 +85,11 @@ impl FromStr for SsrQuery {
85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> { 85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> {
86 let mut it = query.split("==>>"); 86 let mut it = query.split("==>>");
87 let pattern = it.next().expect("at least empty string").trim(); 87 let pattern = it.next().expect("at least empty string").trim();
88 let mut template = 88 let mut template = it
89 it.next().ok_or(SsrError("Cannot find delemiter `==>>`".into()))?.trim().to_string(); 89 .next()
90 .ok_or_else(|| SsrError("Cannot find delemiter `==>>`".into()))?
91 .trim()
92 .to_string();
90 if it.next().is_some() { 93 if it.next().is_some() {
91 return Err(SsrError("More than one delimiter found".into())); 94 return Err(SsrError("More than one delimiter found".into()));
92 } 95 }
@@ -131,11 +134,12 @@ fn traverse(node: &SyntaxNode, go: &mut impl FnMut(&SyntaxNode) -> bool) {
131} 134}
132 135
133fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> { 136fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> {
134 let end_of_name = s.find(":").ok_or(SsrError("Use $<name>:expr".into()))?; 137 let end_of_name = s.find(':').ok_or_else(|| SsrError("Use $<name>:expr".into()))?;
135 let name = &s[0..end_of_name]; 138 let name = &s[0..end_of_name];
136 is_name(name)?; 139 is_name(name)?;
137 let type_begin = end_of_name + 1; 140 let type_begin = end_of_name + 1;
138 let type_length = s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or(s.len()); 141 let type_length =
142 s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or_else(|| s.len());
139 let type_name = &s[type_begin..type_begin + type_length]; 143 let type_name = &s[type_begin..type_begin + type_length];
140 Ok((name, type_name, &s[type_begin + type_length..])) 144 Ok((name, type_name, &s[type_begin + type_length..]))
141} 145}
@@ -182,7 +186,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
182 pattern.text() == code.text() 186 pattern.text() == code.text()
183 } 187 }
184 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => { 188 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => {
185 if placeholders.iter().find(|&n| n.0.as_str() == pattern.text()).is_some() { 189 if placeholders.iter().any(|n| n.0.as_str() == pattern.text()) {
186 match_.binding.insert(Var(pattern.text().to_string()), code.clone()); 190 match_.binding.insert(Var(pattern.text().to_string()), code.clone());
187 true 191 true
188 } else { 192 } else {