Revert "refactor(shellwords)!: change arg handling strategy (#11149)"

This reverts commit 64b38d1a28.
This commit is contained in:
Michael Davis 2025-01-06 12:39:53 -05:00
parent 03f35af9c1
commit 217818681e
No known key found for this signature in database
5 changed files with 725 additions and 1055 deletions

File diff suppressed because it is too large Load diff

View file

@ -30,9 +30,7 @@ use helix_core::{
object, pos_at_coords,
regex::{self, Regex},
search::{self, CharMatcher},
selection,
shellwords::{self, Args},
surround,
selection, shellwords, surround,
syntax::{BlockCommentToken, LanguageServerFeature},
text_annotations::{Overlay, TextAnnotations},
textobject,
@ -209,7 +207,7 @@ use helix_view::{align_view, Align};
pub enum MappableCommand {
Typable {
name: String,
args: String,
args: Vec<String>,
doc: String,
},
Static {
@ -244,17 +242,15 @@ impl MappableCommand {
pub fn execute(&self, cx: &mut Context) {
match &self {
Self::Typable { name, args, doc: _ } => {
let args: Vec<Cow<str>> = args.iter().map(Cow::from).collect();
if let Some(command) = typed::TYPABLE_COMMAND_MAP.get(name.as_str()) {
let mut cx = compositor::Context {
editor: cx.editor,
jobs: cx.jobs,
scroll: None,
};
if let Err(err) =
(command.fun)(&mut cx, Args::from(args), PromptEvent::Validate)
{
cx.editor.set_error(format!("{err}"));
if let Err(e) = (command.fun)(&mut cx, &args[..], PromptEvent::Validate) {
cx.editor.set_error(format!("{}", e));
}
}
}
@ -625,15 +621,21 @@ impl std::str::FromStr for MappableCommand {
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(suffix) = s.strip_prefix(':') {
let (name, args) = suffix.split_once(' ').unwrap_or((suffix, ""));
let mut typable_command = suffix.split(' ').map(|arg| arg.trim());
let name = typable_command
.next()
.ok_or_else(|| anyhow!("Expected typable command name"))?;
let args = typable_command
.map(|s| s.to_owned())
.collect::<Vec<String>>();
typed::TYPABLE_COMMAND_MAP
.get(name)
.map(|cmd| MappableCommand::Typable {
name: cmd.name.to_owned(),
doc: format!(":{} {:?}", cmd.name, args),
args: args.to_string(),
args,
})
.ok_or_else(|| anyhow!("No TypableCommand named '{}'", name))
.ok_or_else(|| anyhow!("No TypableCommand named '{}'", s))
} else if let Some(suffix) = s.strip_prefix('@') {
helix_view::input::parse_macro(suffix).map(|keys| Self::Macro {
name: s.to_string(),
@ -3252,7 +3254,7 @@ pub fn command_palette(cx: &mut Context) {
.iter()
.map(|cmd| MappableCommand::Typable {
name: cmd.name.to_owned(),
args: String::new(),
args: Vec::new(),
doc: cmd.doc.to_owned(),
}),
);
@ -4326,19 +4328,13 @@ fn yank_joined_impl(editor: &mut Editor, separator: &str, register: char) {
let (view, doc) = current!(editor);
let text = doc.text().slice(..);
let separator = if separator.is_empty() {
doc.line_ending.as_str()
} else {
separator
};
let selection = doc.selection(view.id);
let selections = selection.len();
let joined = selection
.fragments(text)
.fold(String::new(), |mut acc, fragment| {
if !acc.is_empty() {
acc.push_str(&shellwords::unescape(separator));
acc.push_str(separator);
}
acc.push_str(&fragment);
acc

View file

@ -109,7 +109,6 @@ fn dap_callback<T, F>(
jobs.callback(callback);
}
// TODO: transition to `shellwords::Args` instead of `Option<Vec<Cow>>>`
pub fn dap_start_impl(
cx: &mut compositor::Context,
name: Option<&str>,
@ -313,7 +312,6 @@ pub fn dap_restart(cx: &mut Context) {
);
}
// TODO: transition to `shellwords::Args` instead of `Vec<String>`
fn debug_parameter_prompt(
completions: Vec<DebugConfigCompletion>,
config_name: String,

File diff suppressed because it is too large Load diff

View file

@ -597,14 +597,18 @@ mod tests {
let expectation = KeyTrie::Node(KeyTrieNode::new(
"",
hashmap! {
key => KeyTrie::Sequence(vec![
key => KeyTrie::Sequence(vec!{
MappableCommand::select_all,
MappableCommand::Typable {
name: "pipe".to_string(),
args: String::from("sed -E 's/\\s+$//g'"),
doc: String::new(),
args: vec!{
"sed".to_string(),
"-E".to_string(),
"'s/\\s+$//g'".to_string()
},
doc: "".to_string(),
},
])
})
},
vec![key],
));