Bug 238505 - Inline comment to help autocompletion no longer working
Summary: Inline comment to help autocompletion no longer working
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P1 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Michael Spector CLA
QA Contact: Sylvia Tancheva CLA
URL:
Whiteboard:
Keywords: contributed
: 249705 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-25 21:19 EDT by Double Compile CLA
Modified: 2020-05-14 11:07 EDT (History)
10 users (show)

See Also:
ganoro: iplog+


Attachments
Bugfix (1.08 KB, patch)
2009-01-22 12:42 EST, Vadim Punski CLA
no flags Details | Diff
patch and unitest for the issue (1.95 KB, patch)
2009-01-25 05:12 EST, Vadim Punski CLA
no flags Details | Diff
golden for the test (987 bytes, patch)
2009-01-25 10:24 EST, Vadim Punski CLA
no flags Details | Diff
fix for canse insesitive typing (758 bytes, patch)
2009-01-25 10:55 EST, Vadim Punski CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Double Compile CLA 2008-06-25 21:19:03 EDT
Build ID: I20080617-2000

Steps To Reproduce:
Create this file:

<?php
class Foobar
{
    public function nonsense()
    {
    }
}

$className = 'Foobar';
$obj = null;
/* @var $obj ReflectionClass */
$obj->
// (no code completion)

More information:
This works in Eclipse 3.3.2 with PDT 1.0.3, but not in Eclipse 3.4 with PDT 1.1.0.20080616.

What happened to the comments that can "help" the autocompletion?
Comment 1 Double Compile CLA 2008-06-25 21:22:21 EDT
Sorry, I copied and pasted my proof-of-concept.  This might make more sense:

<?php
class Foobar
{
    public function nonsense()
    {
    }
}

$obj = null;
/* @var $obj Foobar */
$obj->
// (no code completion)
Comment 2 Roy Ganor CLA 2008-06-26 01:28:05 EDT
(In reply to comment #1)
> Sorry, I copied and pasted my proof-of-concept.  This might make more sense:
> <?php
> class Foobar
> {
>     public function nonsense()
>     {
>     }
> }
> $obj = null;
> /* @var $obj Foobar */
> $obj->
> // (no code completion)

hi,
have you tried to put the comment before the assignment? 

<?php
class Foobar
{
    public function nonsense()
    {
    }
}

/* @var $obj Foobar */
$obj = null;
$obj->
// (code completion should be here)
Comment 3 Double Compile CLA 2008-06-26 09:02:45 EDT
 reply to comment #2)
> have you tried to put the comment before the assignment? 

Hi, Roy.
Putting the hint before the assignment doesn't work either.

Besides, there are times when you don't know the type to hint until after the variable has been assigned; example:

function( $foo ) {
   if ( $foo instanceof ReflectionClass ) {
       /* @var $foo ReflectionClass */
       // $foo-> 
   } else if ( is_string($foo) ) {
       // etc...
   }
}

Furthermore, putting the hint after the assignment worked in 1.0.3 ;)

Thx,
―DC
Comment 4 David Muir CLA 2008-07-01 01:15:27 EDT
Yeah, doesn't work for me either.
Code completion is very flakey in 1.1
Sometimes it finds stuff, but most of the time, it just says "No completions available". And "Open Declaration" doesn't work either, so I can't use that to jump to the appropriate files/positions in the file.
Comment 5 Roy Ganor CLA 2008-07-06 07:47:32 EDT
Well, it randomally works for me :),
indeed we should fix this problem
 

