-
Notifications
You must be signed in to change notification settings - Fork 2
DisplayInfo の format を用いて devtoolsでの表示を指定する #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ members = [ | |
| "gaia-tmtc", | ||
| "gaia-ccsds-c2a", | ||
| "tmtc-c2a", | ||
| "tmtc-c2a/devtools_frontend/crates/wasm-interpolate" | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,7 @@ pub struct FieldIter<'a> { | |
| } | ||
|
|
||
| impl<'a> Iterator for FieldIter<'a> { | ||
| type Item = Result<(&'a str, FieldSchema)>; | ||
| type Item = Result<(&'a str, &'a tlmdb::DisplayInfo, FieldSchema)>; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| let (obs, field, bit_range) = self.fields.next()?; | ||
|
|
@@ -131,10 +131,11 @@ fn build_field_schema( | |
| obs: tlmdb::OnboardSoftwareInfo, | ||
| field: &tlmdb::Field, | ||
| bit_range: Range<usize>, | ||
| ) -> Result<(&str, FieldSchema)> { | ||
| ) -> Result<(&str, &tlmdb::DisplayInfo, FieldSchema)> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [clippy] reported by reviewdog 🐶 |
||
| let converter = build_integral_converter(&field.conversion_info); | ||
| Ok(( | ||
| &field.name, | ||
| &field.display_info, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [clippy] reported by reviewdog 🐶 |
||
| match obs.variable_type { | ||
| tlmdb::VariableType::Int8 => FieldSchema::Integral(IntegralFieldSchema { | ||
| converter, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /target | ||
| **/*.rs.bk | ||
| Cargo.lock | ||
| bin/ | ||
| pkg/ | ||
| wasm-pack.log |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [package] | ||
| name = "wasm-interpolate" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib", "rlib"] | ||
|
|
||
| [features] | ||
| default = ["console_error_panic_hook"] | ||
|
|
||
| [dependencies] | ||
| wasm-bindgen = "0.2.84" | ||
|
|
||
| # The `console_error_panic_hook` crate provides better debugging of panics by | ||
| # logging them with `console.error`. This is great for development, but requires | ||
| # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
| # code size when deploying. | ||
| console_error_panic_hook = { version = "0.1.7", optional = true } | ||
| interpolator = { version = "0.5.0", features = ["number"] } | ||
| js-sys = "0.3.66" | ||
| anyhow = "1" | ||
|
|
||
| [dev-dependencies] | ||
| wasm-bindgen-test = "0.3.34" | ||
|
|
||
| [profile.release] | ||
| # Tell `rustc` to optimize for small code size. | ||
| opt-level = "s" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| mod utils; | ||
|
|
||
| use interpolator::{format, Formattable}; | ||
| use wasm_bindgen::prelude::*; | ||
|
|
||
| use anyhow::{anyhow, Result}; | ||
| use js_sys::BigInt; | ||
| use std::collections::HashMap; | ||
|
|
||
| enum Value { | ||
| I64(i64), | ||
| F64(f64), | ||
| String(String), | ||
| } | ||
|
|
||
| impl Value { | ||
| pub fn formattable(&self) -> Formattable { | ||
| use Value::*; | ||
| match self { | ||
| I64(v) => Formattable::integer(v), | ||
| F64(v) => Formattable::float(v), | ||
| String(v) => Formattable::display(v), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&JsValue> for Value { | ||
| type Error = anyhow::Error; | ||
| fn try_from(value: &JsValue) -> Result<Self> { | ||
| if value.is_bigint() { | ||
| let value = BigInt::new(&value) | ||
| .map_err(|_| anyhow!("not a bigint"))? | ||
| .try_into() | ||
| .map_err(|_| anyhow!("couldn't convert bigint to i64"))?; | ||
| Ok(Value::I64(value)) | ||
| } else if let Some(v) = value.as_f64() { | ||
| Ok(Value::F64(v)) | ||
| } else if let Some(s) = value.as_string() { | ||
| Ok(Value::String(s)) | ||
| } else { | ||
| Err(anyhow!("not a string, f64, or bigint")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn format_value_inner(format_string: &str, arg: &JsValue) -> Result<String> { | ||
| let arg = Value::try_from(arg)?; | ||
| let arg = arg.formattable(); | ||
| let args = HashMap::from([("value", arg)]); | ||
| format(format_string, &args).map_err(Into::into) | ||
| } | ||
|
|
||
| #[wasm_bindgen(js_name = formatValue)] | ||
| pub fn format_value(format_string: &str, arg: &JsValue) -> Result<String, String> { | ||
| format_value_inner(format_string, arg).map_err(|e| e.to_string()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| pub fn set_panic_hook() { | ||
| // When the `console_error_panic_hook` feature is enabled, we can call the | ||
| // `set_panic_hook` function at least once during initialization, and then | ||
| // we will get better error messages if our code ever panics. | ||
| // | ||
| // For more details see | ||
| // https://github.com/rustwasm/console_error_panic_hook#readme | ||
| #[cfg(feature = "console_error_panic_hook")] | ||
| console_error_panic_hook::set_once(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [clippy] reported by reviewdog 🐶
cannot find type
DisplayInfoin moduletlmdb