feat: support configurable tabline status label
This commit is contained in:
+59
-5
@@ -34,6 +34,7 @@ pub struct Config {
|
||||
pub file_picker_view: String,
|
||||
pub file_explorer_view: String,
|
||||
pub clipboard_mode: String,
|
||||
pub tabline_label: String,
|
||||
pub diff_context_lines: usize,
|
||||
pub diff_expand_lines: usize,
|
||||
}
|
||||
@@ -70,6 +71,7 @@ impl Default for Config {
|
||||
file_picker_view: "tree".into(),
|
||||
file_explorer_view: "tree".into(),
|
||||
clipboard_mode: "system".into(),
|
||||
tabline_label: String::new(),
|
||||
diff_context_lines: 10,
|
||||
diff_expand_lines: 15,
|
||||
}
|
||||
@@ -92,6 +94,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
|
||||
file_picker_view,
|
||||
file_explorer_view,
|
||||
clipboard_mode,
|
||||
tabline_label,
|
||||
diff_context_lines,
|
||||
diff_expand_lines,
|
||||
..
|
||||
@@ -116,6 +119,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
|
||||
config.file_picker_view = file_picker_view;
|
||||
config.file_explorer_view = file_explorer_view;
|
||||
config.clipboard_mode = clipboard_mode;
|
||||
config.tabline_label = tabline_label;
|
||||
config.diff_context_lines = diff_context_lines;
|
||||
config.diff_expand_lines = diff_expand_lines;
|
||||
Ok(config)
|
||||
@@ -346,6 +350,7 @@ fn convert_effects(effects: Vec<WireEffect>) -> Vec<Effect> {
|
||||
WireEffect::Insert { text } => Effect::Insert(text),
|
||||
WireEffect::Replace { text } => Effect::Replace(text),
|
||||
WireEffect::Message { text } => Effect::Message(text),
|
||||
WireEffect::TablineLabel { text } => Effect::TablineLabel(text),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -433,6 +438,7 @@ enum Response {
|
||||
file_picker_view: String,
|
||||
file_explorer_view: String,
|
||||
clipboard_mode: String,
|
||||
tabline_label: String,
|
||||
#[serde(deserialize_with = "diff_context_lines")]
|
||||
diff_context_lines: usize,
|
||||
#[serde(deserialize_with = "diff_expand_lines")]
|
||||
@@ -494,6 +500,8 @@ enum WireEffect {
|
||||
Replace { text: String },
|
||||
#[serde(rename = "message")]
|
||||
Message { text: String },
|
||||
#[serde(rename = "tabline_label")]
|
||||
TablineLabel { text: String },
|
||||
}
|
||||
|
||||
struct OutboundFrame {
|
||||
@@ -882,6 +890,8 @@ Vamp.command "greet" do |editor, args|
|
||||
editor.insert "Hello #{args}!"
|
||||
editor.replace editor.text
|
||||
editor.message "Greeting inserted"
|
||||
editor.tabline_label "界 e\u0301 👩🚀\t\n\e"
|
||||
editor.tabline_label ""
|
||||
end
|
||||
"#);
|
||||
assert_eq!(feature.name, "greeting");
|
||||
@@ -892,8 +902,9 @@ end
|
||||
for _ in 0..2 {
|
||||
let effects = plugin.invoke("greet", "friend", &context()).unwrap();
|
||||
assert!(
|
||||
matches!(&effects[..], [Effect::Insert(text), Effect::Replace(replacement), Effect::Message(message)]
|
||||
if text == "Hello friend!" && replacement == "α\nhello" && message == "Greeting inserted")
|
||||
matches!(&effects[..], [Effect::Insert(text), Effect::Replace(replacement), Effect::Message(message), Effect::TablineLabel(label), Effect::TablineLabel(cleared)]
|
||||
if text == "Hello friend!" && replacement == "α\nhello" && message == "Greeting inserted"
|
||||
&& label == "界 e\u{301} 👩🚀\t\n\u{1b}" && cleared.is_empty())
|
||||
);
|
||||
}
|
||||
plugin.disable();
|
||||
@@ -1152,14 +1163,53 @@ end
|
||||
assert!(load_config(&path).unwrap_err().contains(error), "{value}");
|
||||
}
|
||||
for frame in [
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"leader":null,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"leader":7,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","tabline_label":"","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"leader":null,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","tabline_label":"","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
r#"{"type":"config","version":1,"plugins":[],"lsp":{},"bindings":[],"leader":7,"file_explorer_side":"right","file_picker_view":"list","file_explorer_view":"tree","clipboard_mode":"system","tabline_label":"","diff_context_lines":10,"diff_expand_lines":15}"#,
|
||||
] {
|
||||
assert!(serde_json::from_str::<Response>(frame).is_err(), "{frame}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_tabline_label_defaults_accepts_empty_and_rejects_non_strings() {
|
||||
let fixture = Fixture::new();
|
||||
for (value, expected) in [
|
||||
(r#""""#, ""),
|
||||
(r#""界 e\u0301 👩🚀\t\n\e""#, "界 e\u{301} 👩🚀\t\n\u{1b}"),
|
||||
] {
|
||||
let path = fixture.file(
|
||||
"config.rb",
|
||||
&format!("Vamp.configure {{ |config| config.tabline_label = {value} }}"),
|
||||
);
|
||||
assert_eq!(load_config(&path).unwrap().tabline_label, expected);
|
||||
}
|
||||
for value in ["7", "nil", "true", "{}", "[]", "-> { 'label' }"] {
|
||||
let path = fixture.file(
|
||||
"config.rb",
|
||||
&format!("Vamp.configure {{ |config| config.tabline_label = {value} }}"),
|
||||
);
|
||||
let error = load_config(&path).unwrap_err();
|
||||
assert!(
|
||||
error.contains("tabline label must be a String"),
|
||||
"{value}: {error}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tabline_label_wire_effects_require_string_text() {
|
||||
for frame in [
|
||||
serde_json::json!({"type": "tabline_label"}),
|
||||
serde_json::json!({"type": "tabline_label", "text": null}),
|
||||
serde_json::json!({"type": "tabline_label", "text": 7}),
|
||||
serde_json::json!({"type": "tabline_label", "text": "", "extra": true}),
|
||||
] {
|
||||
assert!(serde_json::from_value::<WireEffect>(frame.clone()).is_err());
|
||||
assert!(serde_json::from_value::<UpdateEffect>(frame).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_diff_excerpt_counts_accept_custom_values_and_reject_invalid_values() {
|
||||
let fixture = Fixture::new();
|
||||
@@ -1180,6 +1230,7 @@ end
|
||||
"version": 1, "type": "config", "plugins": [], "lsp": {},
|
||||
"bindings": [], "leader": "space", "file_explorer_side": "right",
|
||||
"file_picker_view": "tree", "file_explorer_view": "tree",
|
||||
"tabline_label": "",
|
||||
"clipboard_mode": "system", "diff_context_lines": 0, "diff_expand_lines": 7
|
||||
});
|
||||
for setting in ["diff_context_lines", "diff_expand_lines"] {
|
||||
@@ -1592,6 +1643,7 @@ end"#,
|
||||
"version": 1, "type": "config", "plugins": [], "lsp": {},
|
||||
"bindings": [], "leader": "space", "file_explorer_side": "right",
|
||||
"file_picker_view": "tree", "file_explorer_view": "tree",
|
||||
"tabline_label": "",
|
||||
"clipboard_mode": "system", "diff_context_lines": 10, "diff_expand_lines": 15
|
||||
});
|
||||
let Response::Config { lsp, .. } =
|
||||
@@ -1674,6 +1726,8 @@ end"#,
|
||||
for mutation in [
|
||||
"return '['",
|
||||
"frame.delete('lsp')",
|
||||
"frame.delete('tabline_label')",
|
||||
"frame['tabline_label'] = 7",
|
||||
"frame['leader'] = 7",
|
||||
"frame['unexpected'] = true",
|
||||
] {
|
||||
|
||||
Reference in New Issue
Block a user