Restructure action macro to assign a namespace to every action

Also, allow arbitrary types to be used as Actions via the impl_actions macro

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-07 16:20:49 -07:00
parent 206b0f0f8c
commit 5242a3a6dc
33 changed files with 432 additions and 306 deletions

View file

@ -1,3 +1,4 @@
use crate::Action;
use anyhow::anyhow;
use std::{
any::Any,
@ -6,8 +7,6 @@ use std::{
};
use tree_sitter::{Language, Node, Parser};
use crate::{Action, AnyAction};
extern "C" {
fn tree_sitter_context_predicate() -> Language;
}
@ -28,7 +27,7 @@ pub struct Keymap(Vec<Binding>);
pub struct Binding {
keystrokes: Vec<Keystroke>,
action: Box<dyn AnyAction>,
action: Box<dyn Action>,
context: Option<ContextPredicate>,
}
@ -73,7 +72,7 @@ where
pub enum MatchResult {
None,
Pending,
Action(Box<dyn AnyAction>),
Action(Box<dyn Action>),
}
impl Debug for MatchResult {
@ -329,7 +328,7 @@ impl ContextPredicate {
#[cfg(test)]
mod tests {
use crate::action;
use crate::{actions, impl_actions};
use super::*;
@ -420,9 +419,10 @@ mod tests {
#[test]
fn test_matcher() -> anyhow::Result<()> {
action!(A, &'static str);
action!(B);
action!(Ab);
#[derive(Clone)]
pub struct A(pub &'static str);
impl_actions!(test, [A]);
actions!(test, [B, Ab]);
impl PartialEq for A {
fn eq(&self, other: &Self) -> bool {