Skip to content

Indentation-based approach to folding is not effective #568

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

Open
3 tasks done
per1234 opened this issue Oct 22, 2021 · 0 comments
Open
3 tasks done

Indentation-based approach to folding is not effective #568

per1234 opened this issue Oct 22, 2021 · 0 comments
Labels
topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Oct 22, 2021

Describe the problem

The IDE's code folding system assumes that code blocks will always be indented, and that indented text is always a code block.

🐛 This not a valid assumption. As a result, some code blocks are not foldable, some don't fold correctly, and some things fold that should not.

To reproduce

  1. Open a sketch that contains code with structure not reflected by indentation:

    /*
    this is not foldable
      this is foldable
    */
    
    /* this block is not foldable
    the IDE does not indent the contents of block comments
    */
    
    void setup() {  // this block is not foldable
    #ifdef FOO  // common code style is no indentation preprocessor blocks, since they are independent from the C++ code structure
      // this block is foldable
    #endif
    }
    
    void loop() { // This block folds incorrectly
      // only this line is folded when folding the `loop` block
    #ifdef FOO
      // this block is foldable
    #endif  // this is treated as a block
      // this is not folded when folding the `loop` block
    bar:  // this is treated as a block
      ; // this is not folded when folding the `loop` block
    }
  2. Hover the mouse pointer up and down through the left margin of the editor pane in the IDE. Noting the locations of the fold controls.

    • 🐛 Expected fold controls are missing at lines 1, 6, and 10.
    • 🐛 An unexpected fold control is present at lines 2 and 22.

    image

  3. Do a "Fold All". Note the results.

    • 🐛 Lines 7, 11-13, 18, 20, and 22 are not folded as expected

    image

Expected behavior

Folding occurs based on code structure, independent from indentation.

Arduino IDE version

Original report

2.0.0-beta.12-nightly.20211021

Last verified with

63e9dfd

Operating system

Windows

Operating system version

  • Windows 10
  • Windows 11

Additional context

Previously reported at arduino/arduino-pro-ide#13 and claimed to be fixed at that time, so perhaps a regression.


Folding is more reliable in the Arduino IDE 1.x:

image

image

Additional reports

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Oct 22, 2021
@per1234 per1234 changed the title Folding not working for block comments Indentation-based approach to folding is not effective Oct 22, 2021
@per1234 per1234 added the topic: language server Related to the Arduino Language Server label Oct 22, 2021
@per1234 per1234 added topic: infrastructure Related to project infrastructure and removed topic: code Related to content of the project itself topic: language server Related to the Arduino Language Server labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants