|
1 | 1 | //! FIXME: write short doc here |
2 | 2 |
|
3 | 3 | use base_db::SourceDatabase; |
4 | | -use hir::{Semantics, SemanticsScope, Type}; |
| 4 | +use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type}; |
5 | 5 | use ide_db::RootDatabase; |
6 | 6 | use syntax::{ |
7 | 7 | algo::{find_covering_element, find_node_at_offset}, |
@@ -90,6 +90,7 @@ pub(crate) struct CompletionContext<'a> { |
90 | 90 | pub(super) impl_as_prev_sibling: bool, |
91 | 91 | pub(super) is_match_arm: bool, |
92 | 92 | pub(super) has_item_list_or_source_file_parent: bool, |
| 93 | + pub(super) locals: Vec<(String, Local)>, |
93 | 94 | } |
94 | 95 |
|
95 | 96 | impl<'a> CompletionContext<'a> { |
@@ -118,6 +119,12 @@ impl<'a> CompletionContext<'a> { |
118 | 119 | original_file.syntax().token_at_offset(position.offset).left_biased()?; |
119 | 120 | let token = sema.descend_into_macros(original_token.clone()); |
120 | 121 | let scope = sema.scope_at_offset(&token.parent(), position.offset); |
| 122 | + let mut locals = vec![]; |
| 123 | + scope.process_all_names(&mut |name, scope| { |
| 124 | + if let ScopeDef::Local(local) = scope { |
| 125 | + locals.push((name.to_string(), local)); |
| 126 | + } |
| 127 | + }); |
121 | 128 | let mut ctx = CompletionContext { |
122 | 129 | sema, |
123 | 130 | scope, |
@@ -165,6 +172,7 @@ impl<'a> CompletionContext<'a> { |
165 | 172 | if_is_prev: false, |
166 | 173 | is_match_arm: false, |
167 | 174 | has_item_list_or_source_file_parent: false, |
| 175 | + locals, |
168 | 176 | }; |
169 | 177 |
|
170 | 178 | let mut original_file = original_file.syntax().clone(); |
|
0 commit comments