diff options
Diffstat (limited to 'crates/libeditor')
-rw-r--r-- | crates/libeditor/src/completion.rs | 13 | ||||
-rw-r--r-- | crates/libeditor/src/scope/fn_scope.rs | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index 06a607265..f3058c023 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs | |||
@@ -142,6 +142,12 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi | |||
142 | snippet: None, | 142 | snippet: None, |
143 | }) | 143 | }) |
144 | ); | 144 | ); |
145 | if scopes.self_param.is_some() { | ||
146 | acc.push(CompletionItem { | ||
147 | name: "self".to_string(), | ||
148 | snippet: None, | ||
149 | }) | ||
150 | } | ||
145 | } | 151 | } |
146 | 152 | ||
147 | #[cfg(test)] | 153 | #[cfg(test)] |
@@ -250,6 +256,13 @@ mod tests { | |||
250 | } | 256 | } |
251 | 257 | ||
252 | #[test] | 258 | #[test] |
259 | fn test_complete_self() { | ||
260 | check_scope_completion(r" | ||
261 | impl S { fn foo(&self) { <|> } } | ||
262 | ", r#"[CompletionItem { name: "self", snippet: None }]"#) | ||
263 | } | ||
264 | |||
265 | #[test] | ||
253 | fn test_completion_kewords() { | 266 | fn test_completion_kewords() { |
254 | check_snippet_completion(r" | 267 | check_snippet_completion(r" |
255 | fn quux() { | 268 | fn quux() { |
diff --git a/crates/libeditor/src/scope/fn_scope.rs b/crates/libeditor/src/scope/fn_scope.rs index 5c04e2f9b..78e9c061c 100644 --- a/crates/libeditor/src/scope/fn_scope.rs +++ b/crates/libeditor/src/scope/fn_scope.rs | |||
@@ -13,6 +13,7 @@ type ScopeId = usize; | |||
13 | 13 | ||
14 | #[derive(Debug)] | 14 | #[derive(Debug)] |
15 | pub struct FnScopes { | 15 | pub struct FnScopes { |
16 | pub self_param: Option<SyntaxNode>, | ||
16 | scopes: Vec<ScopeData>, | 17 | scopes: Vec<ScopeData>, |
17 | scope_for: HashMap<SyntaxNode, ScopeId>, | 18 | scope_for: HashMap<SyntaxNode, ScopeId>, |
18 | } | 19 | } |
@@ -20,6 +21,9 @@ pub struct FnScopes { | |||
20 | impl FnScopes { | 21 | impl FnScopes { |
21 | pub fn new(fn_def: ast::FnDef) -> FnScopes { | 22 | pub fn new(fn_def: ast::FnDef) -> FnScopes { |
22 | let mut scopes = FnScopes { | 23 | let mut scopes = FnScopes { |
24 | self_param: fn_def.param_list() | ||
25 | .and_then(|it| it.self_param()) | ||
26 | .map(|it| it.syntax().owned()), | ||
23 | scopes: Vec::new(), | 27 | scopes: Vec::new(), |
24 | scope_for: HashMap::new() | 28 | scope_for: HashMap::new() |
25 | }; | 29 | }; |