From df1444502ce83f41dcb8985d46d92c4ae50888dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sun, 28 Oct 2018 21:00:00 +0100 Subject: [PATCH 1/9] ci: Add ability to find documentation for static functions defined in parent contexts --- src/DefinitionResolver.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 3a4f3785..c1c7623c 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -493,21 +493,33 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ } elseif ($scoped->scopeResolutionQualifier instanceof Node\QualifiedName) { $className = $scoped->scopeResolutionQualifier->getResolvedName(); } - if ($scoped->memberName instanceof Node\Expression\Variable) { + do { + if ($scoped->memberName instanceof Node\Expression\Variable) { + if ($scoped->parent instanceof Node\Expression\CallExpression) { + return null; + } + $memberName = $scoped->memberName->getName(); + if (empty($memberName)) { + return null; + } + $name = (string)$className . '::$' . $memberName; + } else { + $name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents()); + } if ($scoped->parent instanceof Node\Expression\CallExpression) { - return null; + $name .= '()'; } - $memberName = $scoped->memberName->getName(); - if (empty($memberName)) { - return null; + $definition = $this->index->getDefinition($name); + if(!!$definition) { + break; + } else { + $class = $this->index->getDefinition((string)$className); + if(!$class) { + break; + } + $className = $class->extends[0]; } - $name = (string)$className . '::$' . $memberName; - } else { - $name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents()); - } - if ($scoped->parent instanceof Node\Expression\CallExpression) { - $name .= '()'; - } + } while (true); return $name; } From c6eda5f30f5fc545180ba8f374e193535930b55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sun, 28 Oct 2018 21:20:01 +0100 Subject: [PATCH 2/9] fix: Fix some possible notices --- src/DefinitionResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index c1c7623c..93d19671 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -514,8 +514,8 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ break; } else { $class = $this->index->getDefinition((string)$className); - if(!$class) { - break; + if(!$class || empty($class->extends)) { + return null; } $className = $class->extends[0]; } From 6fa6fd57dbef1b7efa7c1f62ea9cc9544af0f8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sun, 28 Oct 2018 21:37:44 +0100 Subject: [PATCH 3/9] fix: Fix spacing --- src/DefinitionResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 93d19671..d67d0916 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -510,11 +510,11 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ $name .= '()'; } $definition = $this->index->getDefinition($name); - if(!!$definition) { + if (!!$definition) { break; } else { $class = $this->index->getDefinition((string)$className); - if(!$class || empty($class->extends)) { + if ($class === null || empty($class->extends)) { return null; } $className = $class->extends[0]; From d231f425b9e818de717b7dc12a33a00cc3909b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sun, 28 Oct 2018 22:19:24 +0100 Subject: [PATCH 4/9] Fix: Small fixes --- src/DefinitionResolver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index d67d0916..e07981a8 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -493,6 +493,7 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ } elseif ($scoped->scopeResolutionQualifier instanceof Node\QualifiedName) { $className = $scoped->scopeResolutionQualifier->getResolvedName(); } + $origName = null; do { if ($scoped->memberName instanceof Node\Expression\Variable) { if ($scoped->parent instanceof Node\Expression\CallExpression) { @@ -509,13 +510,16 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ if ($scoped->parent instanceof Node\Expression\CallExpression) { $name .= '()'; } + if ($origName === null) { + $origName = $name; + } $definition = $this->index->getDefinition($name); if (!!$definition) { break; } else { $class = $this->index->getDefinition((string)$className); if ($class === null || empty($class->extends)) { - return null; + return $origName; } $className = $class->extends[0]; } From 107c962df83fb119d8ce5a2aec8138b856554104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sat, 22 Dec 2018 23:11:37 +0100 Subject: [PATCH 5/9] test: The inherited static methods and properties --- fixtures/global_references.php | 3 +++ fixtures/references.php | 3 +++ src/DefinitionResolver.php | 26 ++++++++++--------- tests/Server/ServerTestCase.php | 16 +++++++++--- .../TextDocument/References/GlobalTest.php | 24 +++++++++++++++++ 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/fixtures/global_references.php b/fixtures/global_references.php index c76c9347..25c4a35d 100644 --- a/fixtures/global_references.php +++ b/fixtures/global_references.php @@ -41,3 +41,6 @@ function whatever(TestClass $param): TestClass { $child = new ChildClass; echo $child->testMethod(); + +ChildClass::staticTestMethod(); +ChildClass::$staticTestProperty[123]->testProperty; diff --git a/fixtures/references.php b/fixtures/references.php index b98a38ee..1fd0a0c5 100644 --- a/fixtures/references.php +++ b/fixtures/references.php @@ -41,3 +41,6 @@ function whatever(TestClass $param): TestClass { $child = new ChildClass; echo $child->testMethod(); + +ChildClass::staticTestMethod(); +ChildClass::$staticTestProperty[123]->testProperty; diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index e07981a8..322f5449 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -494,19 +494,21 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ $className = $scoped->scopeResolutionQualifier->getResolvedName(); } $origName = null; - do { - if ($scoped->memberName instanceof Node\Expression\Variable) { - if ($scoped->parent instanceof Node\Expression\CallExpression) { - return null; - } - $memberName = $scoped->memberName->getName(); - if (empty($memberName)) { - return null; - } - $name = (string)$className . '::$' . $memberName; - } else { - $name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents()); + $nameSuffix = null; + if ($scoped->memberName instanceof Node\Expression\Variable) { + if ($scoped->parent instanceof Node\Expression\CallExpression) { + return null; + } + $memberName = $scoped->memberName->getName(); + if (empty($memberName)) { + return null; } + $nameSuffix = '::$' . $memberName; + } else { + $nameSuffix = '::' . $scoped->memberName->getText($scoped->getFileContents()); + } + do { + $name = (string)$className . $nameSuffix; if ($scoped->parent instanceof Node\Expression\CallExpression) { $name .= '()'; } diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 880e1a00..8a37faf8 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -84,6 +84,8 @@ public function setUp() 'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))), + 'ChildClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))), + 'ChildClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))), 'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113,11), new Position(113, 26))), @@ -103,6 +105,8 @@ public function setUp() 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))), + 'TestNamespace\\ChildClass::staticTestProperty'=> new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), + 'TestNamespace\\ChildClass::staticTestMethod()'=> new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))), 'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))), @@ -153,10 +157,12 @@ public function setUp() ], 'TestNamespace\\TestClass::staticTestProperty' => [ 0 => new Location($referencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty; - 1 => new Location($referencesUri, new Range(new Position(39, 11), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; + 1 => new Location($referencesUri, new Range(new Position(39, 11), new Position(39, 30))), // TestClass::$staticTestProperty[123]->testProperty; + 2 => new Location($referencesUri, new Range(new Position(45, 12), new Position(45, 31))) // ChildClass::$staticTestProperty[123]->testProperty; ], 'TestNamespace\\TestClass::staticTestMethod()' => [ - 0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 27))) + 0 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 27))), + 1 => new Location($referencesUri, new Range(new Position(44, 0), new Position(44, 28))) ], 'TestNamespace\\TestClass::testMethod()' => [ 0 => new Location($referencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod(); @@ -207,10 +213,12 @@ public function setUp() ], 'TestClass::staticTestProperty' => [ 0 => new Location($globalReferencesUri, new Range(new Position( 8, 16), new Position( 8, 35))), // echo TestClass::$staticTestProperty; - 1 => new Location($globalReferencesUri, new Range(new Position(39, 11), new Position(39, 30))) // TestClass::$staticTestProperty[123]->testProperty; + 1 => new Location($globalReferencesUri, new Range(new Position(39, 11), new Position(39, 30))), // TestClass::$staticTestProperty[123]->testProperty; + 2 => new Location($globalReferencesUri, new Range(new Position(45, 12), new Position(45, 31))) // ChildClass::$staticTestProperty[123]->testProperty; ], 'TestClass::staticTestMethod()' => [ - 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 27))) + 0 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 27))), + 1 => new Location($globalReferencesUri, new Range(new Position(44, 0), new Position(44, 28))) ], 'TestClass::testMethod()' => [ 0 => new Location($globalReferencesUri, new Range(new Position( 5, 0), new Position( 5, 16))), // $obj->testMethod(); diff --git a/tests/Server/TextDocument/References/GlobalTest.php b/tests/Server/TextDocument/References/GlobalTest.php index d2550c8a..078fd275 100644 --- a/tests/Server/TextDocument/References/GlobalTest.php +++ b/tests/Server/TextDocument/References/GlobalTest.php @@ -198,4 +198,28 @@ public function testReferencesForUnusedMethod() )->wait(); $this->assertEquals([], $result); } + public function testReferencesForInheritedStaticMethods() + { + // public static function staticTestMethod() + // Get references for staticTestMethod + $definition = $this->getDefinitionLocation('ChildClass::staticTestMethod()'); + $result = $this->textDocument->references( + new ReferenceContext, + new TextDocumentIdentifier($definition->uri), + $definition->range->start + )->wait(); + $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result); + } + public function testReferencesForInheritedStaticProperties() + { + // public static $staticTestProperty; + // Get references for $staticTestProperty + $definition = $this->getDefinitionLocation('ChildClass::staticTestProperty'); + $result = $this->textDocument->references( + new ReferenceContext, + new TextDocumentIdentifier($definition->uri), + $definition->range->start + )->wait(); + $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result); + } } From 89886b19e390e49cded7bf8d818f8945b473c2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sat, 22 Dec 2018 23:20:15 +0100 Subject: [PATCH 6/9] fix: We effectively don't need these tests They are tested as references to the TestClass --- tests/Server/ServerTestCase.php | 2 -- .../TextDocument/References/GlobalTest.php | 24 ------------------- 2 files changed, 26 deletions(-) diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 8a37faf8..50910e0a 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -105,8 +105,6 @@ public function setUp() 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))), - 'TestNamespace\\ChildClass::staticTestProperty'=> new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), - 'TestNamespace\\ChildClass::staticTestMethod()'=> new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))), 'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))), diff --git a/tests/Server/TextDocument/References/GlobalTest.php b/tests/Server/TextDocument/References/GlobalTest.php index 078fd275..d2550c8a 100644 --- a/tests/Server/TextDocument/References/GlobalTest.php +++ b/tests/Server/TextDocument/References/GlobalTest.php @@ -198,28 +198,4 @@ public function testReferencesForUnusedMethod() )->wait(); $this->assertEquals([], $result); } - public function testReferencesForInheritedStaticMethods() - { - // public static function staticTestMethod() - // Get references for staticTestMethod - $definition = $this->getDefinitionLocation('ChildClass::staticTestMethod()'); - $result = $this->textDocument->references( - new ReferenceContext, - new TextDocumentIdentifier($definition->uri), - $definition->range->start - )->wait(); - $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result); - } - public function testReferencesForInheritedStaticProperties() - { - // public static $staticTestProperty; - // Get references for $staticTestProperty - $definition = $this->getDefinitionLocation('ChildClass::staticTestProperty'); - $result = $this->textDocument->references( - new ReferenceContext, - new TextDocumentIdentifier($definition->uri), - $definition->range->start - )->wait(); - $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result); - } } From 637f2bc741f7999c36a88d8a6f440ff0de57d216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sat, 22 Dec 2018 23:21:42 +0100 Subject: [PATCH 7/9] fix: We don't need these --- tests/Server/ServerTestCase.php | 2 -- .../TextDocument/References/GlobalTest.php | 24 ------------------- 2 files changed, 26 deletions(-) diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 8a37faf8..50910e0a 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -105,8 +105,6 @@ public function setUp() 'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))), - 'TestNamespace\\ChildClass::staticTestProperty'=> new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))), - 'TestNamespace\\ChildClass::staticTestMethod()'=> new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1))), 'TestNamespace\\Example' => new Location($symbolsUri, new Range(new Position(101, 0), new Position(104, 1))), diff --git a/tests/Server/TextDocument/References/GlobalTest.php b/tests/Server/TextDocument/References/GlobalTest.php index 078fd275..d2550c8a 100644 --- a/tests/Server/TextDocument/References/GlobalTest.php +++ b/tests/Server/TextDocument/References/GlobalTest.php @@ -198,28 +198,4 @@ public function testReferencesForUnusedMethod() )->wait(); $this->assertEquals([], $result); } - public function testReferencesForInheritedStaticMethods() - { - // public static function staticTestMethod() - // Get references for staticTestMethod - $definition = $this->getDefinitionLocation('ChildClass::staticTestMethod()'); - $result = $this->textDocument->references( - new ReferenceContext, - new TextDocumentIdentifier($definition->uri), - $definition->range->start - )->wait(); - $this->assertEquals($this->getReferenceLocations('TestClass::staticTestMethod()'), $result); - } - public function testReferencesForInheritedStaticProperties() - { - // public static $staticTestProperty; - // Get references for $staticTestProperty - $definition = $this->getDefinitionLocation('ChildClass::staticTestProperty'); - $result = $this->textDocument->references( - new ReferenceContext, - new TextDocumentIdentifier($definition->uri), - $definition->range->start - )->wait(); - $this->assertEquals($this->getReferenceLocations('TestClass::staticTestProperty'), $result); - } } From cc4a63fc58cb5e953f8c5aeff14672ff98fe95b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sat, 22 Dec 2018 23:26:11 +0100 Subject: [PATCH 8/9] fix: Move the leftovet bit outside --- src/DefinitionResolver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 322f5449..26e29fb6 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -507,11 +507,11 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\ } else { $nameSuffix = '::' . $scoped->memberName->getText($scoped->getFileContents()); } + if ($scoped->parent instanceof Node\Expression\CallExpression) { + $nameSuffix .= '()'; + } do { $name = (string)$className . $nameSuffix; - if ($scoped->parent instanceof Node\Expression\CallExpression) { - $name .= '()'; - } if ($origName === null) { $origName = $name; } From c3b8cbd73bc5699dfa47006061fb62b1c6a75799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Let=C3=A1=C4=8Dek?= Date: Sat, 22 Dec 2018 23:58:18 +0100 Subject: [PATCH 9/9] fix: Yet another copy of unused reference --- tests/Server/ServerTestCase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 4322c3ec..16aa47e5 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -84,8 +84,6 @@ public function setUp() 'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))), 'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))), - 'ChildClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))), - 'ChildClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))), 'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))), 'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))), 'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113,11), new Position(113, 26))),