refactor: derive canonical commands from core actions and centralize aliases
This commit is contained in:
+43
-1
@@ -516,6 +516,7 @@ impl Host {
|
||||
#[derive(Serialize)]
|
||||
struct Startup<'a> {
|
||||
core_actions: crate::editor::CoreActionCatalog,
|
||||
command_aliases: crate::editor::CoreCommandAliases,
|
||||
options: &'a serde_json::Value,
|
||||
}
|
||||
let mut encoded_startup = FrameWriter(Vec::new());
|
||||
@@ -523,6 +524,7 @@ impl Host {
|
||||
&mut encoded_startup,
|
||||
&Startup {
|
||||
core_actions: crate::editor::CoreActionCatalog,
|
||||
command_aliases: crate::editor::CoreCommandAliases,
|
||||
options,
|
||||
},
|
||||
)
|
||||
@@ -1018,7 +1020,20 @@ end"#,
|
||||
#[test]
|
||||
fn raw_builtin_aliases_are_not_external_binding_commands() {
|
||||
let fixture = Fixture::new();
|
||||
for name in ["q", "core.quit"] {
|
||||
for name in [
|
||||
"quit",
|
||||
"save",
|
||||
"buffer_next",
|
||||
"q",
|
||||
"w",
|
||||
"bnext",
|
||||
"q!",
|
||||
"wq",
|
||||
"bprev",
|
||||
"bdelete",
|
||||
"bdelete!",
|
||||
"core.quit",
|
||||
] {
|
||||
let config = fixture.file(
|
||||
"config.rb",
|
||||
&format!("Vamp.configure {{ |config| config.bind 'K', '{name}' }}"),
|
||||
@@ -1027,6 +1042,33 @@ end"#,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plugin_commands_cannot_shadow_canonical_commands_or_aliases() {
|
||||
let fixture = Fixture::new();
|
||||
for name in [
|
||||
"quit",
|
||||
"save",
|
||||
"buffer_next",
|
||||
"q",
|
||||
"w",
|
||||
"bnext",
|
||||
"q!",
|
||||
"wq",
|
||||
"bprev",
|
||||
"bdelete",
|
||||
"bdelete!",
|
||||
] {
|
||||
let path = fixture.file(
|
||||
"plugin.rb",
|
||||
&format!("Vamp.plugin 'shadow'\nVamp.command '{name}' do |editor, args|\nend"),
|
||||
);
|
||||
assert!(
|
||||
RubyPlugin::start(&path, &serde_json::json!({})).is_err(),
|
||||
"plugin shadowed built-in command {name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_resolves_relative_paths_and_rejects_invalid_types_and_core() {
|
||||
let fixture = Fixture::new();
|
||||
|
||||
Reference in New Issue
Block a user