diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-20 10:59:10 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-20 10:59:10 +0100 |
commit | 6b352ffeb346eb7c7e46e00e790c2f395907eaa6 (patch) | |
tree | f19271365126259a7975dda9ee3e1e1496a299dd /crates/ra_ide_api/src/completion | |
parent | 2830d1376b05794c7bf1467fe52ad3bc0eb4ca41 (diff) | |
parent | f3bdbec1b68fa0e20f0b7b6c6ef64e1507970b0d (diff) |
Merge #1560
1560: move debug_dump to fmt::Debug r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion')
4 files changed, 23 insertions, 15 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs index 4cf34eff8..18c1839dc 100644 --- a/crates/ra_ide_api/src/completion/complete_keyword.rs +++ b/crates/ra_ide_api/src/completion/complete_keyword.rs | |||
@@ -88,7 +88,7 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool { | |||
88 | .visit::<ast::LoopExpr, _>(|it| it.loop_body()) | 88 | .visit::<ast::LoopExpr, _>(|it| it.loop_body()) |
89 | .accept(&node); | 89 | .accept(&node); |
90 | if let Some(Some(body)) = loop_body { | 90 | if let Some(Some(body)) = loop_body { |
91 | if leaf.range().is_subrange(&body.syntax().range()) { | 91 | if leaf.text_range().is_subrange(&body.syntax().text_range()) { |
92 | return true; | 92 | return true; |
93 | } | 93 | } |
94 | } | 94 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 29586cd1f..5fd41eeb3 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
26 | if Some(module) == ctx.module { | 26 | if Some(module) == ctx.module { |
27 | if let Some(import) = res.import { | 27 | if let Some(import) = res.import { |
28 | if let Either::A(use_tree) = module.import_source(ctx.db, import) { | 28 | if let Either::A(use_tree) = module.import_source(ctx.db, import) { |
29 | if use_tree.syntax().range().contains_inclusive(ctx.offset) { | 29 | if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { |
30 | // for `use self::foo<|>`, don't suggest `foo` as a completion | 30 | // for `use self::foo<|>`, don't suggest `foo` as a completion |
31 | tested_by!(dont_complete_current_use); | 31 | tested_by!(dont_complete_current_use); |
32 | continue; | 32 | continue; |
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index c75b1c159..6d834f6ce 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs | |||
@@ -12,7 +12,7 @@ use ra_text_edit::TextEditBuilder; | |||
12 | fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { | 12 | fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { |
13 | let edit = { | 13 | let edit = { |
14 | let receiver_range = | 14 | let receiver_range = |
15 | ctx.dot_receiver.as_ref().expect("no receiver available").syntax().range(); | 15 | ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); |
16 | let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); | 16 | let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); |
17 | let mut builder = TextEditBuilder::default(); | 17 | let mut builder = TextEditBuilder::default(); |
18 | builder.replace(delete_range, snippet.to_string()); | 18 | builder.replace(delete_range, snippet.to_string()); |
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index b803271ab..2f78d5409 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -78,7 +78,7 @@ impl<'a> CompletionContext<'a> { | |||
78 | pub(crate) fn source_range(&self) -> TextRange { | 78 | pub(crate) fn source_range(&self) -> TextRange { |
79 | match self.token.kind() { | 79 | match self.token.kind() { |
80 | // workaroud when completion is triggered by trigger characters. | 80 | // workaroud when completion is triggered by trigger characters. |
81 | IDENT => self.token.range(), | 81 | IDENT => self.token.text_range(), |
82 | _ => TextRange::offset_len(self.offset, 0.into()), | 82 | _ => TextRange::offset_len(self.offset, 0.into()), |
83 | } | 83 | } |
84 | } | 84 | } |
@@ -123,13 +123,17 @@ impl<'a> CompletionContext<'a> { | |||
123 | } | 123 | } |
124 | 124 | ||
125 | fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { | 125 | fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { |
126 | let name_range = name_ref.syntax().range(); | 126 | let name_range = name_ref.syntax().text_range(); |
127 | if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() { | 127 | if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() { |
128 | self.struct_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); | 128 | self.struct_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); |
129 | } | 129 | } |
130 | 130 | ||
131 | let top_node = | 131 | let top_node = name_ref |
132 | name_ref.syntax().ancestors().take_while(|it| it.range() == name_range).last().unwrap(); | 132 | .syntax() |
133 | .ancestors() | ||
134 | .take_while(|it| it.text_range() == name_range) | ||
135 | .last() | ||
136 | .unwrap(); | ||
133 | 137 | ||
134 | match top_node.parent().map(|it| it.kind()) { | 138 | match top_node.parent().map(|it| it.kind()) { |
135 | Some(SOURCE_FILE) | Some(ITEM_LIST) => { | 139 | Some(SOURCE_FILE) | Some(ITEM_LIST) => { |
@@ -180,23 +184,27 @@ impl<'a> CompletionContext<'a> { | |||
180 | .ancestors() | 184 | .ancestors() |
181 | .find_map(|node| { | 185 | .find_map(|node| { |
182 | if let Some(stmt) = ast::ExprStmt::cast(node.clone()) { | 186 | if let Some(stmt) = ast::ExprStmt::cast(node.clone()) { |
183 | return Some(stmt.syntax().range() == name_ref.syntax().range()); | 187 | return Some( |
188 | stmt.syntax().text_range() == name_ref.syntax().text_range(), | ||
189 | ); | ||
184 | } | 190 | } |
185 | if let Some(block) = ast::Block::cast(node) { | 191 | if let Some(block) = ast::Block::cast(node) { |
186 | return Some( | 192 | return Some( |
187 | block.expr().map(|e| e.syntax().range()) | 193 | block.expr().map(|e| e.syntax().text_range()) |
188 | == Some(name_ref.syntax().range()), | 194 | == Some(name_ref.syntax().text_range()), |
189 | ); | 195 | ); |
190 | } | 196 | } |
191 | None | 197 | None |
192 | }) | 198 | }) |
193 | .unwrap_or(false); | 199 | .unwrap_or(false); |
194 | 200 | ||
195 | if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) { | 201 | if let Some(off) = name_ref.syntax().text_range().start().checked_sub(2.into()) { |
196 | if let Some(if_expr) = | 202 | if let Some(if_expr) = |
197 | find_node_at_offset::<ast::IfExpr>(original_file.syntax(), off) | 203 | find_node_at_offset::<ast::IfExpr>(original_file.syntax(), off) |
198 | { | 204 | { |
199 | if if_expr.syntax().range().end() < name_ref.syntax().range().start() { | 205 | if if_expr.syntax().text_range().end() |
206 | < name_ref.syntax().text_range().start() | ||
207 | { | ||
200 | self.after_if = true; | 208 | self.after_if = true; |
201 | } | 209 | } |
202 | } | 210 | } |
@@ -208,14 +216,14 @@ impl<'a> CompletionContext<'a> { | |||
208 | // ident, so it should have the same range in the non-modified file | 216 | // ident, so it should have the same range in the non-modified file |
209 | self.dot_receiver = field_expr | 217 | self.dot_receiver = field_expr |
210 | .expr() | 218 | .expr() |
211 | .map(|e| e.syntax().range()) | 219 | .map(|e| e.syntax().text_range()) |
212 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); | 220 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); |
213 | } | 221 | } |
214 | if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { | 222 | if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { |
215 | // As above | 223 | // As above |
216 | self.dot_receiver = method_call_expr | 224 | self.dot_receiver = method_call_expr |
217 | .expr() | 225 | .expr() |
218 | .map(|e| e.syntax().range()) | 226 | .map(|e| e.syntax().text_range()) |
219 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); | 227 | .and_then(|r| find_node_with_range(original_file.syntax(), r)); |
220 | self.is_call = true; | 228 | self.is_call = true; |
221 | } | 229 | } |
@@ -229,6 +237,6 @@ fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Op | |||
229 | fn is_node<N: AstNode>(node: &SyntaxNode) -> bool { | 237 | fn is_node<N: AstNode>(node: &SyntaxNode) -> bool { |
230 | match node.ancestors().filter_map(N::cast).next() { | 238 | match node.ancestors().filter_map(N::cast).next() { |
231 | None => false, | 239 | None => false, |
232 | Some(n) => n.syntax().range() == node.range(), | 240 | Some(n) => n.syntax().text_range() == node.text_range(), |
233 | } | 241 | } |
234 | } | 242 | } |