Bug 422521 - syntax/folding (C/C++): "#..." interferes with std block "{" folding
Summary: syntax/folding (C/C++): "#..." interferes with std block "{" folding
Status: REPORTED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (other bugs)
Version First Reported In: unspecified
Platform: FreeBSD Ports FreeBSD
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-06 07:39 UTC by Torsten Eichstädt
Modified: 2020-06-22 11:34 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
freebsd's usr.sbin/powerd/powerd.c (19.63 KB, text/x-csrc)
2020-06-06 07:44 UTC, Torsten Eichstädt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Torsten Eichstädt 2020-06-06 07:39:11 UTC
SUMMARY
This has a subtle bad (buggy) consequence:  The whole part of the file after the function where the "#..." occurs gets hidden.  Very nasty... ;)

If s/o fixes this: IMHO the region of any "#if" (or "#ifdef" or such) should only span until an "#else" or "#elif", if such occurs. Any "#elif" or "#else" should start an own region until the next "#elif", "#else" or "#end".  Alternatively the "#elif" and "#else" could be sub-regions (then the starting "#if" must start two regions: outer->"#end", inner->"#el..."), but IMHO w/o sub-regions the user sees what the compiler sees (after the preprocessor, which processes the "#..." stuff), and that's what s/he is interested in.  As it is now, the folding of preproccessor directives ("#...") is so that I can fold s/th that does not match to what gets compiled.

STEPS TO REPRODUCE
1. Open the file "powerd.c" (attachment)
2. Point the mouse at the closing brace "}" of that function (line 397), and
   note where the region begins.
3. Point the mouse at the previous closing brace (line 396), and note where
   the region begins.  Very interesting...
4. Fold the function acline_read() (line 327): the whole rest of the file
   gets hidden.


OBSERVED RESULT
Folding a region that contains overlaping sub-regions brings the folding engine out of sync.  Sorry I can't explain it better...

EXPECTED RESULT
"PERFECT" behaviour ;)

SOFTWARE/OS VERSIONS
Windows: igitt!
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.18.4
KDE Frameworks Version: 5.68.0
Qt Version: 5.13.2

ADDITIONAL INFORMATION
THX for everything
Comment 1 Torsten Eichstädt 2020-06-06 07:44:03 UTC
Created attachment 129097 [details]
freebsd's usr.sbin/powerd/powerd.c
Comment 2 Nibaldo G. 2020-06-22 08:20:49 UTC
This is very difficult to fully correct. One solution may be to disable the folding of "{" and "}" inside the block "#else" - "#endif".

For example:

#ifdef SOMETHING
if (a >= b || b >= c) { // <-- Here folding in "{" is activated
#else
if (a < b && b < c) {   // <-- Here folding is disabled
#endif
    /* code */
}
Comment 3 Torsten Eichstädt 2020-06-22 11:21:20 UTC
Hello Nibaldo,

1. Nested regions are hairy... ;)

2. I do not remember if I did this right in prolog.xml: it has user regions
   (%BEGIN...%END; '%' is Prolog's one-line comment starter), and the usual folding
   for blocks and multi-line comments.  I do not have downloaded the KDE sources
   yet, so I can not have a look myself.  Maybe you like to have a look?
   Chances are I figured s/th out when I wrote that.

3. Yes, I agree.  A practical solution would be to start as you suggested.
   A really useful enhancement would be to switch activation based on which part
   of the '#if...#el...#endif' is folded.  Then folding would reflect which parts
   of the code are active.

THX & good luck
Comment 4 Torsten Eichstädt 2020-06-22 11:34:03 UTC
I forgot: keep in mind there can be multiple blocks '#if...#elif...#elif...#else...#endif' so it would be good to switch activation to the next block, then to the next etc.pp.