diff options
Diffstat (limited to 'crates/ide/src/extend_selection.rs')
-rw-r--r-- | crates/ide/src/extend_selection.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs index b540d04fe..e187243cb 100644 --- a/crates/ide/src/extend_selection.rs +++ b/crates/ide/src/extend_selection.rs | |||
@@ -88,7 +88,7 @@ fn try_extend_selection( | |||
88 | return Some(range); | 88 | return Some(range); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | token.parent() | 91 | token.parent()? |
92 | } | 92 | } |
93 | NodeOrToken::Node(node) => node, | 93 | NodeOrToken::Node(node) => node, |
94 | }; | 94 | }; |
@@ -142,7 +142,8 @@ fn extend_tokens_from_range( | |||
142 | let extended = { | 142 | let extended = { |
143 | let fst_expanded = sema.descend_into_macros(first_token.clone()); | 143 | let fst_expanded = sema.descend_into_macros(first_token.clone()); |
144 | let lst_expanded = sema.descend_into_macros(last_token.clone()); | 144 | let lst_expanded = sema.descend_into_macros(last_token.clone()); |
145 | let mut lca = algo::least_common_ancestor(&fst_expanded.parent(), &lst_expanded.parent())?; | 145 | let mut lca = |
146 | algo::least_common_ancestor(&fst_expanded.parent()?, &lst_expanded.parent()?)?; | ||
146 | lca = shallowest_node(&lca); | 147 | lca = shallowest_node(&lca); |
147 | if lca.first_token() == Some(fst_expanded) && lca.last_token() == Some(lst_expanded) { | 148 | if lca.first_token() == Some(fst_expanded) && lca.last_token() == Some(lst_expanded) { |
148 | lca = lca.parent()?; | 149 | lca = lca.parent()?; |
@@ -151,9 +152,13 @@ fn extend_tokens_from_range( | |||
151 | }; | 152 | }; |
152 | 153 | ||
153 | // Compute parent node range | 154 | // Compute parent node range |
154 | let validate = |token: &SyntaxToken| { | 155 | let validate = |token: &SyntaxToken| -> bool { |
155 | let expanded = sema.descend_into_macros(token.clone()); | 156 | let expanded = sema.descend_into_macros(token.clone()); |
156 | algo::least_common_ancestor(&extended, &expanded.parent()).as_ref() == Some(&extended) | 157 | let parent = match expanded.parent() { |
158 | Some(it) => it, | ||
159 | None => return false, | ||
160 | }; | ||
161 | algo::least_common_ancestor(&extended, &parent).as_ref() == Some(&extended) | ||
157 | }; | 162 | }; |
158 | 163 | ||
159 | // Find the first and last text range under expanded parent | 164 | // Find the first and last text range under expanded parent |