Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 - Confusing commentsBlocks references #278

Closed
miljan-aleksic opened this issue Mar 14, 2019 · 2 comments
Closed

3.0 - Confusing commentsBlocks references #278

miljan-aleksic opened this issue Mar 14, 2019 · 2 comments
Assignees

Comments

@miljan-aleksic
Copy link

miljan-aleksic commented Mar 14, 2019

Hi, first of all thank you for your work :)

I found it confusing and difficult to associate comments with their methods in the current 3.0-prerelease 8 version. Taking as example:

<?php

namespace Foospace\Foo;

/**
 * Class description
 */
class FooClass
{
    /**
     * Description
     */
    public static function bar()
    {
        return $array;
    }

    /**
     * Description
     */
    public static function baz()
    {
        return $array;
    }
  
    /**
     * Description
     */
    public static function woo()
    {
        return $array;
    }
}

the AST explorer will render something like this:

// class body
[
    {
        "kind": "method",
        "leadingComments": [...],
        "body": {
            "trailingComments": [...],
        },
        ...
    },
    {
        "kind": "method",
        "body": {
            "trailingComments": [...],
        },
        ...
    },
    {
        "kind": "method",
        "body": {
            "trailingComments": [...],
        },
        ...
    }
]

The confusing part is that the trailing comments are part of the method body, which is not accurate.

And I would expect each method to have it leadingComments as the first one in order to access them easier.

@alexander-akait
Copy link
Collaborator

Looks like a bug, thanks for issue

@ichiriac
Copy link
Member

ichiriac commented Apr 7, 2019

Hi @miljan-aleksic,

Sorry for the late reply, this bug was corrected after the last release, but not yet released. With actual version master here the output :

/**
 * Class description
 */
class FooClass
{
    /**
     * Description
     */
    public static function bar()
    {
        return $array;
    }

    /**
     * Description
     */
    public static function baz()
    {
        return $array;
    }
  
    /**
     * Description
     */
    public static function woo()
    {
        return $array;
    }
    // true trailing comment
}
Program {
  "children": Array [
    Class {
      "body": Array [
        Method {
          "arguments": Array [],
          "body": Block {
            "children": Array [
              Return {
                "expr": Variable {
                  "byref": false,
                  "curly": false,
                  "kind": "variable",
                  "name": "array",
                },
                "kind": "return",
              },
            ],
            "kind": "block",
          },
          "byref": false,
          "isAbstract": false,
          "isFinal": false,
          "isStatic": true,
          "kind": "method",
          "leadingComments": Array [
            CommentBlock {
              "kind": "commentblock",
              "offset": 51,
              "value": "/**
     * Description
     */",
            },
          ],
          "name": Identifier {
            "kind": "identifier",
            "name": "bar",
          },
          "nullable": false,
          "type": null,
          "visibility": "public",
        },
        Method {
          "arguments": Array [],
          "body": Block {
            "children": Array [
              Return {
                "expr": Variable {
                  "byref": false,
                  "curly": false,
                  "kind": "variable",
                  "name": "array",
                },
                "kind": "return",
              },
            ],
            "kind": "block",
          },
          "byref": false,
          "isAbstract": false,
          "isFinal": false,
          "isStatic": true,
          "kind": "method",
          "leadingComments": Array [
            CommentBlock {
              "kind": "commentblock",
              "offset": 155,
              "value": "/**
     * Description
     */",
            },
          ],
          "name": Identifier {
            "kind": "identifier",
            "name": "baz",
          },
          "nullable": false,
          "type": null,
          "visibility": "public",
        },
        Method {
          "arguments": Array [],
          "body": Block {
            "children": Array [
              Return {
                "expr": Variable {
                  "byref": false,
                  "curly": false,
                  "kind": "variable",
                  "name": "array",
                },
                "kind": "return",
              },
            ],
            "kind": "block",
            "trailingComments": Array [
              CommentLine {
                "kind": "commentline",
                "offset": 364,
                "value": "// true trailing comment
",
              },
            ],
          },
          "byref": false,
          "isAbstract": false,
          "isFinal": false,
          "isStatic": true,
          "kind": "method",
          "leadingComments": Array [
            CommentBlock {
              "kind": "commentblock",
              "offset": 261,
              "value": "/**
     * Description
     */",
            },
          ],
          "name": Identifier {
            "kind": "identifier",
            "name": "woo",
          },
          "nullable": false,
          "type": null,
          "visibility": "public",
        },
      ],
      "extends": null,
      "implements": null,
      "isAbstract": false,
      "isAnonymous": false,
      "isFinal": false,
      "kind": "class",
      "leadingComments": Array [
        CommentBlock {
          "kind": "commentblock",
          "offset": 1,
          "value": "/**
 * Class description
 */",
        },
      ],
      "name": Identifier {
        "kind": "identifier",
        "name": "FooClass",
      },
    },
  ],

The actually ugly thing is that's the last true trailing comment, is attached on the body and not to the method, as the body is the last node on the same level... and it's much harder to fix.

I'll let you know when the the alpha9 will be released on this issue.

@ichiriac ichiriac added the RELEASE-READY Waiting to release label Apr 7, 2019
@ichiriac ichiriac added this to the 3.0.0-prerelease.9 milestone Apr 7, 2019
@ichiriac ichiriac removed the RELEASE-READY Waiting to release label Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants