Build hover content for a property.
(
&self,
property: &PropertyInfo,
owner: &ClassInfo,
class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>,
)
| 1221 | |
| 1222 | /// Build hover content for a property. |
| 1223 | pub(crate) fn hover_for_property( |
| 1224 | &self, |
| 1225 | property: &PropertyInfo, |
| 1226 | owner: &ClassInfo, |
| 1227 | class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>, |
| 1228 | ) -> Hover { |
| 1229 | let visibility = format_visibility(property.visibility); |
| 1230 | let static_kw = if property.is_static { "static " } else { "" }; |
| 1231 | |
| 1232 | // Use native type hint in the code block, effective type as docblock annotation. |
| 1233 | let native_type = property |
| 1234 | .native_type_hint |
| 1235 | .as_ref() |
| 1236 | .map(|t| format!("{} ", t)) |
| 1237 | .unwrap_or_default(); |
| 1238 | |
| 1239 | let member_line = format!( |
| 1240 | "{}{}{}${};", |
| 1241 | visibility, static_kw, native_type, property.name |
| 1242 | ); |
| 1243 | |
| 1244 | // Build the docblock annotation showing the effective type |
| 1245 | // when it differs from the native one. |
| 1246 | let var_annotation = build_var_annotation( |
| 1247 | property.type_hint.as_ref(), |
| 1248 | property.native_type_hint.as_ref(), |
| 1249 | ); |
| 1250 | |
| 1251 | let mut lines = Vec::new(); |
| 1252 | |
| 1253 | // When the property type is a template parameter on the owning |
| 1254 | // class, show the template's variance and bound so the user |
| 1255 | // understands the constraint (e.g. "**template-covariant** |
| 1256 | // `TNode` of `AstNode`"). |
| 1257 | if let Some(ref type_hint) = property.type_hint |
| 1258 | && let Some(tpl_line) = find_template_info_in_class(type_hint, owner) |
| 1259 | { |
| 1260 | lines.push(tpl_line); |
| 1261 | } |
| 1262 | |
| 1263 | // Origin indicator (override / implements / virtual). |
| 1264 | let origin = build_origin_lines( |
| 1265 | &property.name, |
| 1266 | owner, |
| 1267 | property.is_virtual, |
| 1268 | MemberKindForOrigin::Property, |
| 1269 | class_loader, |
| 1270 | ); |
| 1271 | if !origin.is_empty() { |
| 1272 | lines.push(origin.trim_end().to_string()); |
| 1273 | } |
| 1274 | |
| 1275 | if let Some(ref desc) = property.description { |
| 1276 | lines.push(desc.clone()); |
| 1277 | } |
| 1278 | |
| 1279 | if let Some(ref msg) = property.deprecation_message { |
| 1280 | lines.push(format_deprecation_line(msg)); |
no test coverage detected