MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / hover_for_constant

Method hover_for_constant

src/hover/mod.rs:1297–1360  ·  view source on GitHub ↗

Build hover content for a class constant.

(
        &self,
        constant: &ConstantInfo,
        owner: &ClassInfo,
        class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>,
    )

Source from the content-addressed store, hash-verified

1295
1296 /// Build hover content for a class constant.
1297 pub(crate) fn hover_for_constant(
1298 &self,
1299 constant: &ConstantInfo,
1300 owner: &ClassInfo,
1301 class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>,
1302 ) -> Hover {
1303 let member_line = if constant.is_enum_case {
1304 if let Some(ref val) = constant.enum_value {
1305 format!("case {} = {};", constant.name, val)
1306 } else {
1307 format!("case {};", constant.name)
1308 }
1309 } else {
1310 let visibility = format_visibility(constant.visibility);
1311 let type_hint = constant
1312 .type_hint
1313 .as_ref()
1314 .map(|t| format!(": {}", t))
1315 .unwrap_or_default();
1316 let value_suffix = constant
1317 .value
1318 .as_ref()
1319 .map(|v| format!(" = {}", v))
1320 .unwrap_or_default();
1321 format!(
1322 "{}const {}{}{};",
1323 visibility, constant.name, type_hint, value_suffix
1324 )
1325 };
1326
1327 let mut lines = Vec::new();
1328
1329 // Origin indicator (implements / virtual).
1330 let origin = build_origin_lines(
1331 &constant.name,
1332 owner,
1333 constant.is_virtual,
1334 MemberKindForOrigin::Constant,
1335 class_loader,
1336 );
1337 if !origin.is_empty() {
1338 lines.push(origin.trim_end().to_string());
1339 }
1340
1341 if let Some(ref desc) = constant.description {
1342 lines.push(desc.clone());
1343 }
1344
1345 if let Some(ref msg) = constant.deprecation_message {
1346 lines.push(format_deprecation_line(msg));
1347 }
1348
1349 // Constants don't have a native vs effective type split, so no doc annotation.
1350 let code = build_class_member_block(
1351 &owner.name,
1352 owner.file_namespace.as_deref(),
1353 owner_kind_keyword(owner),
1354 &owner_name_suffix(owner),

Callers 2

resolve_memberMethod · 0.80
hover_from_symbolMethod · 0.80

Calls 11

format_visibilityFunction · 0.85
build_origin_linesFunction · 0.85
format_deprecation_lineFunction · 0.85
build_class_member_blockFunction · 0.85
owner_kind_keywordFunction · 0.85
owner_name_suffixFunction · 0.85
make_hoverFunction · 0.85
pushMethod · 0.80
cloneMethod · 0.80
mapMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected