1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Padawan\Command; |
4
|
|
|
|
5
|
|
|
use Padawan\Framework\Complete\CompleteEngine; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Padawan\Framework\Application\Socket\HttpOutput; |
9
|
|
|
use Padawan\Domain\ProjectRepository; |
10
|
|
|
use Padawan\Framework\Domain\Project\Persister; |
11
|
|
|
|
12
|
|
|
class CompleteCommand extends AsyncCommand |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this->setName("complete") |
18
|
|
|
->setDescription("Finds completion") |
19
|
|
|
->addArgument( |
20
|
|
|
"path", |
21
|
|
|
InputArgument::REQUIRED, |
22
|
|
|
"Path to the project root" |
23
|
|
|
)->addArgument( |
24
|
|
|
"column", |
25
|
|
|
InputArgument::REQUIRED, |
26
|
|
|
"Column number of cursor position" |
27
|
|
|
)->addArgument( |
28
|
|
|
"line", |
29
|
|
|
InputArgument::REQUIRED, |
30
|
|
|
"Line number of cursor position" |
31
|
|
|
)->addArgument( |
32
|
|
|
"data", |
33
|
|
|
InputArgument::REQUIRED, |
34
|
|
|
"File contents" |
35
|
|
|
)->addArgument( |
36
|
|
|
"filepath", |
37
|
|
|
InputArgument::REQUIRED, |
38
|
|
|
"Path to file relative to project root" |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
protected function executeAsync(InputInterface $input, HttpOutput $output) |
42
|
|
|
{ |
43
|
|
|
$column = $input->getArgument("column"); |
44
|
|
|
$file = $input->getArgument("filepath"); |
45
|
|
|
$line = $input->getArgument("line"); |
46
|
|
|
$content = $input->getArgument("data"); |
47
|
|
|
$path = $input->getArgument("path"); |
48
|
|
|
|
49
|
|
|
$projectRepository = $this->getContainer()->get(ProjectRepository::class); |
50
|
|
|
$project = $projectRepository->findByPath($path); |
51
|
|
|
|
52
|
|
|
$completeEngine = $this->getContainer()->get(CompleteEngine::class); |
53
|
|
|
/** @var Persister */ |
54
|
|
|
$persister = $this->getContainer()->get(Persister::class); |
|
|
|
|
55
|
|
|
try { |
56
|
|
|
$completion = $completeEngine->createCompletion( |
57
|
|
|
$project, |
58
|
|
|
$content, |
59
|
|
|
$line, |
60
|
|
|
$column, |
61
|
|
|
$file |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
yield $output->write( |
65
|
|
|
json_encode( |
66
|
|
|
[ |
67
|
|
|
"completion" => $this->prepareEntries( |
68
|
|
|
$completion["entries"] |
69
|
|
|
), |
70
|
|
|
"context" => $completion["context"] |
71
|
|
|
] |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
yield $output->disconnect(); |
75
|
|
|
} catch (\Exception $e) { |
76
|
|
|
yield $output->write( |
77
|
|
|
json_encode( |
78
|
|
|
[ |
79
|
|
|
"completion" => [], |
80
|
|
|
"context" => [] |
81
|
|
|
] |
82
|
|
|
) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
protected function prepareEntries(array $entries) { |
87
|
|
|
$result = []; |
88
|
|
|
foreach ($entries as $entry) { |
89
|
|
|
$result[] = [ |
90
|
|
|
"name" => $entry->getName(), |
91
|
|
|
"signature" => $entry->getSignature(), |
92
|
|
|
"description" => $entry->getDesc(), |
93
|
|
|
"menu" => $entry->getMenu() |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
return $result; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.