Move event handling into modules
Dependencies
- [2]
3YGYMEXVCreate `event_loop` module - [3]
TDTLSDFGCreate macro for defining `ThreadsafeFunction`s - [4]
NB2MF3MYAdd `OpenWorkspaceFolder` event - [5]
MGJ23FHFAssign repository URI to source control in `OpenWorkspaceFolder` events - [6]
OUADGWKRCreate fully-initialized `SourceControl` object in `event_loop`
Change contents
- edit in editors/vscode/src/event_loop/mod.rs at line 5
use iri_string::types::UriAbsoluteStr; - edit in editors/vscode/src/event_loop/mod.rs at line 8
// Re-export Event so it can be used by callerspub use event::Event; - edit in editors/vscode/src/event_loop/mod.rs at line 12
mod event; - edit in editors/vscode/src/event_loop/mod.rs at line 19
#[derive(Debug)]pub enum Event {OpenWorkspaceFolder { uri: String },} - replacement in editors/vscode/src/event_loop/mod.rs at line 50[5.1532]→[5.1532:2356](∅→∅),[5.2356]→[6.3019:3408](∅→∅),[6.3408]→[5.2428:2544](∅→∅),[5.2428]→[5.2428:2544](∅→∅),[5.2544]→[6.3409:3471](∅→∅),[6.3471]→[5.2614:2971](∅→∅),[5.2614]→[5.2614:2971](∅→∅),[5.2971]→[6.3472:4411](∅→∅),[6.4411]→[5.2971:2972](∅→∅),[5.2971]→[5.2971:2972](∅→∅),[5.2972]→[6.4412:5172](∅→∅),[6.5172]→[5.3198:3199](∅→∅),[4.2519]→[5.3198:3199](∅→∅),[5.3199]→[6.5173:5369](∅→∅)
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 - file addition: event[2.138]
- file addition: open_workspace_folder.rs[0.332]
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);} - file addition: mod.rs[0.332]
pub mod open_workspace_folder;#[derive(Debug)]pub enum Event {OpenWorkspaceFolder { uri: String },}