blob: cf61ec784d1b2cd4d1ccb900418e3699d88502d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use libsyntax2::{
File, TextUnit,
ast,
algo::find_leaf_at_offset,
};
use {
AtomEdit, find_node_at_offset,
};
#[derive(Debug)]
pub struct CompletionItem {
name: String,
}
pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> {
// Insert a fake ident to get a valid parse tree
let file = {
let edit = AtomEdit::insert(offset, "intellijRulezz".to_string());
// Don't bother with completion if incremental reparse fails
file.incremental_reparse(&edit)?
};
let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), offset)?;
Some(complete(name_ref))
}
fn complete(name_ref: ast::NameRef) -> Vec<CompletionItem> {
vec![CompletionItem {
name: "foo".to_string()
}]
}
|