Skip to content

Commit

Permalink
added container's method name detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mkusher committed Aug 10, 2015
1 parent 7d0041d commit 25b76ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 4 additions & 13 deletions Completer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,7 +31,7 @@ public function init()
[$this->resolver, 'handleTypeResolveEvent']
);
$this->dispatcher->addListener(
CompleterFactory::CUSTOM_COMPLETER,
CompleteEngine::CUSTOM_COMPLETER,
[$this, 'handleCompleteEvent']
);
}
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 25b76ff

Please sign in to comment.