You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "naitsirch (via GitHub)" <gi...@apache.org> on 2023/03/14 13:27:16 UTC

[GitHub] [netbeans] naitsirch opened a new issue, #5663: [PHP] Wrong auto completion in foreach loop on iterators

naitsirch opened a new issue, #5663:
URL: https://github.com/apache/netbeans/issues/5663

   ### Apache NetBeans version
   
   Apache NetBeans 17
   
   ### What happened
   
   If I am iterating with `foreach` over an iterator object Netbeans offers auto completion for the members of the object that provides the iterator. But this is wrong.
   
   Here's a screenshot:
   ![grafik](https://user-images.githubusercontent.com/1118790/225010645-a6e941b4-75fe-4110-bb3b-87d616f50364.png)
   
   It would be great if Netbeans would offer auto completion for the `foreach` items (as far as I remember this already worked some years ago). But at least the wrong suggestions should be removed.
   
   You will find an example code to reproduce the issue below.
   
   ### How to reproduce
   
   ```php
   <?php
   
   class CollectionItem {}
   
   class Collection implements IteratorAggregate
   {
       public function __construct(
           private array $items
       ) {}
   
       public function getIterator(): \Traversable
       {
           return new ArrayIterator($this->items);
       }
   
       public function customCollectionMethod() {}
   }
   
   class Example
   {
       private Collection $collection;
       
       public function __construct()
       {
           $this->collection = new Collection([
               new CollectionItem(),
               new CollectionItem(),
           ]);
       }
   
       /**
        * @return CollectionItem[]
        */
       public function getCollection(): Collection
       {
           return $this->collection;
       }
   }
   
   $example = new Example();
   
   foreach ($example->getCollection() as $item) {
       $item-> // put your cursor here and press Ctrl + Space
   }
   ```
   
   Netbeans offers `getCollection()` and `customCollectionMethod()` for auto completion. This would be correct if I press Ctrl + Space after `$example->getCollection()->`. But when iterating over `$example->getCollection()` the items usually have other properties.
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Debian Linux
   
   ### JDK
   
   OpenJDK Runtime Environment 11.0.18+10-post-Debian-1deb11u1
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] naitsirch commented on issue #5663: [PHP] Wrong auto completion in foreach loop on iterators

Posted by "naitsirch (via GitHub)" <gi...@apache.org>.
naitsirch commented on issue #5663:
URL: https://github.com/apache/netbeans/issues/5663#issuecomment-1471732864

   > Currently, NB ignores return types of PHPDoc if original return types exist.
   
   I do understand that and that's okay. But that wasn't my main issue.
   
   The foreach loop uses `$example->getCollection()`. NB knows that its type is `Collection`. But why is it suggesting the methods of `Collection` as methods for `$item`? The latter is not of type `Collection` - in fact it is unknown for NB.
   
   I hope you understand my explanation :-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on issue #5663: [PHP] Wrong auto completion in foreach loop on iterators

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on issue #5663:
URL: https://github.com/apache/netbeans/issues/5663#issuecomment-1471377196

   Currently, NB ignores return types of PHPDoc if original return types exist.
   
   As work around:
   Using `@var`
   ```php
   /** @var CollectionItem $item */
   foreach ($example->getCollection() as $item) {
       $item-> // put your cursor here and press Ctrl + Space
   }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on issue #5663: [PHP] Wrong auto completion in foreach loop on iterators

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on issue #5663:
URL: https://github.com/apache/netbeans/issues/5663#issuecomment-1473165610

   Ah, I see now.
   
   It would be easy to understand if you write actual results and expected results.
   e.g.
   #### Actual result
   Items of `Collection` are shown in the CC list
   
   #### Expected result
   Items of `Collection` are not shown in the CC list
   
   I guess that the following case was supported in the past... (but I'm not sure because I don't implement it.)
   
   ```php
   class Example
   {
       /**
        * @var CollectionItem[]
        */
       private $collection;
       
   foreach ($example->getCollection() as $item) {
       $item-> // put your cursor here and press Ctrl + Space
   }
   ```
   
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists