bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 93 forks source link

PHP docblock not working for existing files in project #1267

Open MikeTodd opened 4 years ago

MikeTodd commented 4 years ago

The automatic phpdoc doesn't seem to be working. Note: I have purchased the full version, and successfully activated my license key.

UPDATE - I just found an important clue: if I create a new file and make a function in it, then the phpdoc is generated correctly. But when I'm working with files already in my project, it doesn't work. If I disable Intelephense and enable an extension like PHP DocBlocker, then phpdoc is correctly generated within my existing files.

If I have this:

function foo($input) {
    return false;
}

I type /** before that and press enter, and all I get is:

/**
 * 
 */

Whereas I expect that to be more like:

/**
 * Undocumented function
 *
 * @param [type] $input
 * @return void
 */

I've tried setting up my intelephense.phpdoc.functionTemplate to various suggestions from these bug reports, but none produce any different output.

Alternatively, is there some way to allow other extensions to handle the phpdoc generation? I have PHP DocBlocker too, but if Intelephense is enabled it seems to override that extension.

Platform and version macOS 10.15.5 (latest), VS Code 1.46.1 (latest)

KapitanOczywisty commented 4 years ago

Have you changed any settings related to phpdoc inside intelephense section? And are you using any other extension for phpdoc?

2020-06-29_23-50-56

MikeTodd commented 4 years ago

