From 25b76ffaf9a0f8ef627f58128709e6e970cb0f3d Mon Sep 17 00:00:00 2001 From: Aleh Kashnikau Date: Mon, 10 Aug 2015 12:28:24 +0300 Subject: [PATCH] added container's method name detection --- Completer.php | 17 ++++------------- Plugin.php | 14 +++++++++++--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Completer.php b/Completer.php index f0808ac..9796b52 100644 --- a/Completer.php +++ b/Completer.php @@ -17,19 +17,10 @@ public function __construct(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 []; + return array_map( + [$this, 'wrapEntry'], + $this->classNameCompleter->getEntries($project, $context) + ); } public function wrapEntry($entry) diff --git a/Plugin.php b/Plugin.php index 21344cf..48b9247 100644 --- a/Plugin.php +++ b/Plugin.php @@ -4,8 +4,9 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Complete\Resolver\NodeTypeResolver; -use Complete\Completer\CompleterFactory; +use Complete\CompleteEngine; use Parser\UseParser; +use Entity\FQCN; class Plugin { @@ -30,7 +31,7 @@ public function init() [$this->resolver, 'handleTypeResolveEvent'] ); $this->dispatcher->addListener( - CompleterFactory::CUSTOM_COMPLETER, + CompleteEngine::CUSTOM_COMPLETER, [$this, 'handleCompleteEvent'] ); } @@ -39,7 +40,14 @@ public function handleCompleteEvent($e) { $context = $e->context; if ($context->isMethodCall()) { - $e->completer = $this->completer; + list($type, $isThis, $types, $workingNode) = $context->getData(); + $fqcn = array_pop($types); + if ($fqcn instanceof FQCN + && $fqcn->toString() === 'DI\\Container' + && $workingNode->name === 'get' + ) { + $e->completer = $this->completer; + } } }