Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 257 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions crates/rake-cli/src/cdp/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub(super) fn node(
result["name"] = json!({"type":"string","value":label});
}

if let Some(key) = &a11y.message_key {
result["messageKey"] = json!(key);
}

if let Some(description) = &a11y.description {
result["description"] = json!({"type":"string","value":description});
}
Expand Down
1 change: 1 addition & 0 deletions crates/rake-cli/src/cdp/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub(super) fn capture(count: usize) -> Snapshot {
status: Status::Captured,
capture: "one".into(),
router_revision: 0,
locale: None,
omitted: 0,
coverage: "generated benchmark boundaries".into(),
elements: (0..count)
Expand Down
2 changes: 1 addition & 1 deletion crates/rake-cli/src/cdp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(super) fn describe(
json!({
"version":1,"runtimeId":info.runtime_id,"platform":info.platform,"methods":methods,
"errorContractVersion":1,
"agentQuery":{"filters":["nodeId","stableId","id","role","name","text","textContains","textContent","textContentContains","bounds","enabled","visible"],"snapshotOptions":["limit","offset","expectedRevision","rootNodeId"],"textContent":"captured rendered text; a boundary owns its text or aggregates descendants; private input values are excluded"},
"agentQuery":{"filters":["nodeId","stableId","id","role","name","messageKey","text","textContains","textContent","textContentContains","bounds","enabled","visible"],"snapshotOptions":["limit","offset","expectedRevision","rootNodeId"],"textContent":"captured rendered text; a boundary owns its text or aggregates descendants; private input values are excluded"},
"sourceRead":{"supported":sources && inspection && native,"transport":"snapshot source.url HTTP GET"},
"nativeWindowsAvailable":native,"nativeError":native_error,
"limits":{"evidenceBytes":921600,"evidenceTreeNodes":64,"capturedTextBytes":16777216,"snapshotNodes":256,"waitHandles":32,"waitTimeoutMs":30000,"requestTimeoutMs":2000,"textBytes":16384,"imageBytes":768000,"messageBytes":1048576},
Expand Down
1 change: 1 addition & 0 deletions crates/rake-cli/src/cdp/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod tests {
status: Status::Captured,
capture: capture.into(),
router_revision: 0,
locale: None,
omitted: 0,
coverage: "x".repeat(bytes),
elements: vec![],
Expand Down
2 changes: 2 additions & 0 deletions crates/rake-cli/src/cdp/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,7 @@ mod tests {
label: Some("Save".into()),
name: None,
name_source: None,
message_key: Some("save".into()),
states: Default::default(),
description: None,
disabled: false,
Expand Down Expand Up @@ -1512,6 +1513,7 @@ mod tests {

assert_eq!(node["role"]["value"], "button");
assert_eq!(node["name"]["value"], "Save");
assert_eq!(node["messageKey"], "save");
assert_eq!(node["ignored"], false);
let root = dom
.accessibility("Accessibility.getRootAXNode", &json!({}))
Expand Down
9 changes: 7 additions & 2 deletions crates/rake-cli/src/cdp/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub(super) struct Selector {
pub id: Option<String>,
pub role: Option<String>,
pub name: Option<String>,
pub message_key: Option<String>,
pub text_contains: Option<String>,
pub text: Option<String>,
pub text_content: Option<String>,
Expand Down Expand Up @@ -377,6 +378,10 @@ pub(super) fn project(
.name
.as_ref()
.is_some_and(|v| name != Some(v.as_str()))
|| selector
.message_key
.as_ref()
.is_some_and(|key| ax.and_then(|a| a.message_key.as_ref()) != Some(key))
|| selector
.text_contains
.as_ref()
Expand All @@ -403,7 +408,7 @@ pub(super) fn project(

elements.push(json!({"nodeId":node,"stableId":element.stable_id,"id":element.semantic_id,
"parentId":element.parent.as_deref().and_then(|p|dom.node_id(p)),"type":element.display_name(),
"role":role,"name":name.map(prefix),"nameTruncated":name.is_some_and(|n|n.len()>512),"text":element.text.as_deref().map(prefix),
"role":role,"name":name.map(prefix),"messageKey":ax.and_then(|a|a.message_key.as_deref()),"nameTruncated":name.is_some_and(|n|n.len()>512),"text":element.text.as_deref().map(prefix),
"textContent":prefix(content.text(index)),"textContentTruncated":content.text(index).len()>512,"textContentComplete":content.complete(index),
"textTruncated":element.text.as_ref().is_some_and(|t|t.len()>512),"bounds":element.layout,
"visibleBounds":element.content_mask,"visible":visible,"enabled":enabled,
Expand All @@ -414,7 +419,7 @@ pub(super) fn project(
Ok(
json!({"windowId":presentation.window,"frameSequence":presentation.frame,"revision":revision,"rootNodeId":root,"queryComplete":query_complete,
"elements":elements,"totalMatches":matches,"offset":offset,"hasMore":matches>offset+limit,
"omitted":presentation.tree.omitted,"coverage":presentation.tree.coverage,
"locale":presentation.tree.locale,"omitted":presentation.tree.omitted,"coverage":presentation.tree.coverage,
"visibilitySemantics":"sampled layout, clipping and accessibility; final occlusion is unavailable"}),
)
}
Expand Down
95 changes: 94 additions & 1 deletion crates/rake-cli/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rake highlight ID|none [--generation CAPTURE] [--instance UUID|application-id]
rake inspect pick [--instance UUID|application-id]
rake instances [--json]
rake ctl [--instance UUID|application-id] [--json] [--timeout SECONDS]
inspect tree | inspect element ELEMENT_ID | inspect pick | inspect mode on|off [--lease-ms MS]
inspect tree | inspect message-key KEY [--role ROLE] [--window WINDOW] | inspect element ELEMENT_ID | inspect pick | inspect mode on|off [--lease-ms MS]
inspect focus|scroll ELEMENT_ID [--generation CAPTURE] | inspect source ELEMENT_ID [--style INDEX|--handler INDEX]
info | schema | snapshot | events [--follow]
quit [--jobs wait|cancel] | quit status
Expand Down Expand Up @@ -544,6 +544,26 @@ pub(super) fn run(mut args: Vec<String>) -> Result<()> {
args[1] = "element".into();
}

let message_key = if args.first().is_some_and(|arg| arg == "inspect")
&& args.get(1).is_some_and(|arg| arg == "message-key")
{
let role = option(&mut args, "--role")?;

let window = option(&mut args, "--window")?
.map(|window| window.parse())
.transpose()?;

if args.len() != 3 {
return Err("inspect message-key requires one Fluent message identifier".into());
}

args[1] = "tree".into();

Some((args.remove(2), role, window))
} else {
None
};

let (mut message, follow) = parse_message(args)?;

let candidates: Vec<_> = instances
Expand All @@ -564,6 +584,79 @@ pub(super) fn run(mut args: Vec<String>) -> Result<()> {
_ => return Err("ambiguous instance; select a RuntimeId using --instance".into()),
};

if let Some((key, role, window)) = message_key {
let mut offset = 0;
let mut pin = None;
let mut result: Option<rake_protocol::inspection::Snapshot> = None;

loop {
let page = if let Some(window) = window {
let Reply::InspectionWindow(page) = query(
instance,
Query::InspectWindow {
window,
presentation: pin.take(),
offset,
},
timeout,
)?
else {
return Err("unexpected window inspection reply".into());
};

pin = Some(page.presentation);

page.page
} else {
let Reply::ElementPage(page) = query(
instance,
Query::InspectTreePage {
generation: pin.take(),
offset,
},
timeout,
)?
else {
return Err("unexpected tree inspection reply".into());
};

pin = Some(page.snapshot.capture.clone());

page
};

let mut tree = page.snapshot;

tree.elements.retain(|element| {
element.accessibility.as_ref().is_some_and(|accessibility| {
accessibility.message_key.as_deref() == Some(key.as_str())
&& role.as_ref().is_none_or(|role| {
accessibility
.role
.as_ref()
.is_some_and(|value| value.eq_ignore_ascii_case(role))
})
})
});

match &mut result {
Some(result) => result.elements.extend(tree.elements),
None => result = Some(tree),
}

match page.next {
Some(next) if next > offset => offset = next,
Some(_) => return Err("inspection pagination did not advance".into()),
None => {
return print(
&Reply::Elements(result.ok_or("missing inspection page")?),
compact,
);
}
}
}
}

if let Message::Command(Command::HighlightElement {
id: Some(id),
generation,
Expand Down
11 changes: 11 additions & 0 deletions crates/rake-protocol/src/inspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ pub struct Snapshot {
pub capture: String,
/// Router revision at the start of the captured render, not a live revision.
pub router_revision: u64,
/// Resolved application locale when the tree was captured.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub locale: Option<String>,
/// Captured boundaries in depth-first order.
pub elements: Vec<Element>,
/// Inspected boundaries omitted by count/byte limits. Opaque descendants are uncounted.
Expand Down Expand Up @@ -510,6 +513,13 @@ pub struct Accessibility {
/// `label`, `text`, or `contents`; absent on older runtimes or unknown names.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name_source: Option<String>,
/// Fluent message identifier for this label or control.
#[serde(
default,
rename = "messageKey",
skip_serializing_if = "Option::is_none"
)]
pub message_key: Option<String>,
/// Actual AccessKit states; never editable text or password values.
#[serde(default, skip_serializing_if = "serde_json::Map::is_empty")]
pub states: serde_json::Map<String, Value>,
Expand Down Expand Up @@ -543,6 +553,7 @@ impl Accessibility {
&& self.label == other.label
&& self.name == other.name
&& self.name_source == other.name_source
&& self.message_key == other.message_key
&& self.states == other.states
&& self.description == other.description
&& self.disabled == other.disabled
Expand Down
28 changes: 28 additions & 0 deletions crates/rake-view-syntax/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,34 @@ impl Element {
for (position, attribute) in self.attributes.iter().enumerate() {
let value = attribute.expression()?;

if attribute.name == "message-key" {
let valid = if let Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(key),
..
}) = value
{
let key = key.value();
let mut bytes = key.bytes();

bytes
.next()
.is_some_and(|first| first.is_ascii_alphabetic())
&& bytes
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'))
} else {
false
};

if !valid {
return Err(syn::Error::new(
attribute.span,
"message-key expects a literal Fluent message identifier",
));
}

continue;
}

if self.resolved == Tag::Svg
&& !matches!(
attribute.name.as_str(),
Expand Down
6 changes: 5 additions & 1 deletion crates/rake-view-syntax/src/view/inspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ impl Element {
let node = syn::Ident::new("__rake_inspection_element", Span::mixed_site());
let mut inspected = quote_spanned!(self.tag.span()=> #rake::__private::view_inspect(#node, #definition, #named));

for (attribute, method) in [("focus", "focus_handle"), ("scroll", "scroll_handle")] {
for (attribute, method) in [
("focus", "focus_handle"),
("scroll", "scroll_handle"),
("message-key", "message_key"),
] {
if let Some(value) = self.attribute(attribute) {
let value = value.expression().expect("validated handle");
let method = syn::Ident::new(method, value.span());
Expand Down
24 changes: 24 additions & 0 deletions crates/rake-view-syntax/src/view/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,30 @@ fn file_drag_over_classes_merge_with_the_external_paths_payload() {
assert!(expanded.contains(".border_2()"));
}

#[test]
fn preserves_explicit_translation_and_lowers_message_key() {
let output = expand(
r#"<button aria-label={label.clone()} message-key="inbox-count">
{rake::t!(cx, "inbox-count", count = n)}
</button>"#,
)
.unwrap();

let tokens = output.to_string();

syn::parse2::<syn::Expr>(output).unwrap();
assert!(
tokens.contains(r#"rake :: t ! (cx , "inbox-count" , count = n)"#),
"{tokens}"
);
assert!(
tokens.contains(r#". message_key ("inbox-count")"#),
"{tokens}"
);
assert!(expand(r#"<button message-key="inbox.count"/>"#).is_err());
assert!(expand(r#"<button message-key={dynamic_key}/>"#).is_err());
}

#[test]
fn links_and_selectable_text_expand() {
for source in [
Expand Down
15 changes: 14 additions & 1 deletion crates/rake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ updates-velopack = ["updates", "rake-updates/velopack"]
devtools = ["gpui_pre?/profiler", "gpui_fast?/profiler", "rake-diagnostics/devtools", "rake-http/devtools", "objc2-app-kit?/objc2-quartz-core", "dep:windows"]
devtools-memory = ["devtools", "dep:backtrace"]
kit = ["gpui", "rake-ui/kit"]
locale = ["gpui", "dep:fluent-bundle", "dep:icu_locale_core", "dep:sys-locale"]
locale-icu = ["locale", "dep:fixed_decimal", "dep:icu_calendar", "dep:icu_datetime", "dep:icu_decimal", "dep:icu_plurals", "dep:icu_provider", "dep:icu_provider_blob", "dep:writeable"]
# Deprecated compatibility alias; UI is provided by gpui (enabled by default).
experimental-view = []
experimental-reactive = ["gpui", "rake-macros/reactive", "dep:slotmap"]
view-test-support = ["gpui", "gpui_pre/test-support", "gpui_fast?/test-support", "rake-ui/test-support", "gpui_platform/runtime_shaders", "gpui_fast_platform?/runtime_shaders"]
gpui = ["dep:gpui_pre_apple", "dep:windows", "dep:oo7", "dep:zbus", "dep:rake-ui", "rake-macros/view", "dep:gpui_pre", "dep:gpui_platform", "dep:objc2-app-kit", "dep:objc2", "dep:objc2-foundation", "dep:block2", "dep:objc2-user-notifications", "dep:raw-window-handle", "dep:windows-sys", "native-lifecycle"]

[dependencies]
fluent-bundle = { version = "0.16", optional = true }
icu_locale_core = { version = "2.4", optional = true }
fixed_decimal = { version = "0.7", optional = true }
icu_calendar = { version = "2.4", default-features = false, optional = true }
icu_datetime = { version = "2.4", default-features = false, features = ["serde"], optional = true }
icu_decimal = { version = "2.4", default-features = false, features = ["serde"], optional = true }
icu_plurals = { version = "2.4", default-features = false, features = ["serde"], optional = true }
icu_provider = { version = "2.4", features = ["sync"], optional = true }
icu_provider_blob = { version = "2.4", optional = true }
writeable = { version = "0.6", optional = true }
zeroize = "1"
rake-shortcuts = { version = "=0.1.0-alpha.4", path = "../rake-shortcuts", optional = true }
image = { version = "0.25.10", default-features = false, features = ["png"] }
Expand Down Expand Up @@ -80,6 +92,7 @@ backtrace = { version = "0.3.76", optional = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
blaze-live = { package = "rake-blaze-live", version = "=0.1.0-alpha.4", path = "../../vendor/blaze-live", optional = true }
sys-locale = { version = "0.3", optional = true }
anyhow = "1"
libc = "0.2"
async-io = "2.6"
Expand All @@ -92,7 +105,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
js-sys = "0.3"
console_error_panic_hook = "0.1"
web-sys = { version = "0.3", features = ["console", "Window", "History", "Location", "Event", "BeforeUnloadEvent", "EventTarget", "Document", "Element", "HtmlElement", "Node", "Storage", "ClipboardEvent", "DataTransfer"] }
web-sys = { version = "0.3", features = ["console", "Window", "History", "Location", "Navigator", "Event", "BeforeUnloadEvent", "EventTarget", "Document", "Element", "HtmlElement", "Node", "Storage", "ClipboardEvent", "DataTransfer"] }

[target.'cfg(target_os = "macos")'.dependencies]
gpui_fast_apple = { package = "gpui-fast-apple", version = "=0.1.13", optional = true }
Expand Down
Loading
Loading