NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Codecompletion `broken in 5989?


Joined: 08 Sep 2009
Posts: 9
Reply with quote
I recently updated to the lates build and discovered that some of the code completion have stopped working and give a rather dubious error message "Failed to identitfy type of returning value ...".

This worked in my previous version 5980 ( or somewhere around there ).


The error appears if I am trying to via PHPDoc syntax define a class for example

/** @var \Product $Product */
$Product = $Datastore->getProduct($id);

this gave me codecompletion earlier but with the latest release it only give me the error message.

Help is greatly apreciated Smile
View user's profileFind all posts by quickolaSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
I'm assuming the Datastore is a class that return items of type Product class.

If that is the case, then this works in my 5989:
Code:
class Product {
  protected $_productName = null;
  public function loadProduct($id) {
    $this->_productName = 'PRODUCT-' . $id;
    return $this;
  }
  public function getName() {
    return $this->_productName;
  }
}

class Datastore {
  protected $_product = null;
  public function __construct() {
    $this->_product = new Product();
  }
  public function getProduct($id) {
    return $this->_product->loadProduct($id);
  }
}

$Datastore = new Datastore();
/**
* @var Product
*/
$Product = $Datastore->getProduct(1234);
echo 'Name is ' . $Product->getName();

Put your cursor after $Product-> and you should get code completion. The @var immediately precedes the first assignment of the $Product variable and specifies the datatype (in this case it is a class name). Any text after the datatype is a human readable description and not parsed by PhpED. In my example $Datastore does not require an @var because PhpED recognises new Datastore() and knows the variable type from that.

If this doesn't help, please share a little more information about the structure of your classes and exactly where you want to get code completion. Wink
View user's profileFind all posts by plugnplaySend private message


Joined: 08 Sep 2009
Posts: 9
Reply with quote
Thanks for your help but it still wont work for me. Here is another simple example of what doesnt work for me.

file class.Product.php:

class Product{
}


file index.php

/** @var Product $prod */
$prod = $Datastore->getProduct();

The way this worked earlier was that the PHPDoc syntax preceded everything else and did just look at the $prod as a type of Product, but now it will only give me a $prod unknown type.


thanks
View user's profileFind all posts by quickolaSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
Your example works in my 5989, although I did add a function so that it would popup with something in code completion:

file class.Product.php:

Code:
class Product{
  public function test() {
    return 'value';
  }
}


file index.php

Code:
/** @var Product */
$prod = $Datastore->getProduct();
$prod-> // code completion works here


Does class.Product.php appear in the Code Explorer panel? Maybe try doing a refresh in the Code Explorer panel to see if that helps? The new 5990 is supposed to help with some Code Completion issue, but I'm not sure it would help this.
View user's profileFind all posts by plugnplaySend private message


Joined: 08 Sep 2009
Posts: 9
Reply with quote
Thanks for your help. I did find out what was my problem. It seems like PHPEd has gotten much stricter on the PHPDoc return types than earlier. I had an abstract class Datastore that was set to return a "mixed" type and that one apearantly messed up my code completion.

Earlier I could override these return types with just redefining the type of the variable where I wanted too but that doesnt seem possible now, so I guess I have to start commenting my classes and functions better Razz
View user's profileFind all posts by quickolaSend private message
Codecompletion `broken in 5989?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic