From 5bd517a05fb49382a1b2467ab57fab0d01756e22 Mon Sep 17 00:00:00 2001 From: tenkai Date: Thu, 16 May 2024 19:35:32 -0700 Subject: [PATCH] removed default workspace and language, added cli arguments --- .tool-versions | 2 +- Cargo.toml | 2 +- sazid-term/src/application.rs | 28 +++++---- sazid-term/src/args.rs | 100 ++++++++++++++++---------------- sazid-term/src/main.rs | 2 +- sazid-term/src/widgets/table.rs | 37 +----------- 6 files changed, 71 insertions(+), 100 deletions(-) diff --git a/.tool-versions b/.tool-versions index 0ebfebc..0082a9e 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -rust 1.77.2 +rust 1.78 diff --git a/Cargo.toml b/Cargo.toml index 018f819..8f449da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ repository = "https://github.com/cosmikwolf/sazid" authors = ["tenkai "] categories = ["coding assistant"] license = "Apache 2.0 / MIT" -rust-version = "1.77.2" +rust-version = "1.78" homepage = "https://github.com/cosmikwolf/sazid" diff --git a/sazid-term/src/application.rs b/sazid-term/src/application.rs index 8150238..8fbc584 100644 --- a/sazid-term/src/application.rs +++ b/sazid-term/src/application.rs @@ -113,7 +113,7 @@ fn setup_integration_logging() { } impl Application { - pub fn new(_args: Args, config: Config, lang_loader: syntax::Loader) -> Result { + pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result { #[cfg(feature = "integration")] setup_integration_logging(); @@ -176,15 +176,23 @@ impl Application { let session_events = UnboundedReceiverStream::new(session_rx); let mut session_config = config.load().session.clone(); - session_config.workspace = Some(WorkspaceParams { - workspace_path: PathBuf::from( - "/Users/tenkai/Development/gpt/sazid/sazid", - // "/Users/tenkai/Development/gpt/rust_test_project", - ), - language: "rust".to_string(), - language_server: "rust-analyzer".to_string(), - doc_path: None, - }); + match (args.workspace, args.language) { + (Some(workspace_path), Some(language)) => { + session_config.workspace = Some(WorkspaceParams { + workspace_path, + language, + language_server: "rust-analyzer".to_string(), + doc_path: None, + }); + }, + (None, None) => {}, + (None, Some(_)) => { + anyhow::bail!("--language must be used with --workspace"); + }, + (Some(_), None) => { + anyhow::bail!("--workspace must be used with --language"); + }, + } let mut session = Session::new(session_tx, Some(session_config)); session.set_system_prompt("you are an expert programming assistant"); diff --git a/sazid-term/src/args.rs b/sazid-term/src/args.rs index e4b38f7..0f43ac0 100644 --- a/sazid-term/src/args.rs +++ b/sazid-term/src/args.rs @@ -17,7 +17,8 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, - pub working_directory: Option, + pub workspace: Option, + pub language: Option, } impl Args { @@ -32,49 +33,61 @@ impl Args { match arg.as_str() { "--" => break, // stop parsing at this point treat the remaining as files "--version" => args.display_version = true, - "--help" => args.display_help = true, - "--tutor" => args.load_tutor = true, - "--vsplit" => match args.split { - Some(_) => { - anyhow::bail!("can only set a split once of a specific type") - }, - None => args.split = Some(Layout::Vertical), - }, - "--hsplit" => match args.split { - Some(_) => { - anyhow::bail!("can only set a split once of a specific type") - }, - None => args.split = Some(Layout::Horizontal), + // "--help" => args.display_help = true, + // "--tutor" => args.load_tutor = true, + // "--vsplit" => match args.split { + // Some(_) => { + // anyhow::bail!("can only set a split once of a specific type") + // }, + // None => args.split = Some(Layout::Vertical), + // }, + // "--hsplit" => match args.split { + // Some(_) => { + // anyhow::bail!("can only set a split once of a specific type") + // }, + // None => args.split = Some(Layout::Horizontal), + // }, + // "--health" => { + // args.health = true; + // args.health_arg = argv.next_if(|opt| !opt.starts_with('-')); + // }, + // "-g" | "--grammar" => match argv.next().as_deref() { + // Some("fetch") => args.fetch_grammars = true, + // Some("build") => args.build_grammars = true, + // _ => { + // anyhow::bail!("--grammar must be followed by either 'fetch' or 'build'") + // }, + // }, + "-c" | "--config" => { + todo!(); + match argv.next().as_deref() { + Some(path) => args.config_file = Some(path.into()), + None => anyhow::bail!("--config must specify a path to read"), + } }, - "--health" => { - args.health = true; - args.health_arg = argv.next_if(|opt| !opt.starts_with('-')); + "--log" => { + todo!(); + match argv.next().as_deref() { + Some(path) => args.log_file = Some(path.into()), + None => anyhow::bail!("--log must specify a path to write"), + } }, - "-g" | "--grammar" => match argv.next().as_deref() { - Some("fetch") => args.fetch_grammars = true, - Some("build") => args.build_grammars = true, - _ => { - anyhow::bail!("--grammar must be followed by either 'fetch' or 'build'") + "-l" | "--language" => match argv.next().as_deref() { + Some(language) => { + args.language = Some(language.into()); }, + None => {}, }, - "-c" | "--config" => match argv.next().as_deref() { - Some(path) => args.config_file = Some(path.into()), - None => anyhow::bail!("--config must specify a path to read"), - }, - "--log" => match argv.next().as_deref() { - Some(path) => args.log_file = Some(path.into()), - None => anyhow::bail!("--log must specify a path to write"), - }, - "-w" | "--working-dir" => match argv.next().as_deref() { + "-w" | "--workspace" => match argv.next().as_deref() { Some(path) => { - args.working_directory = if Path::new(path).is_dir() { + args.workspace = if Path::new(path).is_dir() { Some(PathBuf::from(path)) } else { - anyhow::bail!("--working-dir specified does not exist or is not a directory") + anyhow::bail!("--workspace specified does not exist or is not a directory") } }, None => { - anyhow::bail!("--working-dir must specify an initial working directory") + // anyhow::bail!("--workspace must specify an initial working directory") }, }, arg if arg.starts_with("--") => { @@ -91,24 +104,9 @@ impl Args { } } }, - arg if arg.starts_with('+') => { - match arg[1..].parse::() { - Ok(n) => line_number = n.saturating_sub(1), - _ => args.files.push(parse_file(arg)), - }; + arg => { + anyhow::bail!("unexpected argument: {:?}", arg); }, - arg => args.files.push(parse_file(arg)), - } - } - - // push the remaining args, if any to the files - for arg in argv { - args.files.push(parse_file(&arg)); - } - - if let Some(file) = args.files.first_mut() { - if line_number != 0 { - file.1.row = line_number; } } diff --git a/sazid-term/src/main.rs b/sazid-term/src/main.rs index 18516a7..466a3fd 100644 --- a/sazid-term/src/main.rs +++ b/sazid-term/src/main.rs @@ -172,7 +172,7 @@ FLAGS: // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that // Application::new() depends on this logic so it must be updated if this changes. - if let Some(path) = &args.working_directory { + if let Some(path) = &args.workspace { helix_stdx::env::set_current_working_dir(path)?; } else if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) { // If the first file is a directory, it will be the working directory unless -w was specified diff --git a/sazid-term/src/widgets/table.rs b/sazid-term/src/widgets/table.rs index 27e7935..6914c2b 100644 --- a/sazid-term/src/widgets/table.rs +++ b/sazid-term/src/widgets/table.rs @@ -170,17 +170,6 @@ impl<'a> MessageCell<'a> { highlight_range: Option>, highlight_style: Option