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

Method lookup_global_constant

src/hover/mod.rs:833–907  ·  view source on GitHub ↗

Look up a global constant by name, returning its value if found. Searches in order: 1. `global_defines` — constants already parsed from user files. 2. `autoload_constant_index` — lazily parses the defining file. 3. `autoload_file_paths` — last-resort lazy parse of known autoload files for constants the byte-level scanner missed. 4. `stub_constant_index` — built-in PHP constants from stubs. Lazily

(&self, name: &str)

Source from the content-addressed store, hash-verified

831 /// value, `Some(None)` when it exists but the value is unknown, and
832 /// `None` when the constant was not found at all.
833 pub(crate) fn lookup_global_constant(&self, name: &str) -> Option<Option<String>> {
834 // Phase 1: already-parsed constants.
835 let lookup = self
836 .global_defines
837 .read()
838 .get(name)
839 .map(|info| info.value.clone());
840 if lookup.is_some() {
841 return lookup;
842 }
843
844 // Phase 2: autoload constant index — lazily parse the file.
845 let path = self.autoload_constant_index.read().get(name).cloned();
846 if let Some(path) = path
847 && let Ok(content) = std::fs::read_to_string(&path)
848 {
849 let file_uri = crate::util::path_to_uri(&path);
850 self.update_ast(&file_uri, &content);
851 let lookup = self
852 .global_defines
853 .read()
854 .get(name)
855 .map(|info| info.value.clone());
856 if lookup.is_some() {
857 return lookup;
858 }
859 }
860
861 // Phase 3: lazily parse known autoload files for constants
862 // the byte-level scanner missed (e.g. inside
863 // `if (!defined(...))` guards).
864 {
865 let paths = self.autoload_file_paths.read().clone();
866 for path in &paths {
867 let uri = crate::util::path_to_uri(path);
868 if self.parsed_uris.read().contains(&uri) {
869 continue;
870 }
871 if let Ok(content) = std::fs::read_to_string(path) {
872 self.update_ast(&uri, &content);
873 let lookup = self
874 .global_defines
875 .read()
876 .get(name)
877 .map(|info| info.value.clone());
878 if lookup.is_some() {
879 return lookup;
880 }
881 }
882 }
883 }
884
885 // Phase 4: built-in PHP constants from embedded stubs.
886 // Parse the stub via update_ast (which populates global_defines),
887 // then re-check. This is the same lazy-parse pattern as Phases
888 // 2 and 3 — no special raw-source scanning needed.
889 let stub_const_idx = self.stub_constant_index.read();
890 if let Some(&stub_source) = stub_const_idx.get(name) {

Callers 3

constant_loaderMethod · 0.80
hover_from_symbolMethod · 0.80

Calls 6

path_to_uriFunction · 0.85
cloneMethod · 0.80
update_astMethod · 0.80
containsMethod · 0.80
mapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected