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

comments moves to beginning of the line if written above control structure #142

Open
vikaskhunteta opened this issue Apr 1, 2024 · 18 comments

Comments

@vikaskhunteta
Copy link

Hi,

Everything works fine except the comments before the control structure, see the screenshot

Screenshot 2024-04-01 192938

Other than above issue, the extension works great into VS code even for large files but doesn't work into sublime text, only very small files are formatted. For medium to large size files, it hangs the editor and I have to end the process to resume working. I don't use VS code for development purpose, so I have to switch between editors just for formatting.

@driade
Copy link

driade commented Apr 1, 2024

Hi @vikaskhunteta. I use it on my regular basis on Sublime Text, and seems fine. May you please share some of this big files with me to check if there's any infinite loop? The code behind both vscode-phpfmt and the sublime plugin it's the same (https://github.com/driade/phpfmt8).

@vikaskhunteta
Copy link
Author

@driade Thanks for prompt response, the files on which the extension hangs into sublime doesn't have even 200 lines, I believe there must be some conflict with other extension installed. Here is the list of extension installed

Better Completion, Bootstrap 3 Snippets, BracketHighlighter, Brackets Color Scheme, Color Highlighter, CSS Lint, DocBlockr, DotENV, Emmet, Emmet CSS Snippets, Formatter, Git, HTML, HTML-CSS-JS Prettify, HTML5, HTMLBeautify, jQuery, JSHint, JSHint Gutter, JsPrettier, Minifier, Minify, Monokai Extended, PyV8, Rails, Sass, SCSS, SCSS Compiler, SideBarEnhancements, SideBarGit, SublimeCodeIntel, SublimeLinter, SublimeLinter-csslint, SublimeLinter-phplint, Tailwind CSS Autocomplete, WordPress

I removed PHPFMT package because of the issue mentioned earlier, I have two PHP installed, default is PHP7.4 also set Path env, but for PHPFMT I configured PHP8.2 as it was not working at all with PHP7.4 into sublime, however into VS Code it working with PHP7.4 without issue.

@driade
Copy link

driade commented Apr 1, 2024

Thanks. I'll check the comment formating issue.

@vikaskhunteta
Copy link
Author

@driade Any update on this? Also did you get chance to debug the issue on Sublime Text with all packages that I have installed on my system?

@driade
Copy link

driade commented Apr 17, 2024

No chance to check it, sorry.

@lutyne
Copy link

lutyne commented Jun 28, 2024

me too. troubling question

@lutyne
Copy link

lutyne commented Jun 28, 2024

comments moves to beginning, is there any solution?

@vikaskhunteta
Copy link
Author

vikaskhunteta commented Jun 28, 2024

@lutyne The only working solution I found is to use of multi line comments instead of single line comments above the if condition

@lutyne
Copy link

lutyne commented Jun 28, 2024

@vikaskhunteta multi comments cause another problem, the comments are not only moved to the head, but also separated......
企业微信截图_17195650241592
企业微信截图_17195650377057

@driade
Copy link

driade commented Jun 28, 2024

Sorry, I'll try to find a solution next month

@vikaskhunteta
Copy link
Author

Screenshot 2024-06-28 143043
@lutyne Multi line comments are written like this

@lutyne
Copy link

lutyne commented Jun 28, 2024

A matter of habit.... It seems I need to adapt.

@vikaskhunteta
Copy link
Author

@driade Did you get chance to look into this? Other than issue with comments above if and foreach syntax,

if the comment is placed after the closing curly braces like below

{
    some code
} // comment

then after formatting it would go down like this

{
    some code
}

// comment

sometimes comments after the syntax like this also move to new line below the syntax

$value = functionName( [
    'Id' => $id // REQUIRED
] );

@driade
Copy link

driade commented Jan 8, 2025

Hi @vikaskhunteta @lutyne I'm unable to reproduce this issue.

For example this code on my side gets perfectly formated

<?php
class A
{
    // foo
    public $a = 1;

    // bar
    public $b = 2;

    public function handle()
    {
          // $seach_param['b'] = input();
          // $seach_param['b'] = input();
          // $seach_param['b'] = input();
    } // comment
}

May you please share some complete samples?

@vikaskhunteta
Copy link
Author

@driade Write down the single line comment above if condition or foreach statement, also put single line comments in each row without new line between them, on format a new line will be put between them see the screenshot
image

@driade
Copy link

driade commented Jan 8, 2025

// comment 1
// comment 2
// comment 3
if ($a) {

}
<?php
class A
{
    public function handle()
    {
        // comment 1
        // comment 2
        // comment 3
        if ($a) {

        }
    }
}

This gets correctly formated on my side. It may help if you share a complete failing snippet

@vikaskhunteta
Copy link
Author

@driade Can you share your extension settings? Btw I am using VS code.

@driade
Copy link

driade commented Jan 8, 2025

@vikaskhunteta there you've

{
    "phpfmt.autocomplete": false,
    "phpfmt.autoimport": false,
    "phpfmt.excludes": [
        "SpaceBetweenMethods"
    ],
    "editor.formatOnSave": true,
    "phpfmt.passes": [
        "AlignDoubleArrow",
        "AlignPHPCode",
        "SpaceAfterExclamationMark",
        "AlignConstVisibilityEquals",
        "AutoSemicolon",
        "ConvertOpenTagWithEcho",
        "AlignEquals",
        "MergeNamespaceWithOpenTag",
        "RemoveSemicolonAfterCurly",
        "RestoreComments",
        "ShortArray",
        "ExtraCommaInArray",
        "AlignDoubleSlashComments"
    ],
    "phpfmt.php_bin": "/usr/local/bin/php",
    "phpfmt.psr1": false,
    "phpfmt.psr1_naming": false,
    "phpfmt.psr2": true,
    "phpfmt.readini": true,
    "phpfmt.smart_linebreak_after_curly": false,
    "phpfmt.version": 4,
    "phpfmt.wp": false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants