phpactor/completion
最新稳定版本:0.4.7
Composer 安装命令:
composer require phpactor/completion
包简介
Completion library for Worse Reflection
README 文档
README
PHP Code Completion library for Phpactor.
This package includes:
- Completion APIs and implementations.
- Phpactor RPC extension and handlers.
- Language Server extension and handlers.
Usage
Each completor implements the Completor interface which accepts the source
code as a string and a byte offset from which to complete from. The completor
must yield instances of the Suggestion class:
$completor = new MyCompletor(); $suggestions = $completor->complete($sourceCode, $byteOffset); /** @var Suggestion $suggestion */ foreach ($suggestions as $suggestion) { echo $suggestion->name(); echo $suggestion->shortDescription(); }
Multiple completors can be chained together with the ChainCompletor:
$completor = new ChainCompletor([ new MyCompletor1(), new MyCompletor2(), ]); $suggestions = $completor->complete($sourceCode, $byteOffset);
Tolerant Completors
The library currently includes a suite of completors using the Tolerant PHP
Parser and WorseReflection.
All of the tolerant completors are instances of TolerantCompletorInterface
and accept a parser node rather than a byte offset. They can be collected in a
TolerantChainCompletor class which in turn implements the primary
Completor interface:
use Phpactor\WorseReflection\ReflectorBuilder; use Phpactor\Completion\Bridge\TolerantParser\ChainTolerantCompletor; use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseLocalVariableCompletor; use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseClassMemberCompletor; $reflector = ReflectorBuilder::create()->addSource($sourceCode)->build(); $formatter = new ObjectFormatter([ // ... instances of ObjectFormatter ]); $completor = new ChainTolerantCompletor([ new WorseLocalVariableCompletor($reflector, $formatter), new WorseClassMemberCompletor($reflector, $formatter), ]); $completor->complete($sourceCode, $byteOffset);
Formatters
This library can format arbitrary objects as strings, for example to go from a
ReflectionMethod to the synopsis: pub function($foobar).
$formatter = new ObjectFormatter([ new TypeFormatter(), new TypesFormatter(), new FunctionFormatter(), new MethodFormatter(), new ParameterFormatter(), new ParametersFormatter(), new PropertyFormatter(), new VariableFormatter(), ]); $reflectionMethod = $reflector->reflectClass(Foobar::class)->methods()->get('barfoo'); $formatter->format($reflectionMethod);
Each formatter is able to indicate if it can format a given object, and if so it is chosen.
Contributing
This package is open source and welcomes contributions! Feel free to open a pull request on this repository.
Support
- Create an issue on the main Phpactor repository.
- Join the
#phpactorchannel on the Slack Symfony Devs channel.
统计信息
- 总下载量: 53.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-01