use std::rc::Rc;
use camino::Utf8PathBuf;
use iri_string::types::UriAbsoluteString;
use napi::bindgen_prelude::{External, FnArgs, Object};
use pijul_extension::path_state::PathState;
use crate::vscode_sys;
pub mod fire_decoration_change_event;
pub mod get_text_editor_contents;
pub mod get_text_editor_is_dirty;
pub mod get_text_editor_selections;
pub mod initialize_source_control;
pub mod set_text_editor_decorations;
pub mod update_resource_states;
pub struct Functions {
fire_decoration_change_event: fire_decoration_change_event::Prototype,
get_text_editor_contents: get_text_editor_contents::Prototype,
get_text_editor_is_dirty: get_text_editor_is_dirty::Prototype,
get_text_editor_selections: get_text_editor_selections::Prototype,
initialize_source_control: initialize_source_control::Prototype,
set_text_editor_decorations: set_text_editor_decorations::Prototype,
update_resource_states: update_resource_states::Prototype,
uri_file: vscode_sys::threadsafe_function::uri::file::Prototype,
}
impl Functions {
pub fn get(env: &napi::Env, vscode_object: &Object) -> Result<Self, napi::Error> {
Ok(Self {
fire_decoration_change_event: fire_decoration_change_event::build(env)?,
get_text_editor_contents: get_text_editor_contents::build(env)?,
get_text_editor_is_dirty: get_text_editor_is_dirty::build(env)?,
get_text_editor_selections: get_text_editor_selections::build(env)?,
initialize_source_control: initialize_source_control::build(env)?,
set_text_editor_decorations: set_text_editor_decorations::build(env)?,
update_resource_states: update_resource_states::build(env)?,
uri_file: vscode_sys::threadsafe_function::uri::file::get(vscode_object)?,
})
}
pub async fn fire_decoration_change_event(
&self,
uri: UriAbsoluteString,
event_emitter_reference: &Rc<vscode_sys::reference::EventEmitterRef>,
) -> Result<(), napi::Error> {
let arguments = fire_decoration_change_event::Arguments {
uri,
event_emitter_reference: Rc::clone(event_emitter_reference),
};
self.fire_decoration_change_event
.call_async(External::new(arguments))
.await
}
pub async fn get_text_editor_contents(
&self,
text_editor_reference: &Rc<vscode_sys::reference::TextEditorRef>,
) -> Result<String, napi::Error> {
let arguments = get_text_editor_contents::Arguments {
text_editor_reference: Rc::clone(text_editor_reference),
};
self.get_text_editor_contents
.call_async(External::new(arguments))
.await
}
pub async fn get_text_editor_is_dirty(
&self,
text_editor_reference: &Rc<vscode_sys::reference::TextEditorRef>,
) -> Result<bool, napi::Error> {
let arguments = get_text_editor_is_dirty::Arguments {
text_editor_reference: Rc::clone(text_editor_reference),
};
self.get_text_editor_is_dirty
.call_async(External::new(arguments))
.await
}
pub async fn get_text_editor_selections(
&self,
text_editor_reference: &Rc<vscode_sys::reference::TextEditorRef>,
) -> Result<Vec<(u32, u32)>, napi::Error> {
let arguments = get_text_editor_selections::Arguments {
text_editor_reference: Rc::clone(text_editor_reference),
};
self.get_text_editor_selections
.call_async(External::new(arguments))
.await
}
pub async fn initialize_source_control(
&self,
repository_uri_ref: vscode_sys::reference::UriRef,
quick_diff_provider_ref: &Rc<vscode_sys::reference::QuickDiffProviderRef>,
pijul_label: String,
changes_label: String,
untracked_label: String,
) -> Result<initialize_source_control::Return, napi::Error> {
let arguments = initialize_source_control::Arguments {
repository_uri_ref,
quick_diff_provider_ref: Rc::clone(quick_diff_provider_ref),
pijul_label,
changes_label,
untracked_label,
};
self.initialize_source_control
.call_async(External::new(arguments))
.await
}
pub async fn set_text_editor_decorations(
&self,
line_decorations: Vec<crate::inline_credit::LineDecoration>,
text_editor_reference: &Rc<vscode_sys::reference::TextEditorRef>,
decoration_type_reference: &Rc<vscode_sys::reference::TextEditorDecorationTypeRef>,
) -> Result<(), napi::Error> {
let arguments = set_text_editor_decorations::Arguments {
line_decorations,
text_editor_reference: Rc::clone(text_editor_reference),
decoration_type_reference: Rc::clone(decoration_type_reference),
};
self.set_text_editor_decorations
.call_async(External::new(arguments))
.await
}
pub async fn update_resource_states(
&self,
repository_path: Utf8PathBuf,
repository_states: Vec<(Utf8PathBuf, PathState)>,
unrecorded_changes: &Rc<vscode_sys::reference::SourceControlResourceGroupRef>,
untracked_paths: &Rc<vscode_sys::reference::SourceControlResourceGroupRef>,
) -> Result<(), napi::Error> {
let arguments = update_resource_states::Arguments {
repository_path,
repository_states,
unrecorded_changes: Rc::clone(unrecorded_changes),
untracked_paths: Rc::clone(untracked_paths),
};
self.update_resource_states
.call_async(External::new(arguments))
.await
}
pub async fn uri_file(
&self,
path: String,
) -> Result<vscode_sys::reference::UriRef, napi::Error> {
let arguments = FnArgs::from((path,));
self.uri_file.call_async(arguments).await
}
}