Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/args.rs')
| -rw-r--r-- | helix-term/src/args.rs | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 090c1192..0b1c9cde 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -1,7 +1,6 @@ use anyhow::Result; use helix_core::Position; use helix_view::tree::Layout; -use indexmap::IndexMap; use std::path::{Path, PathBuf}; #[derive(Default)] @@ -17,7 +16,7 @@ pub struct Args { pub verbosity: u64, pub log_file: Option<PathBuf>, pub config_file: Option<PathBuf>, - pub files: IndexMap<PathBuf, Vec<Position>>, + pub files: Vec<(PathBuf, Position)>, pub working_directory: Option<PathBuf>, } @@ -27,18 +26,6 @@ impl Args { let mut argv = std::env::args().peekable(); let mut line_number = 0; - let mut insert_file_with_position = |file_with_position: &str| { - let (filename, position) = parse_file(file_with_position); - - // Before setting the working directory, resolve all the paths in args.files - let filename = helix_stdx::path::canonicalize(filename); - - args.files - .entry(filename) - .and_modify(|positions| positions.push(position)) - .or_insert_with(|| vec![position]); - }; - argv.next(); // skip the program, we don't care about that while let Some(arg) = argv.next() { @@ -102,29 +89,24 @@ impl Args { } } } - "+" => line_number = usize::MAX, arg if arg.starts_with('+') => { match arg[1..].parse::<usize>() { Ok(n) => line_number = n.saturating_sub(1), - _ => insert_file_with_position(arg), + _ => args.files.push(parse_file(arg)), }; } - arg => insert_file_with_position(arg), + arg => args.files.push(parse_file(arg)), } } // push the remaining args, if any to the files for arg in argv { - insert_file_with_position(&arg); + args.files.push(parse_file(&arg)); } - if line_number != 0 { - if let Some(first_position) = args - .files - .first_mut() - .and_then(|(_, positions)| positions.first_mut()) - { - first_position.row = line_number; + if let Some(file) = args.files.first_mut() { + if line_number != 0 { + file.1.row = line_number; } } @@ -147,7 +129,7 @@ pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) { /// /// Does not validate if file.rs is a file or directory. fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> { - let mut s = s.trim_end_matches(':').rsplitn(3, ':'); + let mut s = s.rsplitn(3, ':'); let col: usize = s.next()?.parse().ok()?; let row: usize = s.next()?.parse().ok()?; let path = s.next()?.into(); @@ -159,7 +141,7 @@ fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> { /// /// Does not validate if file.rs is a file or directory. fn split_path_row(s: &str) -> Option<(PathBuf, Position)> { - let (path, row) = s.trim_end_matches(':').rsplit_once(':')?; + let (path, row) = s.rsplit_once(':')?; let row: usize = row.parse().ok()?; let path = path.into(); let pos = Position::new(row.saturating_sub(1), 0); |