-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Giant PR making demo crate kinda presentable #52
Conversation
Instead of automatically treating everything in a CommandGroup as 1 undo group. We'll need more flexibility in undos when implementing a fancier call stack. feat: replace commandgroup with metacommand
Instead of returning it from get_content(). Should be fairly static, and this simplifies things.
This could lead to their unused undo stacks growing really big...
And move the `Keymaps` manager into another file.
Instead of requiring it to be 'static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, modes and menus! And a call stack! And Engine/Server separation!
demo/src/core_editor.rs
Outdated
lazy_static! { | ||
pub static ref LANG_SET: LanguageSet = LanguageSet::new(); | ||
pub static ref NOTE_SETS: GrowOnlyMap<LanguageName, NotationSet> = GrowOnlyMap::new(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be (i) made in main
, and (ii) probably put in a struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made in main, not in a struct for now
demo/src/core_editor.rs
Outdated
} | ||
} | ||
|
||
pub struct Core<'l> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoreEditor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait no, Engine!
demo/src/data/example_keymaps.rs
Outdated
use crate::keymaps::{FilterRule, TextKeymapFactory, TreeKeymapFactory}; | ||
use crate::prog::{Prog, Value, Word}; | ||
|
||
pub fn make_node_map<'l>(lang: &Language) -> TreeKeymapFactory<'l> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 4 functions could use doc strings
}; | ||
|
||
let divider = PaneNotation::Fill { | ||
ch: '=', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be impressive & pretty to use a unicode character here. Some possibilities:
░▒▓
═ // this is not an equal sign
▄▅▆▇█
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Characters don't work well anyways because there's no DynWidth
option for the text in the status bar. Maybe we should reverse the background instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And PaneNotations don't really support applying a Style to a whole Pane right now, so I'm leaving this as-is until those pretty
changes shake out.
demo/src/error.rs
Outdated
// Note: we can't use the inner DocError as the error source because it | ||
// contains a non-static lifetime. | ||
#[error("doc error: {0}")] | ||
DocExec(DocError<'l>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, we should eliminate lifetime parameters on error messages:
- Eliminate lifetime parameter on ServerError, EngineError, DocError.
- Delete the replace error in DocError
- Instead of docs having a replace command, have a "insert fresh node with no children" command.
- Change how keyhints are created to accommodate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the lifetime parameter from errors. We need to keep the Replace
command though, for implementing undo. Because of that, and because the Doc doesn't have access to the language set and notation sets needed to create a new node, I'd rather continue to have the Engine create new nodes and pass them to the Doc in a Replace
command. The Doc won't be able to give back a rejected node to the Engine, but that doesn't matter.
demo/src/server.rs
Outdated
let tree_context = if doc.in_tree_mode() { | ||
Some(FilterContext { | ||
required_sort: doc.self_sort(), | ||
self_arity: doc.self_arity_type(), | ||
parent_arity: doc.parent_arity_type(), | ||
}) | ||
} else { | ||
None | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider putting this in its own method. get_tree_context()
demo/src/server.rs
Outdated
fn next_event(&mut self, keymap: &FilteredKeymap) -> Result<Prog<'l>, ServerError<'l>> { | ||
match self.frontend.next_event() { | ||
Some(Ok(Event::KeyEvent(Key::Ctrl('c')))) => Err(ServerError::KeyboardInterrupt), | ||
Some(Ok(Event::KeyEvent(key))) => self | ||
.keymap_manager | ||
.lookup(key, keymap) | ||
.ok_or_else(|| ServerError::UnknownKey(key)), | ||
Some(Err(err)) => Err(err.into()), | ||
_ => Err(ServerError::UnknownEvent), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably inline this. As a bonus, it will make the borrow checker happy about the FilteredKeymap struct change.
demo/src/server.rs
Outdated
Ok(ed) | ||
} | ||
|
||
pub fn run(&mut self) -> Result<(), ServerError<'l>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use comments. (Regular comments, not doc comments.)
demo/src/server.rs
Outdated
fn update_key_hints(&mut self, keymap: &FilteredKeymap) -> Result<(), ServerError<'l>> { | ||
let lang_name = self.engine.lang_name_of(&DocLabel::KeyHints)?; | ||
|
||
let mut dict_node = self.engine.new_node("dict", lang_name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename:
- dict -> keymap
- entry -> binding
demo/src/server.rs
Outdated
} | ||
} | ||
|
||
fn update_key_hints(&mut self, keymap: &FilteredKeymap) -> Result<(), ServerError<'l>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future: make a "Virtual Doc" that implements PrettyDocument, b.c. ASTs have a terrible API for this use case, as demonstrated in this method's code. (Add a TODO.)
By removing the Ast<'l> stored in of DocError's variants.
Leftover from the old implementation of keymap filtering. If we want them again someday for something else, we can re-add them.
Split out the CoreEditor, implement mode-style and menu-style keymaps, and implement a proper callstack for the concatenative language.