mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
completion snippets
This commit is contained in:
parent
b6c654e233
commit
4c1f17af7d
1 changed files with 9 additions and 2 deletions
|
@ -14,6 +14,7 @@ use {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CompletionItem {
|
pub struct CompletionItem {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub snippet: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> {
|
pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> {
|
||||||
|
@ -33,7 +34,10 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI
|
||||||
let scope = ModuleScope::new(root);
|
let scope = ModuleScope::new(root);
|
||||||
res.extend(
|
res.extend(
|
||||||
scope.entries().iter()
|
scope.entries().iter()
|
||||||
.map(|entry| CompletionItem { name: entry.name().to_string() })
|
.map(|entry| CompletionItem {
|
||||||
|
name: entry.name().to_string(),
|
||||||
|
snippet: None,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Some(res)
|
Some(res)
|
||||||
|
@ -43,7 +47,10 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi
|
||||||
acc.extend(
|
acc.extend(
|
||||||
scopes.scope_chain(name_ref.syntax())
|
scopes.scope_chain(name_ref.syntax())
|
||||||
.flat_map(|scope| scopes.entries(scope).iter())
|
.flat_map(|scope| scopes.entries(scope).iter())
|
||||||
.map(|entry| CompletionItem { name: entry.name().to_string() })
|
.map(|entry| CompletionItem {
|
||||||
|
name: entry.name().to_string(),
|
||||||
|
snippet: None,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue