Skip to main content

mir_analyzer/
lib.rs

1pub mod arena;
2pub mod cache;
3pub mod call;
4pub mod class;
5pub mod collector;
6pub mod context;
7pub mod db;
8pub mod dead_code;
9pub mod diagnostics;
10pub mod expr;
11pub mod file_analyzer;
12pub mod generic;
13pub mod narrowing;
14pub mod parser;
15pub mod pass2;
16pub mod php_version;
17pub mod project;
18pub mod session;
19pub mod stmt;
20pub mod stubs;
21pub mod taint;
22
23pub use file_analyzer::{FileAnalysis, FileAnalyzer};
24pub use parser::type_from_hint::type_from_hint;
25pub use parser::{DocblockParser, ParsedDocblock};
26pub use php_version::{ParsePhpVersionError, PhpVersion};
27pub use project::{AnalysisResult, ProjectAnalyzer};
28pub use session::AnalysisSession;
29pub use stubs::{is_builtin_function, stub_files, StubVfs};
30
31pub mod symbol;
32pub mod type_env;
33pub use mir_issues::{Issue, IssueKind, Location, Severity};
34
35/// Convert a parser [`php_ast::Span`] (byte-offset range) into a
36/// [`mir_codebase::storage::Location`] (file path + 1-based line range +
37/// 0-based codepoint columns) using `source` and the parser's `source_map`.
38///
39/// This is the canonical way for consumers to translate Pass-2 result spans
40/// (e.g. [`crate::symbol::ResolvedSymbol::span`]) into source locations they
41/// can hand to their own protocol layer. Consumers that need different
42/// position semantics (LSP UTF-16 code units, byte offsets, etc.) translate
43/// from this `Location` rather than re-implementing the column math.
44pub fn location_from_span(
45    span: php_ast::Span,
46    file: std::sync::Arc<str>,
47    source: &str,
48    source_map: &php_rs_parser::source_map::SourceMap,
49) -> mir_codebase::storage::Location {
50    let (line, col_start) = diagnostics::offset_to_line_col(source, span.start, source_map);
51    let (line_end, col_end) = if span.start < span.end {
52        diagnostics::offset_to_line_col(source, span.end, source_map)
53    } else {
54        (line, col_start)
55    };
56    mir_codebase::storage::Location {
57        file,
58        line,
59        line_end,
60        col_start,
61        col_end: col_end.max(col_start.saturating_add(1)),
62    }
63}
64pub use symbol::{DocumentSymbol, DocumentSymbolKind, ResolvedSymbol, SymbolKind};
65pub use type_env::{ScopeId, TypeEnv};
66
67pub mod composer;
68pub use composer::Psr4Map;
69
70pub mod test_utils;