(&mut self, node: pl::Expr)
| 71 | |
| 72 | impl pl::PlFold for Labeler<'_> { |
| 73 | fn fold_expr(&mut self, node: pl::Expr) -> Result<pl::Expr> { |
| 74 | if let Some(ident) = node.kind.as_ident() { |
| 75 | if let Some(span) = node.span { |
| 76 | let decl = self.root_mod.module.get(ident); |
| 77 | |
| 78 | let ident = format!("[{ident}]"); |
| 79 | |
| 80 | let (decl, color) = if let Some(decl) = decl { |
| 81 | let color = match &decl.kind { |
| 82 | DeclKind::Expr(_) => Color::Blue, |
| 83 | DeclKind::Ty(_) => Color::Green, |
| 84 | DeclKind::Column { .. } => Color::Yellow, |
| 85 | DeclKind::InstanceOf(_, _) => Color::Yellow, |
| 86 | DeclKind::TableDecl { .. } => Color::Red, |
| 87 | DeclKind::Module(module) => { |
| 88 | self.label_module(module); |
| 89 | |
| 90 | Color::Cyan |
| 91 | } |
| 92 | DeclKind::LayeredModules(_) => Color::Cyan, |
| 93 | DeclKind::Infer(_) => Color::White, |
| 94 | DeclKind::QueryDef(_) => Color::White, |
| 95 | DeclKind::Import(_) => Color::White, |
| 96 | }; |
| 97 | |
| 98 | let location = decl |
| 99 | .declared_at |
| 100 | .and_then(|id| self.get_span_lines(id)) |
| 101 | .unwrap_or_default(); |
| 102 | |
| 103 | let decl = match &decl.kind { |
| 104 | DeclKind::TableDecl(TableDecl { ty, .. }) => { |
| 105 | format!( |
| 106 | "table {}", |
| 107 | ty.as_ref().and_then(|t| t.name.clone()).unwrap_or_default() |
| 108 | ) |
| 109 | } |
| 110 | _ => decl.to_string(), |
| 111 | }; |
| 112 | |
| 113 | (format!("{decl}{location}"), color) |
| 114 | } else if let Some(decl_id) = node.target_id { |
| 115 | let lines = self.get_span_lines(decl_id).unwrap_or_default(); |
| 116 | |
| 117 | (format!("variable{lines}"), Color::Yellow) |
| 118 | } else { |
| 119 | ("".to_string(), Color::White) |
| 120 | }; |
| 121 | |
| 122 | let label_span = (self.source_id.to_string(), span.start..span.end); |
| 123 | |
| 124 | self.report.add_label( |
| 125 | Label::new(label_span) |
| 126 | .with_message(format!("{ident} {decl}")) |
| 127 | .with_color(color), |
| 128 | ); |
| 129 | } |
| 130 | } |
no test coverage detected