aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/completion.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-26 07:12:18 +0100
committerAleksey Kladov <[email protected]>2018-08-26 07:12:18 +0100
commita450142aca947b9364e498897f522f854f19781d (patch)
treef4ebe8f259582042bd251c595629599abcbe9524 /crates/libeditor/src/completion.rs
parenta48964c64de635f532874ede293d91df54e624d7 (diff)
fix stray curly
Diffstat (limited to 'crates/libeditor/src/completion.rs')
-rw-r--r--crates/libeditor/src/completion.rs31
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 @@
1use libsyntax2::{
2 File, TextUnit,
3 ast,
4 algo::find_leaf_at_offset,
5};
6
7use {
8 AtomEdit, find_node_at_offset,
9};
10
11#[derive(Debug)]
12pub struct CompletionItem {
13 name: String,
14}
15
16pub 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
27fn complete(name_ref: ast::NameRef) -> Vec<CompletionItem> {
28 vec![CompletionItem {
29 name: "foo".to_string()
30 }]
31}