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

Method find_constant_references

src/references/mod.rs:1090–1155  ·  view source on GitHub ↗

Find all references to a constant across all files.

(
        &self,
        target_name: &str,
        include_declaration: bool,
    )

Source from the content-addressed store, hash-verified

1088
1089 /// Find all references to a constant across all files.
1090 fn find_constant_references(
1091 &self,
1092 target_name: &str,
1093 include_declaration: bool,
1094 ) -> Vec<Location> {
1095 let mut locations = Vec::new();
1096
1097 let snapshot = self.user_file_symbol_maps();
1098
1099 for (file_uri, symbol_map) in &snapshot {
1100 // First pass: name-only check.
1101 let has_potential_match = symbol_map.spans.iter().any(|span| match &span.kind {
1102 SymbolKind::ConstantReference { name } => name == target_name,
1103 SymbolKind::MemberDeclaration { name, is_static }
1104 if include_declaration && name == target_name && *is_static =>
1105 {
1106 true
1107 }
1108 _ => false,
1109 });
1110
1111 if !has_potential_match {
1112 continue;
1113 }
1114
1115 let parsed_uri = match Url::parse(file_uri) {
1116 Ok(u) => u,
1117 Err(_) => continue,
1118 };
1119
1120 let mut file_content: Option<Arc<String>> = None;
1121
1122 for span in &symbol_map.spans {
1123 let matched = match &span.kind {
1124 SymbolKind::ConstantReference { name } => name == target_name,
1125 SymbolKind::MemberDeclaration { name, is_static }
1126 if include_declaration && name == target_name && *is_static =>
1127 {
1128 true
1129 }
1130 _ => false,
1131 };
1132
1133 if matched {
1134 if file_content.is_none() {
1135 file_content = self.get_file_content_arc(file_uri);
1136 }
1137 if let Some(ref content) = file_content {
1138 let start = offset_to_position(content, span.start as usize);
1139 let end = offset_to_position(content, span.end as usize);
1140 push_unique_location(&mut locations, &parsed_uri, start, end);
1141 }
1142 }
1143 }
1144 }
1145
1146 locations.sort_by(|a, b| {
1147 a.uri

Callers 1

Calls 6

offset_to_positionFunction · 0.85
push_unique_locationFunction · 0.85
user_file_symbol_mapsMethod · 0.80
iterMethod · 0.80
get_file_content_arcMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected