Skip to content

Commit 7d88d7a

Browse files
committed
added non-composer files parsing
Removed hard FQCN checking from CompleteEngine, so that completion would work in files that are not in the class map. Next step is to add namespace parsing and building FQCN from this information
1 parent 72a2b90 commit 7d88d7a

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/Complete/CompleteEngine.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Entity\Project;
66
use Entity\Completion\Scope;
7+
use Entity\FQN;
78
use Parser\Parser;
89
use Generator\IndexGenerator;
910
use Entity\Completion\Entry;
@@ -115,8 +116,8 @@ protected function processFileContent(Project $project, $lines, $line, $file){
115116
return;
116117
}
117118
$fqcn = $project->getIndex()->findFQCNByFile($file);
118-
if(!$fqcn){
119-
return;
119+
if(!$fqcn instanceof FQN){
120+
$fqcn = new FQN();
120121
}
121122
if(!array_key_exists($file, $this->cachePool)){
122123
$this->cachePool[$file] = [0, [], []];

src/Entity/Node/Uses.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace Entity\Node;
44

5+
use Entity\FQN;
56
use Entity\FQCN;
67

78
class Uses {
89
private $map = [];
910
private $reversed;
1011
private $fqcn;
1112

12-
public function __construct(FQCN $fqcn = null){
13+
public function __construct(FQN $fqcn = null){
1314
$this->fqcn = $fqcn;
1415
}
1516

src/Generator/IndexGenerator.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,19 @@ public function processFile(Index $index, $fqcn, $file,
149149
$end = microtime(1) - $startParser;
150150
$this->getLogger()
151151
->addInfo("Parsing: [$end]s");
152-
$this->processFileNodes($index, $fqcn, $nodes);
152+
$this->processFileNodes($index, $nodes);
153153
$index->addParsedFile($file);
154154
}
155-
public function processFileNodes(Index $index, FQCN $fqcn, $nodes){
156-
$index->addFQCN($fqcn);
155+
public function processFileNodes(Index $index, $nodes){
157156
$this->getLogger()->addDebug('Processing nodes ' . count($nodes));
158157
foreach($nodes as $node){
159158
if($node instanceof ClassData){
160-
$index->addClass($node, $fqcn->toString());
159+
$index->addFQCN($node->fqcn);
160+
$index->addClass($node, $node->fqcn->toString());
161161
}
162162
elseif($node instanceof InterfaceData){
163-
$index->addInterface($node, $fqcn->toString());
163+
$index->addFQCN($node->fqcn);
164+
$index->addInterface($node, $node->fqcn->toString());
164165
}
165166
}
166167
}

src/Parser/Parser.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Parser;
44

5+
use Entity\FQN;
56
use Entity\FQCN;
67
use Entity\Node\Uses;
78
use Utils\PathResolver;
@@ -26,20 +27,27 @@ public function __construct(
2627
$this->astPool = [];
2728
$this->logger = $logger;
2829
}
29-
public function parseFile(FQCN $fqcn, $file, $createCache=true){
30+
public function parseFile(FQN $fqcn, $file, $createCache=true){
3031
$file = $this->path->getAbsolutePath($file);
3132
$content = $this->path->read($file);
3233
return $this->parseContent($fqcn, $file, $content, $createCache);
3334
}
34-
public function parseContent(FQCN $fqcn, $file, $content, $createCache=true){
35+
public function parseContent(FQN $fqcn, $file, $content, $createCache=true){
3536
if($createCache){
3637
$hash = hash('md5', $content);
3738
if(!array_key_exists($file, $this->astPool)){
3839
$this->astPool[$file] = [0,0];
3940
}
4041
list($oldHash, $ast) = $this->astPool[$file];
4142
}
42-
$uses = new Uses($this->parseFQCN($fqcn->getNamespace()));
43+
var_dump($fqcn->toString());
44+
if($fqcn instanceof FQCN){
45+
$uses = new Uses($this->parseFQCN($fqcn->getNamespace()));
46+
}
47+
else {
48+
$uses = new Uses($fqcn);
49+
$fqcn = new FQCN('', $fqcn->getParts());
50+
}
4351
$this->useParser->setUses($uses);
4452
$this->logger->addDebug(sprintf('Cache status: %s', (
4553
$createCache ? 'active' : 'disabled'
@@ -49,7 +57,7 @@ public function parseContent(FQCN $fqcn, $file, $content, $createCache=true){
4957
$ast = $this->parser->parse($content);
5058
}
5159
catch(\Exception $e){
52-
printf("Parsing failed in file %s\n", $file);
60+
$this->logger->addError(sprintf("Parsing failed in file %s\n", $file));
5361
return [];
5462
}
5563
if($createCache){

0 commit comments

Comments
 (0)