Skip to content

Commit

Permalink
feat: type-aware autocomplete (#67)
Browse files Browse the repository at this point in the history
* feat: type-aware autocomplete

* add better context completion

* feat: add completion to imports

* feat: add completion for functions

* feat: add function to numeric autocomplete

* cargo fmt
  • Loading branch information
felixrieg authored Oct 10, 2023
1 parent 1bd3cd3 commit 08a68c5
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 96 deletions.
35 changes: 35 additions & 0 deletions uvls/src/core/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ impl Ast {
fn all_imports(&self) -> impl Iterator<Item = Symbol> + DoubleEndedIterator {
(0..self.import.len()).map(Symbol::Import)
}
fn get_import(&self, index: usize) -> Option<&Import> {
self.import.get(index)
}
fn all_features(&self) -> impl Iterator<Item = Symbol> {
(0..self.features.len()).map(Symbol::Feature)
}
Expand Down Expand Up @@ -289,6 +292,9 @@ impl AstDocument {
pub fn all_imports(&self) -> impl Iterator<Item = Symbol> + DoubleEndedIterator {
self.ast.all_imports()
}
pub fn get_import(&self, index: usize) -> Option<&Import> {
self.ast.get_import(index)
}
pub fn all_features(&self) -> impl Iterator<Item = Symbol> {
self.ast.all_features()
}
Expand Down Expand Up @@ -475,6 +481,35 @@ impl AstDocument {
}
res
}

pub fn get_symbols(&self, path: Ustr) -> Vec<Symbol> {
let mut res = vec![];
for i in 0..self.ast.features.len() {
if path == self.get_feature(i).unwrap().name.name {
res.push(Symbol::Feature(i));
}
}
if path.contains(".") {
let paths = path.split(".").collect_vec();
let feature = self.get_symbols(Ustr::from(paths[0]));
if let Some(Symbol::Feature(x)) = feature.first() {
for child in self.direct_children(Symbol::Feature(x.clone())) {
match child {
Symbol::Attribute(a) => {
if paths[1].to_string()
== self.get_attribute(a).unwrap().name.name.to_string()
{
res.push(Symbol::Attribute(a));
}
}
_ => (),
}
}
}
}
res
}

//prefix of sym from root
pub fn prefix(&self, mut sym: Symbol) -> Vec<Ustr> {
if matches!(sym, Symbol::Import(..)) {
Expand Down
4 changes: 3 additions & 1 deletion uvls/src/core/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ impl ConfigModule {
//Turns a the set of linear configuration values of this module into theire recusive from
//used in json
pub fn serialize(&self) -> Vec<ConfigEntry> {
let ConfigEntry::Import(_,v) = self.serialize_rec(&[],InstanceID(0)) else {unreachable!()};
let ConfigEntry::Import(_, v) = self.serialize_rec(&[], InstanceID(0)) else {
unreachable!()
};
v
}
}
Expand Down
Loading

0 comments on commit 08a68c5

Please sign in to comment.