diff options
author | Aleksey Kladov <[email protected]> | 2018-08-26 07:12:18 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-26 07:12:18 +0100 |
commit | a450142aca947b9364e498897f522f854f19781d (patch) | |
tree | f4ebe8f259582042bd251c595629599abcbe9524 /crates/libeditor/src/completion.rs | |
parent | a48964c64de635f532874ede293d91df54e624d7 (diff) |
fix stray curly
Diffstat (limited to 'crates/libeditor/src/completion.rs')
-rw-r--r-- | crates/libeditor/src/completion.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs new file mode 100644 index 000000000..cf61ec784 --- /dev/null +++ b/crates/libeditor/src/completion.rs | |||
@@ -0,0 +1,31 @@ | |||
1 | use libsyntax2::{ | ||
2 | File, TextUnit, | ||
3 | ast, | ||
4 | algo::find_leaf_at_offset, | ||
5 | }; | ||
6 | |||
7 | use { | ||
8 | AtomEdit, find_node_at_offset, | ||
9 | }; | ||
10 | |||
11 | #[derive(Debug)] | ||
12 | pub struct CompletionItem { | ||
13 | name: String, | ||
14 | } | ||
15 | |||
16 | pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> { | ||
17 | // Insert a fake ident to get a valid parse tree | ||
18 | let file = { | ||
19 | let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); | ||
20 | // Don't bother with completion if incremental reparse fails | ||
21 | file.incremental_reparse(&edit)? | ||
22 | }; | ||
23 | let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), offset)?; | ||
24 | Some(complete(name_ref)) | ||
25 | } | ||
26 | |||
27 | fn complete(name_ref: ast::NameRef) -> Vec<CompletionItem> { | ||
28 | vec![CompletionItem { | ||
29 | name: "foo".to_string() | ||
30 | }] | ||
31 | } | ||