-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Completer Splitted Plugin to Plugin adn TypeResolver
- Loading branch information
Showing
3 changed files
with
116 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Mkusher\PadawanDi; | ||
|
||
use Complete\Completer\CompleterInterface; | ||
use Complete\Completer\ClassNameCompleter; | ||
use Entity\Completion\Entry; | ||
use Entity\Project; | ||
use Entity\Completion\Context; | ||
use Entity\FQCN; | ||
|
||
class Completer implements CompleterInterface | ||
{ | ||
public function __construct(ClassNameCompleter $completer) | ||
{ | ||
$this->classNameCompleter = $completer; | ||
} | ||
public function getEntries(Project $project, Context $context) | ||
{ | ||
list($type, $isThis, $types) = $context->getData(); | ||
if (is_array($types)) { | ||
$fqcn = array_pop($types); | ||
if ($fqcn instanceof FQCN | ||
&& $fqcn->toString() === 'DI\\Container' | ||
) { | ||
return array_map( | ||
[$this, 'wrapEntry'], | ||
$this->classNameCompleter->getEntries($project, $context) | ||
); | ||
} | ||
} | ||
return []; | ||
} | ||
|
||
public function wrapEntry($entry) | ||
{ | ||
return new Entry( | ||
sprintf('"%s"', $entry->getName()), | ||
$entry->getSignature(), | ||
$entry->getDesc(), | ||
$entry->getMenu() | ||
); | ||
} | ||
|
||
private $classNameCompleter; | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace Mkusher\PadawanDi; | ||
|
||
use Parser\UseParser; | ||
use Complete\Resolver\TypeResolveEvent; | ||
use Entity\FQCN; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Scalar\String_; | ||
|
||
class TypeResolver | ||
{ | ||
public function __construct( | ||
UseParser $useParser | ||
) { | ||
$this->useParser = $useParser; | ||
} | ||
|
||
public function handleParentTypeEvent(TypeResolveEvent $e) | ||
{ | ||
$this->parentType = $e->getType(); | ||
} | ||
|
||
public function handleTypeResolveEvent(TypeResolveEvent $e) | ||
{ | ||
$parentType = $this->parentType; | ||
if ($parentType instanceof FQCN | ||
&& $parentType->toString() === 'DI\\Container' | ||
) { | ||
/** @var \Entity\Chain\MethodCall */ | ||
$chain = $e->getChain(); | ||
if ($chain->getType() === 'method' && count($chain->getArgs()) > 0) { | ||
$firstArg = array_pop($chain->getArgs())->value; | ||
if ($firstArg instanceof String_) { | ||
$className = $firstArg->value; | ||
$fqcn = $this->useParser->parseFQCN($className); | ||
$e->setType($fqcn); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** @var UseParser */ | ||
private $useParser; | ||
private $parentType; | ||
} |