(In reply to comment #4)
> Yeah, doesn't work for me either.
> Code completion is very flakey in 1.1
> Sometimes it finds stuff, but most of the time, it just says "No completions
> available". And "Open Declaration" doesn't work either, so I can't use that to
> jump to the appropriate files/positions in the file.

Comment 6 Michael Spector CLA 2008-07-17 04:20:26 EDT
This feature works like follows now:

1. /* @var ... */ must precede to variable declaration (which is an assignment)
For example, in your case the following structure will work:

/* @var $foo ReflectionClass */
$foo = $foo;
$foo->

I agree that this is a workaround rather than a solution.

2. Normally, variable type should be detected by type inferencing engine using various hints, like:

a. Function argument type hint:

function foo(A $var) { ...}

b. Function return type:

$var = foo(); // foo is declared as returning "A" in PHPdoc, or there's a 'return' statement, which can be evaluated.

c. Explicit declaration:

$var = new A();

d. etc...

(In reply to comment #3)
>  reply to comment #2)
> > have you tried to put the comment before the assignment? 
> 
> Hi, Roy.
> Putting the hint before the assignment doesn't work either.
> 
> Besides, there are times when you don't know the type to hint until after the
> variable has been assigned; example:
> 
> function( $foo ) {
>    if ( $foo instanceof ReflectionClass ) {
>        /* @var $foo ReflectionClass */
>        // $foo-> 
>    } else if ( is_string($foo) ) {
>        // etc...
>    }
> }
> 
> Furthermore, putting the hint after the assignment worked in 1.0.3 ;)
> 
> Thx,
> ―DC
> 

Comment 7 Michael Spector CLA 2008-10-06 08:44:37 EDT
*** Bug 249705 has been marked as a duplicate of this bug. ***
Comment 8 Guy Gurfinkel CLA 2008-10-22 10:16:49 EDT
the explanation Michael provided is fine by me.
If there is a specific example were the type inferencer does not work as expected a new issue should be submitted.
Comment 9 Gadi Goldbarg CLA 2008-10-22 10:40:55 EDT
Verified on N20081022
Closing

[Sylvia Tancheva]
Comment 10 Mark Kirchner CLA 2009-01-05 09:17:25 EST
Please consider to reopen this bug (I'm not allowed to do so myself):

(In reply to comment #6)
> 1. /* @var ... */ must precede to variable declaration (which is an assignment)
> For example, in your case the following structure will work:
> 
> /* @var $foo ReflectionClass */
> $foo = $foo;
> $foo->
> 
> I agree that this is a workaround rather than a solution.

Definitely. And you probably won't expect anybody to use such a nonsensical line of code in any kind of production-level software, since this line won't survive a review / refactoring (carried out by someone who is not familiar with this specific bug).

Another example:
<?php
class Foo {
  public $bar;
  
  /**
   * @return array
   */
  public static function getArray() {
    // ...
  }
}

foreach (Foo::getArray() as $anElement) {
  /* @var $anElement Foo */
  $anElement->|  // invoke code-assist here
}
?>

Another (probably even better) option would be to improve the phpdoc-parser/type-inference-engine to handle stuff like "@return array[Foo]" (or whatever the appropriate syntax is in this case). I think Bug 170968 already covers this RFE.
In the meantime, the explicit type-hinting should be fixed (without resorting to kludges like "$foo = $foo").
Comment 11 Nick Miller CLA 2009-01-08 10:29:56 EST
Dear Great PDT Developers,

This bug does not appear to be fixed in the latest stable release of PDT 2.0. I have confirmed this problem on two different workstations, one running OS X, and the other Windows XP. This bug is driving our development staff up the wall. We need our type hints! :-)

Best, 
Nick
Comment 12 Vadim Punski CLA 2009-01-22 12:42:21 EST
Created attachment 123402 [details]
Bugfix

The patch fixes the problem of null re-assignment.
Comment 13 Vadim Punski CLA 2009-01-25 05:12:01 EST
Created attachment 123670 [details]
patch and unitest for the issue

1. Fix to the problem described.
2. Unitest for the problematic behavior.
Comment 14 Vadim Punski CLA 2009-01-25 10:24:56 EST
Created attachment 123673 [details]
golden for the test

Golden file for the test provided in a previous attachment
Comment 15 Vadim Punski CLA 2009-01-25 10:55:38 EST
Created attachment 123675 [details]
fix for canse insesitive typing

fixed in trunk
Comment 16 Roy Ganor CLA 2009-01-25 11:13:18 EST
Contributed by Vadim P.

Unit test:

CODE:

<?php 
	class Foobar {
		public function nonsense(){} 
	} 
	/* @var $obj Foobar */ 
	$obj = null; 
	$obj->|
 ?>

COMPLETIONS:

[METHOD_DECLARATION]{completion:nonsense(), declSign:, declKey:, key:, name:nonsense, [106,106], relevance=1000000}
Comment 17 Roy Ganor CLA 2009-01-25 11:40:22 EST
*** Bug 260330 has been marked as a duplicate of this bug. ***
Comment 18 Bogdan Ribic CLA 2009-03-01 18:50:20 EST
I'm sure it worked without assignment prior to 2.0, ie I remember using it.

Problem with this only-assignment policy is that its useless with foreach, ie if you have an array of objects. Perhaps it can be reverted to old way, ie just apply type hint to closest var with that name?


(In reply to comment #6)
> This feature works like follows now:
> 
> 1. /* @var ... */ must precede to variable declaration (which is an assignment)
> For example, in your case the following structure will work:
> 
> /* @var $foo ReflectionClass */
> $foo = $foo;
> $foo->
> 
> I agree that this is a workaround rather than a solution.