Skip to content

Commit 25b76ff

Browse files
committed
added container's method name detection
1 parent 7d0041d commit 25b76ff

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Completer.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,10 @@ public function __construct(ClassNameCompleter $completer)
1717
}
1818
public function getEntries(Project $project, Context $context)
1919
{
20-
list($type, $isThis, $types) = $context->getData();
21-
if (is_array($types)) {
22-
$fqcn = array_pop($types);
23-
if ($fqcn instanceof FQCN
24-
&& $fqcn->toString() === 'DI\\Container'
25-
) {
26-
return array_map(
27-
[$this, 'wrapEntry'],
28-
$this->classNameCompleter->getEntries($project, $context)
29-
);
30-
}
31-
}
32-
return [];
20+
return array_map(
21+
[$this, 'wrapEntry'],
22+
$this->classNameCompleter->getEntries($project, $context)
23+
);
3324
}
3425

3526
public function wrapEntry($entry)

Plugin.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Symfony\Component\EventDispatcher\EventDispatcher;
66
use Complete\Resolver\NodeTypeResolver;
7-
use Complete\Completer\CompleterFactory;
7+
use Complete\CompleteEngine;
88
use Parser\UseParser;
9+
use Entity\FQCN;
910

1011
class Plugin
1112
{
@@ -30,7 +31,7 @@ public function init()
3031
[$this->resolver, 'handleTypeResolveEvent']
3132
);
3233
$this->dispatcher->addListener(
33-
CompleterFactory::CUSTOM_COMPLETER,
34+
CompleteEngine::CUSTOM_COMPLETER,
3435
[$this, 'handleCompleteEvent']
3536
);
3637
}
@@ -39,7 +40,14 @@ public function handleCompleteEvent($e)
3940
{
4041
$context = $e->context;
4142
if ($context->isMethodCall()) {
42-
$e->completer = $this->completer;
43+
list($type, $isThis, $types, $workingNode) = $context->getData();
44+
$fqcn = array_pop($types);
45+
if ($fqcn instanceof FQCN
46+
&& $fqcn->toString() === 'DI\\Container'
47+
&& $workingNode->name === 'get'
48+
) {
49+
$e->completer = $this->completer;
50+
}
4351
}
4452
}
4553

0 commit comments

Comments
 (0)