apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 840 forks source link

Continuation Indentation appears to be doubling the entered value. #7524

Closed dustinsilva-acquia closed 2 months ago

dustinsilva-acquia commented 2 months ago

Apache NetBeans version

Apache NetBeans 22

What happened

While attempting PSR12 code conformation, I ran into an issue with the following code doubling "continuation indentation" values. Note that "sprintf" has 8 spaces in-front of it, where it should only have 4. My Continuation Indentation is set to 4, and when trying values like 1,2,3, etc. it is very clearly doubling the indentation amount before sprintf, and its closing paren.

// This is how my formatter makes it look.
// Continuation Indentation = 4.
$output = Utils::runCommand(
        sprintf(
            'value %s %s',
            $prefix,
            $docroot
        ),
        $output
);

// This is how it should look.
$output = Utils::runCommand(
    sprintf(
        'value %s %s',
        $prefix,
        $docroot
    ),
    $output
);

Language / Project Type / NetBeans Component

PHP Project

How to reproduce

create a PHP file, copy in the provided code, set "continuation indentation" to 4, press CTRL+SHIFT+F to format, and notice how many spaces sprintf if from the start of $command_output; if it fails as mine does, the spaces will double the value entered for "continuation indentation".

Did this work correctly in an earlier version?

No / Don't know

Operating System

Mac OS X version 14.5 running on x86_64; UTF-8; en_US (nb)

JDK

Java: 22.0.1; OpenJDK 64-Bit Server VM 22.0.1+8

Apache NetBeans packaging

Third-party package

Anything else

Installed from self contained from Codelerity: https://github.com/codelerity/netbeans-installers/releases/download/v22-build1/Apache-NetBeans-22-x86_64.pkg Note that this also happens on Apache NetBeans version 15 on the same Mac. Cannot confirm if this happens on other Operating Systems.

Are you willing to submit a pull request?

No

junichi11 commented 2 months ago

@dustinsilva-acquia I can't reproduce it. Please also write an expected result and an actual result. Please provide an example project with your formatting options if possible.

  1. Create a new project
  2. Write an example code
  3. Project properties > Formatting > Use project specific options
  4. Set your formatting option to reproduce it
  5. Zip your example project
  6. Attach it to this issue
dustinsilva-acquia commented 2 months ago

sample-project.zip

Thanks for your time on this.

junichi11 commented 2 months ago

Reproducible. Thanks!

Please write your example code like the following to the issue body:

// This is how my formatter makes it look.
// Continuation Indentation = 4.
$output = Utils::runCommand(
        sprintf(
            'value %s %s',
            $prefix,
            $docroot
        ),
        $output
);

// This is how it should look.
$output = Utils::runCommand(
    sprintf(
        'value %s %s',
        $prefix,
        $docroot
    ),
    $output
);

Please use not ` but ``` if your example code has multiple lines.

junichi11 commented 2 months ago

@dustinsilva-acquia You can test it with dev build: https://github.com/apache/netbeans/suites/25370046547/artifacts/1643402266

dustinsilva-acquia commented 2 months ago

I did have a few minutes to test this, and it worked in the example I provided, however, when I loaded up a class that had the same code in a method, it would not format it properly--I haven't had time to create a working example, but wanted to share this finding, however brief, in the event it may help you. Thanks for your work on NB!