Skip to content

Commit 03d95dd

Browse files
committed
Update feature list and examples
1 parent fcdba8f commit 03d95dd

2 files changed

Lines changed: 264 additions & 310 deletions

File tree

README.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,59 @@ A fast, lightweight PHP language server that stays out of your way. Using only a
66
77
## Features
88

9-
### Document Synchronization
9+
### Completion
1010

11-
- Full text document sync (open, change, close)
11+
- **Instance members** via `->` — methods, properties, constructor-promoted properties
12+
- **Static members** via `::` — static methods, static properties, constants, enum cases
13+
- **`parent::`** — inherited and overridden members (excludes private)
14+
- **Traits and interfaces** — trait members appear on the using class; interface contracts are resolved
15+
- **`@mixin` classes** — members from `@mixin` annotations are included, even when the mixin is declared on a parent class (the Laravel `Model`/`Builder` pattern works out of the box)
16+
- **Magic members**`@property`, `@property-read`, `@method` from PHPDoc
17+
- **Method chaining** — return types are followed through arbitrarily long chains
18+
- **Null-safe chaining**`?->` is handled identically to `->`
19+
- **Full signatures** in completion labels (parameters, types, return type)
20+
- Magic methods (`__construct`, `__destruct`, etc.) are filtered out of results
1221

13-
### PHP Analysis & Type Resolution
22+
<img width="683" height="339" alt="image" src="https://github.com/user-attachments/assets/65e8220d-5d94-466f-aea7-2f239a8d4b19" />
1423

15-
PHPantom uses a shared analysis engine built on [Mago](https://github.com/carthage-software/mago)'s PHP parser for parsing and type resolution, powering both completion and go-to-definition.
24+
### Go to Definition
1625

17-
- Extracts classes, interfaces, traits, enums, and standalone functions
18-
- Parses methods, properties, constants, and constructor-promoted properties with visibility, static modifiers, and type hints
19-
- Parses `use` statements and namespace declarations
20-
- PHPDoc annotations including:
21-
- `@return`, `@var`, `@property`, `@method`, `@mixin`
22-
- PHPStan-style conditional return types
23-
- Resolves `$this`, `self`, `static`, and `parent` keywords
24-
- Infers variable types from assignments and parameter type hints
25-
- Supports property chains and method call chaining (e.g., `$this->getService()->doSomething()`)
26-
- Resolves function and static method return types (e.g., `app()->`, `Class::make()->`)
27-
- Inheritance-aware resolution including traits cases
28-
- Handles union types (`A|B`) and ambiguous variables across conditional branches
26+
- **Classes, interfaces, traits, enums** — same-file and cross-file
27+
- **Methods, properties, constants** — resolves through inheritance, traits, and mixins
28+
- **Standalone functions** — including PHP built-ins via embedded stubs
29+
- **Variables** — jumps to the most recent assignment or declaration (assignment, parameter, `foreach`, `catch`, `static`/`global`)
30+
- **Namespace resolution** — fully-qualified, partially-qualified, and aliased names via `use ... as ...`
2931

30-
### Completion
32+
### Type Resolution
3133

32-
- Instance member completion via `->` (methods and properties)
33-
- Static member completion via `::` (static methods, static properties, constants, and enum cases)
34-
- `parent::` completion (static and non-static members, excluding private)
35-
- Magic method filtering (`__construct`, `__destruct`, etc. are excluded from results)
36-
- Full method signature display in completion labels (parameters, types, return type)
34+
PHPantom infers variable types from assignments, parameter hints, return types, and PHPDoc annotations, then uses them to power both completion and go-to-definition.
3735

38-
<img width="683" height="339" alt="image" src="https://github.com/user-attachments/assets/65e8220d-5d94-466f-aea7-2f239a8d4b19" />
36+
- **Union types** (`A|B`) and **intersection types** (`A&B`), including PHP 8.2 DNF types like `(A&B)|C`
37+
- **Conditional return types** — PHPStan-style `@return ($param is class-string<T> ? T : mixed)`, used by patterns like `app(User::class)->getEmail()`
38+
- **`@var` overrides** — inline `/** @var Type $var */` docblocks refine variable types
39+
- **Ambiguous variables** — when a variable is assigned different types in conditional branches, all candidates are offered
3940

40-
### Go to Definition
41+
### Type Narrowing
42+
43+
Completion results adapt to runtime type checks. PHPantomLSP narrows union types in both the positive and inverse branches of `if`/`else`, `while`, and `match(true)`:
4144

42-
- Jump to class, interface, trait, enum, and standalone function definitions
43-
- Jump to method, property, and constant definitions on a class
44-
- Same-file and cross-file definition lookup
45-
- Fully-qualified, partially-qualified, and unqualified name resolution via `use` statements and the current namespace
45+
- `instanceof` and negated `!instanceof`
46+
- `is_a($var, ClassName::class)`
47+
- `get_class($var) === ClassName::class` and `$var::class === ClassName::class` (including `!==` and reversed operand order)
48+
- `assert($var instanceof ClassName)`
49+
- **Custom assertion functions** via `@phpstan-assert` / `@psalm-assert` annotations:
50+
- `@phpstan-assert Type $param` — unconditional narrowing after the call
51+
- `@phpstan-assert-if-true Type $param` — narrows in the then-branch
52+
- `@phpstan-assert-if-false Type $param` — narrows in the else-branch
4653

47-
### Composer Integration
54+
### Composer & Project Awareness
4855

49-
- Parses `composer.json` for PSR-4 class mapping
50-
- Parses vendor autoload file and PSR-4 loading
51-
- Caches parsed files in memory to avoid redundant loading
56+
- Parses `composer.json` for PSR-4 and file autoload mappings
57+
- Resolves cross-file class lookups on demand
5258

5359
## Building
5460

55-
PHPantomLSP embeds [JetBrains phpstorm-stubs](https://github.com/JetBrains/phpstorm-stubs) at compile time to provide type information for PHP's built-in classes and functions. The stubs are managed as a Composer dependency with `stubs/` as the vendor directory.
61+
The PHP stubs are managed as a Composer dependency in `stubs/`. Install them before building:
5662

5763
```bash
5864
# Install the PHP stubs (requires Composer)

0 commit comments

Comments
 (0)