Skip to content

Commit

Permalink
removed default workspace and language, added cli arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmikwolf committed May 17, 2024
1 parent 6142dfa commit 5bd517a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rust 1.77.2
rust 1.78
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repository = "https://github.com/cosmikwolf/sazid"
authors = ["tenkai <tenkai@kariya.ai>"]
categories = ["coding assistant"]
license = "Apache 2.0 / MIT"
rust-version = "1.77.2"
rust-version = "1.78"
homepage = "https://github.com/cosmikwolf/sazid"


Expand Down
28 changes: 18 additions & 10 deletions sazid-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn setup_integration_logging() {
}

impl Application {
pub fn new(_args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Self, Error> {
pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Self, Error> {
#[cfg(feature = "integration")]
setup_integration_logging();

Expand Down Expand Up @@ -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");
Expand Down
100 changes: 49 additions & 51 deletions sazid-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub working_directory: Option<PathBuf>,
pub workspace: Option<PathBuf>,
pub language: Option<String>,
}

impl Args {
Expand All @@ -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("--") => {
Expand All @@ -91,24 +104,9 @@ impl Args {
}
}
},
arg if arg.starts_with('+') => {
match arg[1..].parse::<usize>() {
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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion sazid-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 1 addition & 36 deletions sazid-term/src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,6 @@ impl<'a> MessageCell<'a> {
highlight_range: Option<std::ops::Range<usize>>,
highlight_style: Option<Style>,
) -> Option<Rope> {
// log::warn!(
// "plain:{}---------buff:{}-----\nformat text x: {} y: {} width: {} height:{}\nwrap: {:?}",
// output_plain_text,
// output_buffer,
// area.x,
// area.y,
// area.width,
// area.height,
// wrap
// );
//
let mut styled = text.lines.iter().flat_map(|spans| {
spans
.0
Expand Down Expand Up @@ -209,7 +198,7 @@ impl<'a> MessageCell<'a> {
let mut y = -(skip_lines as i16);
let mut char_counter = char_idx.unwrap_or(0);
while let Some((current_line, current_line_width)) = line_composer.next_line() {
let mut x = 0; // get_line_offset(current_line_width, area.width, alignment);
let mut x = 0;
let mut linelens = vec![];
let idx_start = char_counter;
for (StyledGrapheme { symbol, style }, grapheme_index) in current_line.iter().zip(idx_start..)
Expand All @@ -220,37 +209,13 @@ impl<'a> MessageCell<'a> {
(highlight_range.as_ref(), highlight_style)
{
if highlight_range.contains(&grapheme_index) {
// log::info!(
// "hl: {} {} {} {} {}",
// symbol,
// area.left() + x,
// area.top() + y,
// char_counter,
// grapheme_index
// );
// buf.set_style(
// Rect {
// x: area.left() + x,
// y: area.top() + y - self.scroll.0,
// width: symbol.width() as u16,
// height: 1,
// },
// highlight_style,
// );
highlight_style
} else {
*style
}
} else {
*style
};
// if symbol.is_empty() {
// // If the symbol is empty, the last char which rendered last time will
// // leave on the line. It's a quick fix.
// " "
// } else {
// symbol
// };
if output_plain_text {
plain_text.push_str(symbol);
}
Expand Down

0 comments on commit 5bd517a

Please sign in to comment.