-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for completing constants * Constant completion * Added completion section * Updated CHANGELOG
- Loading branch information
Showing
6 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
Completion | ||
========== | ||
|
||
Phpactor provides completion for: | ||
|
||
- **Class names**: All PSR compliant classes in the project and vendor tree. | ||
- **Class members**: Methods, constants, properties of auto-loadable classes. | ||
- **Functions**: Built-in and bootstrapped. | ||
- **Constants**: Built-in and bootstrapped. | ||
- **Parameters**: Will suggest appropriate local variables for method parameters. | ||
|
||
Uniquely, Phpactor does not pre-index anything, completion happens in _real | ||
time_, file locations are guessed based on composer locations (or brute forced | ||
if not using composer). For non-autoloadable entities (e.g. functions) it is | ||
assumed that these are defined during bootstrap. | ||
|
||
Type inference | ||
-------------- | ||
|
||
Phpactors type inference is based on | ||
[WorseReflection](https://github.com/phpactot/worse-reflection). | ||
|
||
### Assert | ||
|
||
When encountering an `assert` with `instanceof` it will cast the variable | ||
to that type, or a union of that type. See also [#instanceof](#instanceof). | ||
|
||
```php | ||
assert($foo instanceof Hello); | ||
assert($foo instanceof Hello || $foo instanceof Goodbye) | ||
|
||
$foo-> // type: Hello|Goodbye | ||
``` | ||
|
||
### Assignments | ||
|
||
Phpactor will track assignemnts: | ||
|
||
```php | ||
$a = 'hello'; | ||
$b = $a; | ||
$b; // type: string | ||
``` | ||
|
||
### Catch | ||
|
||
```php | ||
|
||
try { | ||
// something | ||
} catch (MyException $e) { | ||
$e-> // type: MyException | ||
} | ||
``` | ||
|
||
### Foreach | ||
|
||
Understands `foreach` with the docblock array annotation: | ||
|
||
```php | ||
/** @var Hello[] $foos */ | ||
$foos = []; | ||
|
||
foreach ($foos as $foo) { | ||
$foo-> // type:Hello | ||
} | ||
``` | ||
|
||
Also understands simple generics: | ||
|
||
```php | ||
/** @var ArrayIterator<Hello> $foos */ | ||
$foos = new ArrayIterator([ new Hello() ]); | ||
|
||
foreach ($foos as $foo) { | ||
$foo-> // type:Hello | ||
} | ||
``` | ||
|
||
### FunctionLike | ||
|
||
Understands annonymous functions: | ||
|
||
``` | ||
$barfoo = new Barfoo(); | ||
$function = function (Foobar $foobar) use ($barfoo) { | ||
$foobar-> // type: Foobar | ||
$barfoo-> // type: Barfoo | ||
} | ||
``` | ||
|
||
### InstanceOf | ||
|
||
`if` statements are evaluated, if they contain `instanceof` then the type is | ||
inferred: | ||
|
||
```php | ||
if ($foobar instanceof Hello) { | ||
$foobar-> // type: Hello | ||
} | ||
``` | ||
|
||
```php | ||
if (false === $foobar instanceof Hello) { | ||
return; | ||
} | ||
|
||
$foobar-> // type: Hello | ||
``` | ||
|
||
```php | ||
if ($foobar instanceof Hello || $foobar instanceof Goodbye) { | ||
$foobar-> // type: Hello|Goodbye | ||
} | ||
``` | ||
|
||
### Variables | ||
|
||
Phpactor supports type injection via. docblock: | ||
|
||
``` | ||
/** @var Foobar $foobar */ | ||
$foobar-> // type: Foobar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters