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

Method update_ast

src/parser/ast_update.rs:35–81  ·  view source on GitHub ↗

Update the uri_classes_index, use_map, and namespace_map for a given file URI by parsing its content. Returns `true` when at least one class signature in this file changed (or a class was added/removed), meaning other open files that reference those classes may have stale diagnostics.

(&self, uri: &str, content: &str)

Source from the content-addressed store, hash-verified

33 /// changed (or a class was added/removed), meaning other open files
34 /// that reference those classes may have stale diagnostics.
35 pub fn update_ast(&self, uri: &str, content: &str) -> bool {
36 // Invalidate thread-local mixin cache so stale ClassInfo is not
37 // served after a file changes.
38 crate::virtual_members::phpdoc::bump_mixin_generation();
39
40 let content_to_parse = if self.is_blade_file(uri) {
41 let (virtual_php, source_map) = crate::blade::preprocessor::preprocess(content);
42 self.blade_source_maps
43 .write()
44 .insert(uri.to_string(), source_map);
45 self.blade_virtual_content
46 .write()
47 .insert(uri.to_string(), virtual_php.clone());
48 virtual_php
49 } else {
50 content.to_string()
51 };
52
53 // The mago-syntax parser contains `unreachable!()` and `.expect()`
54 // calls that can panic on malformed PHP (e.g. partially-written
55 // heredocs/nowdocs, which are common while editing). Wrap the
56 // entire parse + extraction in `catch_unwind` so a parser panic
57 // doesn't crash the LSP server and produce a zombie process.
58 //
59 // On panic the file is simply skipped — no maps are updated, and
60 // the user gets stale (but not missing) completions until the
61 // file is saved in a parseable state.
62 let content_owned = content_to_parse;
63 let uri_owned = uri.to_string();
64
65 let result = crate::util::catch_panic_unwind_safe("parse", uri, None, || {
66 self.update_ast_inner(&uri_owned, &content_owned)
67 });
68
69 match result {
70 Some(changed) => changed,
71 None => {
72 // Parser panicked — store a single "Parse failed" error
73 // so the syntax-error diagnostic collector can report it.
74 self.parse_errors.write().insert(
75 uri.to_string(),
76 vec![("Parse failed (internal error)".to_string(), 0, 0)],
77 );
78 false
79 }
80 }
81 }
82
83 /// Inner implementation of [`update_ast`] that performs the actual
84 /// parsing and map updates. Separated so that [`update_ast`] can

Callers 15

bench_update_astFunction · 0.80
bench_referencesFunction · 0.80
runFunction · 0.80
runFunction · 0.80
did_openMethod · 0.80
did_changeMethod · 0.80

Calls 8

bump_mixin_generationFunction · 0.85
preprocessFunction · 0.85
catch_panic_unwind_safeFunction · 0.85
is_blade_fileMethod · 0.80
writeMethod · 0.80
cloneMethod · 0.80
update_ast_innerMethod · 0.80
insertMethod · 0.45