Skip to content

Commit

Permalink
expand_args to variable::expand
Browse files Browse the repository at this point in the history
  • Loading branch information
tdaron committed Dec 22, 2024
1 parent 8b1d522 commit c5a06ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 2 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(crate) mod dap;
pub(crate) mod expansions;
pub(crate) mod lsp;
pub(crate) mod typed;
pub(crate) mod variables;

pub use dap::*;
use futures_util::FutureExt;
Expand Down Expand Up @@ -252,7 +252,7 @@ impl MappableCommand {
scroll: None,
};

match expand_args(cx.editor, args.into(), true) {
match variables::expand(cx.editor, args.into(), true) {
Ok(args) => {
if let Err(err) = (command.fun)(
&mut cx,
Expand Down Expand Up @@ -724,8 +724,6 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem

use helix_core::movement::{move_horizontally, move_vertically};

use self::expansions::expand_args;

fn move_char_left(cx: &mut Context) {
move_impl(cx, move_horizontally, Direction::Backward, Movement::Move)
}
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::Deref;

use crate::job::Job;

use super::expansions::expand_args;
use super::variables;
use super::*;

use helix_core::fuzzy::fuzzy_match;
Expand Down Expand Up @@ -3122,7 +3122,7 @@ pub(super) fn command_mode(cx: &mut Context) {
}
}, // completion
move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
match expand_args(cx.editor, input.into(), true) {
match variables::expand(cx.editor, input.into(), true) {
Ok(args) => {
let shellwords = Shellwords::from(args.as_ref());
let command = shellwords.command();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use anyhow::Result;
use helix_core::coords_at_pos;
use helix_view::Editor;

pub fn expand_args<'a>(
editor: &Editor,
input: Cow<'a, str>,
expand_sh: bool,
) -> Result<Cow<'a, str>> {
pub fn expand<'a>(editor: &Editor, input: Cow<'a, str>, expand_sh: bool) -> Result<Cow<'a, str>> {
let (view, doc) = current_ref!(editor);
let shell = &editor.config().shell;

Expand Down Expand Up @@ -106,7 +102,9 @@ pub fn expand_args<'a>(
.primary()
.fragment(doc.text().slice(..))
.to_string(),
_ => anyhow::bail!("Unknown variable"),
_ => {
anyhow::bail!("Unknown variable {}", &input[index + 2..end])
}
};

o.push_str(value.trim());
Expand All @@ -128,7 +126,7 @@ pub fn expand_args<'a>(
}

if let Some(o) = output.as_mut() {
let body = expand_args(
let body = expand(
editor,
Cow::Borrowed(&input[index + 4..end]),
expand_sh,
Expand Down

0 comments on commit c5a06ef

Please sign in to comment.