Skip to main content

Crate phpantom_lsp

Crate phpantom_lsp 

Source
Expand description

PHPantom — a fast, lightweight PHP language server.

Diagnostics are debounced: each did_change bumps a per-file version counter and spawns a delayed task. The task only publishes if its version still matches (i.e. no newer edit arrived in the meantime).

This crate is organised into the following modules:

  • types — Data structures for extracted PHP information (classes, methods, functions, etc.)
  • parser — PHP parsing and AST extraction using mago_syntax
  • completion — Completion logic (target extraction, type resolution, item building, and the top-level completion request handler)
  • composer — Composer autoload (PSR-4, classmap) parsing and class-to-file resolution
  • server — The LSP LanguageServer trait implementation (thin wrapper that delegates to feature-specific modules)
  • util — Utility helpers (position conversion, class lookup, logging)
  • hover — Hover support (textDocument/hover). Resolves the symbol under the cursor and returns type information, method signatures, and docblock descriptions
  • signature_help — Signature help (textDocument/signatureHelp). Shows parameter hints while typing function/method arguments, with active-parameter tracking
  • definition — Go-to-definition support for classes, members, and functions
  • inheritance — Base class inheritance resolution. Merges members from parent classes and traits into a unified ClassInfo
  • virtual_members — Virtual member provider abstraction. Defines the VirtualMemberProvider trait and merge logic for members synthesized from @method/@property tags, @mixin classes, and framework-specific patterns (e.g. Laravel)
  • resolution — Class and function lookup / name resolution (multi-phase: class_index → ast_map → classmap → PSR-4 → stubs)
  • subject_extraction — Shared helpers for extracting the left-hand side of ->, ?->, and :: access operators (used by both completion and definition)
  • highlight — Document highlighting (textDocument/documentHighlight). When the cursor lands on a symbol, returns all other occurrences in the current file so the editor can highlight them. Uses the precomputed SymbolMap with no additional parsing. Variables are scoped to their enclosing function/closure; class names, members, functions, and constants are file-global.
  • semantic_tokens — Semantic tokens (textDocument/semanticTokens/full). Type-aware syntax highlighting that goes beyond TextMate grammars. Maps SymbolMap spans to LSP semantic token types (class, interface, enum, method, property, parameter, variable, function, constant) with modifiers (declaration, static, readonly, deprecated, abstract). Resolves ClassReference spans to distinguish classes from interfaces, enums, and traits. Template parameter names from @template tags are emitted as typeParameter tokens.
  • code_actions — Code actions (textDocument/codeAction). Provides:
    • code_actions::import_class — Import class quick-fix (add a use statement for unresolved class names)
    • code_actions::remove_unused_import — Remove unused import quick-fix (delete individual or all unused use statements)
    • code_actions::generate_constructor — Generate a constructor from non-static properties
    • code_actions::generate_getter_setter — Generate getX()/setX() accessor methods (or isX() for bool properties) from a property declaration
  • diagnostics — Diagnostic collection and delivery. Supports both pull diagnostics (textDocument/diagnostic, LSP 3.17) and push diagnostics (textDocument/publishDiagnostics) as a fallback. Currently implemented providers:
    • diagnostics::deprecated@deprecated usage diagnostics (strikethrough via DiagnosticTag::Deprecated on references to deprecated symbols)
    • diagnostics::unused_imports — unused use dimming (DiagnosticTag::Unnecessary on imports with no references in the file)
    • diagnostics::unknown_classes — unknown class diagnostics (Severity::Warning on ClassReference spans that cannot be resolved through any resolution phase)
    • diagnostics::unresolved_member_access — opt-in diagnostic (Severity::Hint on MemberAccess spans where the subject type cannot be resolved at all; enabled via [diagnostics] unresolved-member-access = true in .phpantom.toml)
  • docblock — PHPDoc block parsing, split into submodules:
    • docblock::tags — tag extraction (@return, @var, @property, @method, @mixin, @deprecated, @phpstan-assert, docblock text retrieval)
    • docblock::conditional — PHPStan conditional return type parsing
    • docblock::types — type utilities (split_type_token), PHPStan array shape parsing (parse_array_shape, extract_array_shape_value_type), and object shape parsing (parse_object_shape, extract_object_shape_property_type, is_object_shape)

Re-exports§

pub use types::AccessKind;
pub use types::ClassInfo;
pub use types::DefineInfo;
pub use types::FunctionInfo;
pub use types::Visibility;

Modules§

analyse
CLI analysis mode.
classmap_scanner
Fast byte-level PHP symbol scanners for early-stage file discovery.
completion
composer
Composer autoload support.
config
Configuration loaded from .phpantom.toml.
diagnostics
Diagnostics — collect and deliver LSP diagnostics for PHP files.
docblock
PHPDoc block parsing.
fix
CLI fix mode.
php_type
Structured representation of PHP type expressions.
stubs
subject_expr
Structured subject expression parsing.
types
Data types used throughout the PHPantom server.

Structs§

Backend
The main LSP backend that holds all server state.

Functions§

extract_completion_target
Detect the access operator before the cursor position and extract both the AccessKind and the textual subject to its left.
resolve_class_fully
Resolve a class with full inheritance and virtual member providers.