egui_pop_api/links/
lint.rs1use egui_pop_model::links::{self as model, Target};
6use egui_pop_model::menus::Item;
7
8use super::{CMD_OPEN, CMD_REVEAL, declared, links};
9use crate::app::AppHandle;
10
11pub fn problems(app: &AppHandle) -> Vec<String> {
20 let Some(links) = links(app) else {
21 return vec!["the links plugin is not connected".into()];
22 };
23 let policy = links.policy();
24 let docs = links.inside().and_then(|i| i.docs_pages());
25 let commands: Vec<String> = app
26 .commands()
27 .into_iter()
28 .map(|(s, _)| s.id.as_str().to_string())
29 .collect();
30 let mut all: Vec<(String, String)> = declared(app);
31 for menu in app.menu_ids() {
32 for item in app.menu(&menu) {
33 if let Item::Command { id, args, .. } = &item.item
34 && (*id == CMD_OPEN || *id == CMD_REVEAL)
35 {
36 let key = if *id == CMD_OPEN { "target" } else { "path" };
37 match args[key].as_str() {
38 Some(t) => all.push((format!("menu `{menu}`"), t.to_string())),
39 None => all.push((format!("menu `{menu}`"), String::new())),
40 }
41 }
42 }
43 }
44 if let Some(tips) = app.service(&crate::tips::TIPS) {
45 for tip in tips.all() {
46 for f in model::find(&tip.text) {
47 all.push((format!("tip `{}`", tip.id), f.target));
48 }
49 }
50 }
51 if let Some(toasts) = app.service(&crate::toasts::TOASTS) {
52 for t in toasts.history().into_iter().chain(toasts.shown()) {
53 if let Some(a) = &t.toast.action
54 && (a.command == CMD_OPEN || a.command == CMD_REVEAL)
55 && let Some(target) = a.args["target"].as_str().or(a.args["path"].as_str())
56 {
57 all.push((format!("toast `{}`", t.toast.text), target.to_string()));
58 }
59 }
60 }
61 all.sort();
62 all.dedup();
63 all.iter()
64 .filter_map(|(place, target)| {
65 check(&policy, target, &commands, docs.as_deref())
66 .err()
67 .map(|e| format!("{place}: {e}"))
68 })
69 .collect()
70}
71
72pub fn check(
75 policy: &model::Policy,
76 target: &str,
77 commands: &[String],
78 docs: Option<&[String]>,
79) -> Result<(), String> {
80 model::check_declared(policy, target, commands, docs)?;
81 if let Ok(t) = Target::parse(target)
83 && let Some(facts) = super::facts_of(&t)
84 && !facts.exists
85 {
86 return Err(format!("`{target}`: the file is not there"));
87 }
88 Ok(())
89}