mir_analyzer/symbol.rs
1//! Per-expression resolved symbol data, retained from Pass 2.
2//!
3//! The static analyzer already resolves types for every expression during
4//! analysis but historically discarded the intermediate state. This module
5//! exposes that data so that downstream consumers (e.g. php-lsp) can build
6//! position indexes for hover, go-to-definition, and completions.
7
8use std::sync::Arc;
9
10use mir_types::Union;
11use php_ast::Span;
12
13/// A single resolved symbol observed during Pass 2.
14#[derive(Debug, Clone)]
15pub struct ResolvedSymbol {
16 /// Byte-offset span in the source file.
17 pub span: Span,
18 /// What kind of symbol this is.
19 pub kind: SymbolKind,
20 /// The resolved type at this location.
21 pub resolved_type: Union,
22}
23
24/// The kind of symbol that was resolved.
25#[derive(Debug, Clone)]
26pub enum SymbolKind {
27 /// A variable reference (`$foo`).
28 Variable(String),
29 /// An instance method call (`$obj->method()`).
30 MethodCall { class: Arc<str>, method: Arc<str> },
31 /// A static method call (`Foo::method()`).
32 StaticCall { class: Arc<str>, method: Arc<str> },
33 /// A property access (`$obj->prop`).
34 PropertyAccess { class: Arc<str>, property: Arc<str> },
35 /// A free function call (`foo()`).
36 FunctionCall(Arc<str>),
37 /// A class reference (`new Foo`, `instanceof Foo`, type hints).
38 ClassReference(Arc<str>),
39}