-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autocompletions for functions and variables (#28)
# Objective Fixes #26 ## Solution There's a new command (`UpdateAutoComplete`) that the UI calls when the command is changed or when the cursor moves (currently does it every frame). Then the `UpdateAutoComplete` command calls `CommandParser::completion` which then makes the current command parser return a list of `CompletionSuggestion`s, which is then displayed to user. --- ## Changelog - Added autocompletions - The `CommandParser` trait has a new optional method: `completion`, every time the UI calls this method every time the command changes or the cursor changes. - The Builtin-parser now implements the new optional `CommandParser` method. - Added `CompletionSuggestion`, which represents a completion suggestion. - ...other stuff i probably forgot about
- Loading branch information
Showing
10 changed files
with
348 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bevy::prelude::*; | ||
|
||
use super::runner::environment::Variable; | ||
use super::Environment; | ||
|
||
/// Stores the names of variables and functions for fast async access. | ||
#[derive(Resource)] | ||
pub struct EnvironmentCache { | ||
pub function_names: Vec<String>, | ||
pub variable_names: Vec<String>, | ||
} | ||
impl FromWorld for EnvironmentCache { | ||
fn from_world(world: &mut World) -> Self { | ||
if let Some(environment) = world.get_non_send_resource::<Environment>() { | ||
store_in_cache(environment) | ||
} else { | ||
Self::empty() | ||
} | ||
} | ||
} | ||
impl EnvironmentCache { | ||
pub const fn empty() -> Self { | ||
EnvironmentCache { | ||
function_names: Vec::new(), | ||
variable_names: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
pub fn store_in_cache(environment: &Environment) -> EnvironmentCache { | ||
let mut function_names = Vec::new(); | ||
let mut variable_names = Vec::new(); | ||
store_in_cache_vec(environment, &mut function_names, &mut variable_names); | ||
|
||
EnvironmentCache { | ||
function_names, | ||
variable_names, | ||
} | ||
} | ||
fn store_in_cache_vec( | ||
environment: &Environment, | ||
function_names: &mut Vec<String>, | ||
variable_names: &mut Vec<String>, | ||
) { | ||
for (name, variable) in &environment.variables { | ||
match variable { | ||
Variable::Function(_) => function_names.push(name.clone()), | ||
Variable::Unmoved(_) => variable_names.push(name.clone()), | ||
Variable::Moved => {} | ||
} | ||
} | ||
if let Some(environment) = &environment.parent { | ||
store_in_cache_vec(environment, function_names, variable_names); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.