I tried with both the default settings just after install (where intelephense.phpdoc.functionTemplate isn't even present), and trying to use some templates that I've found on here. Nothing results in different behavior.

I do not have any other phpdoc extensions installed, and I have disabled the "PHP Language Features" from VS Code as per the install instructions. Just to be certain, I've disabled all other extensions, and I'm using the default settings for Intelephense.

However, I did just find an important clue: if I create a new file and make a function in it, then the phpdoc is generated correctly. But when I'm working with files already in my project, it doesn't work. If I disable Intelephense and enable an extension like PHP DocBlocker, then phpdoc is correctly generated within my existing files.

MikeTodd commented 4 years ago

I'm testing this in a pretty large file that contains a lot of commonly-used functions in a legacy application. The file is about 13,000 lines long. When I remove all the functions starting at line 3500, then the phpdoc is generated correctly. I'm playing around with various configurations to see if I can figure out what's causing this.

If I trim down most of the file, but keep the following function definition as-is, phpdoc is not generated (in a "foo" type function that I add above this):

////
// Parse and secure the cPath parameter values
function tep_parse_category_path($cPath) {
    // make sure the category IDs are integers
    $cPath_array = array_map('tep_string_to_int', explode('_', $cPath));

    // make sure no duplicate category IDs exist which could lock the server in a loop
    $tmp_array = array();
    $n = count($cPath_array);
    for ($i = 0; $i < $n; $i++) {
        if (!in_array($cPath_array[$i], $tmp_array)) {
            $tmp_array[] = $cPath_array[$i];
        }
    }

    return $tmp_array;
}

However, if I remove that first line (the 4 forward-slashes), then phpdoc is generated. Alternatively, if I keep that line in but remove the first line in the function (the one with array_map), phpdoc is generated. Removing all other lines from the function, but keeping those two lines as-is results in no phpdoc.

So it seems that there are some cases where the parsing isn't working correctly, and existing code can cause it to fail.

bmewburn commented 4 years ago

I still can't reproduce the issue. @MikeTodd if I understand correctly the full reproducible example is as below (| indicating cursor).

<?php

|
function foo($input)
{
    return false;
}

////
// Parse and secure the cPath parameter values
function tep_parse_category_path($cPath)
{
    // make sure the category IDs are integers
    $cPath_array = array_map('tep_string_to_int', explode('_', $cPath));

    // make sure no duplicate category IDs exist which could lock the server in a loop
    $tmp_array = array();
    $n = count($cPath_array);
    for ($i = 0; $i < $n; $i++) {
        if (!in_array($cPath_array[$i], $tmp_array)) {
            $tmp_array[] = $cPath_array[$i];
        }
    }

    return $tmp_array;
}

Have you changed the editor.autoClosingBrackets setting? Which intelephense version are you using? Do you use php short open tags <? ? If so have you enabled them in intelephense.environment.shortOpenTag? Could you email me the problematic file if all else fails?

MikeTodd commented 4 years ago

@bmewburn

Have you changed the editor.autoClosingBrackets setting?

I have not, no.

Which intelephense version are you using?

The latest -- I installed it fresh the same day that I opened this ticket.

Do you use php short open tags <? ?

I do not, no. Though there is one place in the file that uses <?=, but even when I remove that this problem remains.

Could you email me the problematic file if all else fails?

I will send it to you yes.

bmewburn commented 4 years ago

Thanks @MikeTodd , unfortunately this still doesn't reproduce the issue for me. I've tried creating doc blocks in several places throughout the file and it has worked each time. I also installed PHP DocBlocker and had it and intelephense both showing suggestions as seen in screenshot below, there shouldn't be any conflict between the two. One thing I did notice is that there can be a delay in the suggestion appearing with a file of that size (I was seeing up to 1 second on a 7th gen i5 laptop). The PHP Docblocker response would likely be quicker than intelephense because it just looks at the function header. VSCode waits for all providers before showing suggestions.

Not sure where else to go from here. If you set intelephense.server.trace to verbose and look in the output tab this may show if intelephense returns are response and the time taken. The output tab may also show errors from the server.

Screenshot from 2020-07-02 08-08-37

MikeTodd commented 4 years ago

I tried waiting an extended period (2 minutes now) on the latest Macbook Pro with 2.6 GHz 6-Core Intel Core i7, still nothing. Maybe it's something about my project at large that is causing the issue.

I set intelephense.server.trace to verbose, but nothing is coming through the output tab at all. Oddly, when I hover over the function definition, it is showing everything correctly, it just seems unable to put that into phpdoc format.

screenshot

I have a feeling that whatever is causing this is probably pretty edge case. Is there any way to just have Intelephense not handle the phpdoc, and let PHP DocBlocker do it? If I disable Intelephense and enable PHP DocBlocker, it generates the documentation as expected. I absolutely love the rest of what Intelephense does, and it would be a shame to have to choose between the two.

bmewburn commented 4 years ago

Is there any way to just have Intelephense not handle the phpdoc, and let PHP DocBlocker do it?

Unfortunately not

arifszn commented 3 years ago

I had the same issue. My scenario is quite interesting.

  1. All was working fine.
  2. After updating vscode to the latest build(1.51), the extension began to misbehave. Suggestion was not coming out properly (not docblock). So I reinstalled vscode. Then installed this extension and activated premium features.
  3. Now, docblock suggestion was not popping up.
  4. Reinstalled the extension and checked without activating premium. The issue persisted.
  5. After activating premium this time, the issue solved. Now all are working perfectly again.
soderlind commented 3 years ago

After upgrading to 1.51.1 editor.suggest.showSnippets had been disabled. Enabling it, both Intenephense docblock and PHP Dockbloker works again :)

image

faelv commented 3 years ago

I have the same issue, after a VSCode update the docblock snippet isn't working anymore. VSCode: 1.54.1 Intelephense: 1.6.3 Changed editor.autoClosingBrackets: no Short open tags: no

mkarulin commented 3 years ago

Same issue and setting intelephense.server.trace to verbose shows nothing in the Output tab. Is this a WSL issue? VSCode 1.57.1 Intelephense: v1.7.1 Editing on WSL: Ubuntu

EDIT: After purchasing the license, i was able to generate the docblock via the ligtbulb icon that appeared next to the method.

aderowbotham commented 1 month ago

I have the same issue, clean install v1.10.4.

Doesn't write a phpdoc block in any circumstances - in a new PHP file within a project or even in a new project.

tohizma commented 1 month ago

I have same issue with version v1.12.2 (PREMIUM), VSC version 1.92.1

I must install PHP DocBlocker by Neil Brayfield to create auto docblock, please make it work to avoid another extension requirement just for docblock