Attempting to avoid a huge match statement in event_loop/mod.rs by splitting handlers up into one module per Event variant.
2ZAM5V35CAQD5MOFPZEGU4ERQ2FM5CL5MB2DOJDW2ZQ74IQFBISQC let uri = match UriAbsoluteStr::new(raw_uri) {Ok(valid_uri) => valid_uri,Err(error) => {tracing::error!(message = "Invalid URI", ?raw_uri, ?error);continue;}};// TODO: handle different schemes using `vscode.workspace.fs`if uri.scheme_str() != "file" {tracing::info!(message = "Skipping unhandled URI scheme", ?uri);continue;}let workspace_path = Utf8PathBuf::from(uri.path_str());// TODO: multiple repositories per workspacelet repository_path = workspace_path.clone();let std::collections::hash_map::Entry::Vacant(repository_entry) =repositories.entry(repository_path.clone())else {tracing::warn!(message = "Ignoring existing repository");continue;};let repository_uri = match threadsafe_functions.uri_file(repository_path.to_string()).await{Ok(repository_uri) => repository_uri,Err(error) => {tracing::error!(message = "Failed to parse URI",?repository_path,?error);continue;}};let (source_control, unrecorded_changes, untracked_paths) =match threadsafe_functions.initialize_source_control(repository_uri,String::from("Pijul"),String::from("Changes"),String::from("Untracked"),).await{Ok(initialized_source_control) => initialized_source_control,Err(error) => {tracing::error!(message = "Unable to create source control",?error);continue;}};let file_system_repository =match pijul_extension::FileSystemRepository::new(&repository_path) {Ok(repository) => repository,Err(error) => {tracing::error!(message = "Failed to open repository", ?error);continue;}};repository_entry.insert(Repository {repository: file_system_repository,source_control,open_editors: HashMap::new(),unrecorded_changes,untracked_paths,});tracing::info!(message = "Opened repository",?repository_path,?workspace_path);
event::open_workspace_folder::handle(raw_uri,&mut repositories,&threadsafe_functions,).await
use std::collections::HashMap;use camino::Utf8PathBuf;use iri_string::types::UriAbsoluteStr;use crate::event_loop::Repository;use crate::event_loop::threadsafe_function::ThreadsafeFunctions;#[tracing::instrument(skip(repositories, threadsafe_functions))]pub async fn handle(raw_uri: &str,repositories: &mut HashMap<Utf8PathBuf, Repository>,threadsafe_functions: &ThreadsafeFunctions,) {let uri = match UriAbsoluteStr::new(raw_uri) {Ok(valid_uri) => valid_uri,Err(error) => {tracing::error!(message = "Invalid URI", ?raw_uri, ?error);return;}};// TODO: handle different schemes using `vscode.workspace.fs`if uri.scheme_str() != "file" {tracing::info!(message = "Skipping unhandled URI scheme", ?uri);return;}let workspace_path = Utf8PathBuf::from(uri.path_str());// TODO: multiple repositories per workspacelet repository_path = workspace_path.clone();let std::collections::hash_map::Entry::Vacant(repository_entry) =repositories.entry(repository_path.clone())else {tracing::warn!(message = "Ignoring existing repository");return;};let repository_uri = match threadsafe_functions.uri_file(repository_path.to_string()).await{Ok(repository_uri) => repository_uri,Err(error) => {tracing::error!(message = "Failed to parse URI", ?repository_path, ?error);return;}};let (source_control, unrecorded_changes, untracked_paths) = match threadsafe_functions.initialize_source_control(repository_uri,String::from("Pijul"),String::from("Changes"),String::from("Untracked"),).await{Ok(initialized_source_control) => initialized_source_control,Err(error) => {tracing::error!(message = "Unable to create source control", ?error);return;}};let file_system_repository = match pijul_extension::FileSystemRepository::new(&repository_path){Ok(repository) => repository,Err(error) => {tracing::error!(message = "Failed to open repository", ?error);return;}};repository_entry.insert(Repository {repository: file_system_repository,source_control,open_editors: HashMap::new(),unrecorded_changes,untracked_paths,});tracing::info!(message = "Opened repository",?repository_path,?workspace_path);}
pub mod open_workspace_folder;#[derive(Debug)]pub enum Event {OpenWorkspaceFolder { uri: String },}