Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 6c221ed3..a197792e 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -20,7 +20,7 @@ pub use typed::*;
use helix_core::{
char_idx_at_visual_offset,
chars::char_is_word,
- comment,
+ command_line, comment,
doc_formatter::TextFormat,
encoding, find_workspace,
graphemes::{self, next_grapheme_boundary},
@@ -33,7 +33,7 @@ use helix_core::{
object, pos_at_coords,
regex::{self, Regex},
search::{self, CharMatcher},
- selection, shellwords, surround,
+ selection, surround,
syntax::{BlockCommentToken, LanguageServerFeature},
text_annotations::{Overlay, TextAnnotations},
textobject,
@@ -58,7 +58,6 @@ use insert::*;
use movement::Movement;
use crate::{
- args,
compositor::{self, Component, Compositor},
filter_picker_entry,
job::Callback,
@@ -211,7 +210,7 @@ use helix_view::{align_view, Align};
pub enum MappableCommand {
Typable {
name: String,
- args: Vec<String>,
+ args: String,
doc: String,
},
Static {
@@ -246,16 +245,19 @@ 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(e) = (command.fun)(&mut cx, &args[..], PromptEvent::Validate) {
+ if let Err(e) =
+ typed::execute_command(&mut cx, command, args, PromptEvent::Validate)
+ {
cx.editor.set_error(format!("{}", e));
}
+ } else {
+ cx.editor.set_error(format!("no such command: '{name}'"));
}
}
Self::Static { fun, .. } => (fun)(cx),
@@ -629,13 +631,8 @@ impl std::str::FromStr for MappableCommand {
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(suffix) = s.strip_prefix(':') {
- 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>>();
+ let (name, args, _) = command_line::split(suffix);
+ ensure!(!name.is_empty(), "Expected typable command name");
typed::TYPABLE_COMMAND_MAP
.get(name)
.map(|cmd| {
@@ -647,7 +644,7 @@ impl std::str::FromStr for MappableCommand {
MappableCommand::Typable {
name: cmd.name.to_owned(),
doc,
- args,
+ args: args.to_string(),
}
})
.ok_or_else(|| anyhow!("No TypableCommand named '{}'", s))
@@ -3384,7 +3381,7 @@ pub fn command_palette(cx: &mut Context) {
.iter()
.map(|cmd| MappableCommand::Typable {
name: cmd.name.to_owned(),
- args: Vec::new(),
+ args: String::new(),
doc: cmd.doc.to_owned(),
}),
);