From ddb6f315628d7dc08a207a87d67d46f45b5e72c5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 30 Dec 2023 16:41:55 -0500 Subject: [PATCH] Implement angle link. --- src/wasm/angle_link.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/wasm/angle_link.rs b/src/wasm/angle_link.rs index bb100eb..adfc856 100644 --- a/src/wasm/angle_link.rs +++ b/src/wasm/angle_link.rs @@ -1,18 +1,28 @@ +use std::borrow::Cow; + use serde::Deserialize; use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; -use super::AdditionalProperties; use crate::compare::ElispFact; use crate::types::AngleLink; +use crate::types::LinkType; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] +#[serde(tag = "format")] +#[serde(rename = "angle")] pub struct WasmAngleLink { - #[serde(flatten)] - pub(crate) additional_properties: AdditionalProperties, + #[serde(rename = "type")] + pub(crate) link_type: String, + pub(crate) path: String, + #[serde(rename = "raw-link")] + pub(crate) raw_link: String, + pub(crate) application: Option, + #[serde(rename = "search-option")] + pub(crate) search_option: Option, } to_wasm!( @@ -21,12 +31,23 @@ to_wasm!( original, wasm_context, { WasmAstNode::AngleLink(original) }, - { "TODO".into() }, + { "link".into() }, { Ok(( Vec::new(), WasmAngleLink { - additional_properties: AdditionalProperties::default(), + link_type: match &original.link_type { + LinkType::File => "file".to_owned(), + LinkType::Protocol(protocol) => protocol.clone().into_owned(), + LinkType::Id => "id".to_owned(), + LinkType::CustomId => "custom-id".to_owned(), + LinkType::CodeRef => "coderef".to_owned(), + LinkType::Fuzzy => "fuzzy".to_owned(), + }, + path: original.get_path().into_owned(), + raw_link: original.raw_link.to_owned(), + application: original.application.map(|c| c.to_owned()), + search_option: original.get_search_option().map(Cow::into_owned), }, )) }