This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226481 - Code Folds automatically un-folding
Summary: Code Folds automatically un-folding
Status: NEW
Alias: None
Product: editor
Classification: Unclassified
Component: CSL (API & infrastructure) (show other bugs)
Version: 7.3
Hardware: PC All
: P3 normal with 1 vote (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-21 21:19 UTC by wnjordan
Modified: 2016-01-18 10:39 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (333.50 KB, text/plain)
2013-02-21 21:19 UTC, wnjordan
Details
Proposed patch for PHP (5.47 KB, patch)
2013-12-03 15:24 UTC, Ondrej Brejla
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description wnjordan 2013-02-21 21:19:36 UTC
Product Version = NetBeans IDE 7.3 RC2 (Build 201302050851)
Operating System = Linux version 3.2.0-37-generic-pae running on i386
Java; VM; Vendor = 1.7.0_09
Runtime = Java HotSpot(TM) Client VM 23.5-b02

After opening a script I often go through it and manually collapse the comments that I don't need to see.  Those folded areas, while not in view, will sporadically unfold so that the next time I see them I have to fold them again.  I have not been able to determine what I'm doing at the time they unfold due to the fact that it occurs offscreen and I don't notice it until afterwards.  At first I thought I had just worked too many hours without a break and had become delirious (which is probably true too); however, I have confirmed this is happening in multiple files and not just the one that I'm working on.
Comment 1 wnjordan 2013-02-21 21:19:40 UTC
Created attachment 131696 [details]
IDE log
Comment 2 Svata Dedic 2013-02-22 07:54:00 UTC
A question: do you just view the text, or edit it ? If you edit some block structure (methods, ...) can it be possible that e.g. by typing '{' or '}', the text structure is broken, folds removed (including the one with folded comment) and then re-created ? This should happen more often to folds past the current edit position.

What file type we are talking about ?
Comment 3 wnjordan 2013-02-22 18:43:25 UTC
The type of files that I'm seeing this behavior on are php and js; however, my guess is that it's happening in all file types.

I was able to recreate this by following what you said.  I opened a document a collapsed all of the /** ... */ comments.  Then I went to an area of the script towards the top and typed /**, waited for half a second for the script below to change color and then closed it with */.  After that I checked the comments below and nearly all of them had auto expanded.

I say nearly because I have about 200 lines commented out at the bottom of the script in six separate comment sections.  In that area only three of the six unfolded - every other one.

Also, as you suggested I tried the same experiment as above using the { character and that produced the same result.  All of the comments below auto expanded in exactly the same way they did before.

The expected behavior would be that existing folds would remain folded regardless of what's happening elsewhere in the script.
Comment 4 Svata Dedic 2013-02-22 18:53:10 UTC
OK. But the question is whether the unexpected collapse you've reported was caused by remove-add (because of e.g. broken text), or by some other condition. Could you remember if you experienced the bug under different circumstances ?

As for the remove-add cycle because of e.g. unfinished comment or curly brace: it's there probably from the beginning (I am lowering the priority, this is the 1st report on this in several years), and probably applies only to JS, HTML and PHP (languages which use CSL module). Folds cannot be suppressed if the text is broken (parser reports some errors), because there are many errors which do not break the overall structure of the source.

First I'll probably need to define a way for the language implementors how to report severe errors, so folds are not updated to the inconsistent state.
Next, it would be probably a good idea, to allow for 'handles' for folds, identified by language's constructs, like method/function (qualified) names. Even a documentation comment preceding a method (function) could be identified as 'comment-for-method-foo'. This could help to retain state when a fold is revived after recovering from a broken source.
Comment 5 Svata Dedic 2013-02-22 19:15:06 UTC
Oh, something could be done more quickly.

Javascript & PHP gurus - could you please report such issues as unfinished comments or program blocks (broken structure of the source) at severity FATAL ? This will block fold updates (I hope that no other feature is affected, at least CSL does not check FATAL in more places)
Thanks.

This however does not fix unfinished /** comment, as it effectively comments the next portion of text up to the nearest */ without any error. The other approaches I've described should be used.
Comment 6 Svata Dedic 2013-03-21 10:08:32 UTC
Please evaluate the possibility to report missing } (i.e. unexpected end of file etc) at FATAL severity, so code folds don't update (= would be removed ?)
Comment 7 Ondrej Brejla 2013-12-03 15:23:10 UTC
Svato if I try to add a "FATAL" error to parser result, it fails on NPE in spi.editor.hints ErrorDescriptionFactory, because there is no mapping for FATAL severity in GsfHintsProvider:125...
Comment 8 Ondrej Brejla 2013-12-03 15:23:50 UTC
Svato look at my last comment #7, thanks ;)
Comment 9 Ondrej Brejla 2013-12-03 15:24:57 UTC
Created attachment 142820 [details]
Proposed patch for PHP

It has to be tested, it's just a compilable proposal.
Comment 10 tomcon 2014-04-15 10:07:03 UTC
Something I just found that was significant for me personally:

if you have comments like this 
`<!-------- ------>`

i.e. *more than just 2 dashes* `<!-- -->` then netbeans seems to get confused. 

Remove the extra dashes and code folding works normally again.
Comment 11 Byson 2015-10-05 12:18:57 UTC
What's the status of this? After Svata Dedic's comments in December 2013 it seemed like this was about to be solved, but as of right now, with Netbeans 8.0.2 I can still report that typing a "{" (e.g. when typing an if-statement) will still unfold all code below that.

In fact, simply starting to write `if (1 == 1` already unfolds everything below it.
This really should be given high priority, seeing as that this basically makes the entire folding mechanic useless.
Comment 12 Byson 2015-11-27 15:20:47 UTC
I have updated the affected version to 8.0.2 as I can confirm this is still broken.

If I can be of assistance in any way please do let me know, I encounter this consistently enough that I don't mind spending some time helping to fix or test it.
Comment 13 Svata Dedic 2015-11-27 15:26:43 UTC
Please - do not change the Version field upwards; it should record the first version the bug appeared. Until the bug closes, it is assumed it is present in all subsequent versions.
Comment 14 Byson 2015-11-30 14:39:02 UTC
My apologies, I was unaware of that.
Comment 15 Byson 2016-01-18 10:39:47 UTC
Is anyone actually planning to fix this? It's been reported 2 years ago, and a proposed patch has been added 1.5 years ago, but since then there has been no indication whatsoever that anyone is planning to fix this for an upcoming release.

It really does have quite an impact, since the entire folding mechanic is basically useless if typing one line of code unfolds everything.

I don't mean to put pressure on anyone, I just get the feeling no one has really taken note, so it will still be broken 2 years from now.