Skip to content

Commit e3c8afc

Browse files
committed
fixed static completion
Added static and self completion
1 parent 3634fea commit e3c8afc

7 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/Complete/Completer/StaticCompleter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getEntries(Project $project, Context $context){
3434
return [];
3535
}
3636
$entries = [];
37-
$spec = new Specification($isThis ? 'private' : 'public', true);
37+
$spec = new Specification($isThis ? 'private' : 'public', 1);
3838
if($class->methods !== null){
3939
foreach($class->methods->all($spec) AS $method){
4040
$entry = $this->createEntryForMethod($method);
@@ -76,7 +76,7 @@ protected function createEntryForMethod(MethodData $method){
7676
protected function createEntryForProperty(ClassProperty $prop){
7777
$type = $prop->type instanceof FQCN ? $prop->type->toString() : 'mixed';
7878
return new Entry(
79-
$prop->name,
79+
'$' . $prop->name,
8080
$type
8181
);
8282
}

src/Complete/Resolver/NodeTypeResolver.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function getType($node, Index $index, Scope $scope){
5858
* @return FQCN|null
5959
*/
6060
public function getChainType($node, Index $index, Scope $scope){
61+
/** @var FQCN */
6162
$type = null;
6263
$chain = $this->createChain($node);
6364
foreach($chain AS $block){
@@ -79,6 +80,15 @@ public function getChainType($node, Index $index, Scope $scope){
7980
}
8081
elseif($block['type'] === 'class'){
8182
$type = $block['name'];
83+
if(
84+
$type->getClassName() === 'self'
85+
|| $type->getClassName() === 'static'
86+
){
87+
$type = $scope->getFQCN();
88+
}
89+
elseif($type->getClassName() === 'parent'){
90+
$type = $this->getParentType($scope->getFQCN(), $index);
91+
}
8292
}
8393
}
8494
return $type;
@@ -158,6 +168,17 @@ protected function getPropertyType($name, FQCN $type, Index $index){
158168
}
159169
return $prop->getType();
160170
}
171+
protected function getParentType(FQCN $type, Index $index){
172+
$class = $index->findClassByFQCN($type);
173+
if(empty($class)){
174+
return null;
175+
}
176+
$parent = $class->getParent();
177+
if(empty($parent)){
178+
return null;
179+
}
180+
return $parent->fqcn;
181+
}
161182

162183
/** @property LoggerInterface */
163184
private $logger;

src/Entity/Collection/MethodsCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function remove(MethodData $method){
2424
}
2525
public function get($name, Specification $spec = null){
2626
if($spec === null){
27-
$spec = new Specification('private', false, true);
27+
$spec = new Specification('private', 2, true);
2828
}
2929
if(array_key_exists($name, $this->methods)){
3030
$method = $this->methods[$name];

src/Entity/Collection/PropertiesCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function all(Specification $spec = null){
3939
}
4040
public function get($propName, Specification $spec = null){
4141
if($spec === null){
42-
$spec = new Specification;
42+
$spec = new Specification('private', 2, false);
4343
}
4444
if(array_key_exists($propName, $this->map)){
4545
$prop = $this->map[$propName];

src/Entity/Collection/Specification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function satisfy($node){
2828
return false;
2929
}
3030
}
31-
if($node->isStatic() !== $this->showStatic){
31+
if($this->showStatic < 2 && $node->isStatic() != $this->showStatic){
3232
return false;
3333
}
3434
return true;

src/Entity/Completion/Token.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ protected function removeType($type){
113113
}
114114
}
115115

116-
/**
117-
* @return Token
118-
*/
119-
protected static function test(){
120-
121-
}
122-
123116
const T_UNKNOWN = -1;
124117
const T_CONTINUE_PROCESS = 1;
125118
const T_TERMINATE = 2;

src/Entity/FQN.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ public function __toString(){
6868
return $this->toString();
6969
}
7070

71+
public static $test;
7172
private $parts;
7273
}

0 commit comments

Comments
 (0)