One of the last of the high-impact features to be ported apart from inline credit. Includes a little bit of cleanup and extra tracing calls.
QJ6EZNXEJE4N5NPDFPXNVDUSR5QZSSIMC3FLQ4XFMDOF2J7M62CAC WFWTKCJNC4VSURSQWE5FXJGTEJJOCDMQ6LN2O6EW2DNOVT2ZUMRQC TWPZLEGDVH4YBYEPFIRD7ONZGJPAMLXLPZTIHHKTUFLU5XIS3X7AC NB2MF3MYAJ25KNZP3GMHX42LUSBYOX6FTNLIBK3CQ7CMANFZFEGQC 2ZAM5V35CAQD5MOFPZEGU4ERQ2FM5CL5MB2DOJDW2ZQ74IQFBISQC IDY5SNLOFZ663OCJ2L5NZMFNJXZSGL5O22QQXR5BIV3SJ2VUQIMQC D3V6U7N6CPS3P7PS245MM2N5UIZOKAP7QU7RUKYXBFMOAHYV47TAC 3RNQI5RXZMXF5N2WKYS3O3G2GTD4TTWDNQ3EBVGUVVKNNOTKQTJAC M5RW5PN4VFYZOKHUFMVWR2XAUAXHUYROVZFTS3RIE7AAUGTVHAEQC POA32CUWX2HB7CYEYCXQSYWNY5AHCY3XCB6MDSA55ICJZAKKNVSQC NEAR63OCPUGLXZ46YRBBY5DI5LCVH27XNGGZD7LCMUESHON54JFQC 3YGYMEXVHOHRQVPC53MVPSLI2ZJM77MBPWNPDDCL56DNCPUC6XTAC if let Some((workspace_path, workspace)) =program_state.repositories.get_open_repository(env, &uri)?{let absolute_path = Utf8PathBuf::from(uri.get_fs_path()?);let relative_path = absolute_path.strip_prefix(&workspace_path).map_err(|error| {napi::Error::from_reason(format!("Failed to strip prefix {workspace_path} from {absolute_path}: {error}"))})?;match workspace.repository.get_open_file(relative_path) {Some(open_file) => Ok(open_file.tracked_contents().map(str::to_string)),None => {tracing::error!(message = "No tracked file state for {relative_path}",?workspace_path);
let (deferred_promise, promise_object) = env.create_deferred()?;event_loop::send(Event::RequestTrackedContents {uri: decoded_uri,deferred_promise,});
use iri_string::types::{UriAbsoluteStr, UriAbsoluteString};use crate::event_loop::ExtensionState;pub type DeferredPromise = napi::JsDeferred<Option<String>,Box<dyn FnOnce(napi::Env) -> Result<Option<String>, napi::Error>>,>;#[tracing::instrument(skip(deferred_promise, extension_state))]pub async fn handle(uri: UriAbsoluteString,deferred_promise: DeferredPromise,extension_state: &ExtensionState,) {let tracked_contents = get_tracked_contents(&uri, extension_state);tracing::info!(message = "Providing tracked contents",length = ?tracked_contents.as_ref().map(|contents| contents.len()));deferred_promise.resolve(Box::new(move |_env| Ok(tracked_contents)));}#[tracing::instrument(skip(extension_state))]fn get_tracked_contents(uri: &UriAbsoluteStr, extension_state: &ExtensionState) -> Option<String> {let Some((repository_path, relative_path, repository)) = extension_state.get_repository(uri)else {tracing::info!(message = "No matching repository for path", ?uri);return None;};let Some(open_file) = repository.repository.get_open_file(relative_path) else {tracing::info!(message = "No open file found in repository",?repository_path,?relative_path);return None;};let Some(tracked_contents) = open_file.tracked_contents() else {tracing::info!(message = "No tracked contents for file",?repository_path,?relative_path);return None;};Some(tracked_contents.to_string())}