Author Topic: SynEdit - Add support code folding for Java  (Read 7589 times)


  • New Member
  • *
  • Posts: 47
SynEdit - Add support code folding for Java
« on: August 29, 2009, 10:48:32 am »

I try add code folding support for SynHighlighterJava unit for submit after to Lazarus project.
I have a very big problem.
When your enter brace ({ or }), it's calling many times but TSynJavaSynRange(CodeFoldRange).CodeFoldStackSize are not reinit beetwen call.
Thus, for same open brace it add 3 or more open node.

If you test SynHighlighterPas, we have not problem.

Somebody know what is the problem ?

I've attach my file.
All my modifications are surrounded by Add emeric / End add emeric

Another stange behavior, if I had code foldind support in comment (/* */), I've not the problème but, close node is always on the line after.
Example :
/* -> open node
[empty] -> close node
*/ -> nothing

Thank you for your help

I use Lazarus 0.9.26-2
« Last Edit: August 29, 2009, 11:05:20 am by bubulemaster »


  • Administrator
  • Hero Member
  • *
  • Posts: 7985
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit - Add support code folding for Java
« Reply #1 on: August 29, 2009, 01:36:23 pm »
I would recommend to use the latest SVN, otherwise it is more than likely your code will stop working when you upgrade.

In SVN there is a special base class for fold-highlighter: TSynCustomFoldHighlighter

You want to look at the procedure SetLine in TSynCustomFoldHighlighter and TSynPasSyn (the pascal highlighter). Maybe also SetRange / ResetRange.
But ignore all LevelIfDef* / LevelRegion* => the pascal highlighter keeps 3 different set of counters (all using the same logic). This is because ifdef/region can overlap each other.

Important is that you re-initialize all the fold levels for the line. A line may get scanned more than once, if you do not reset the level, then your results will increase (as you have it).

There are 2 important counters:
* FoldEndLevel: Level at the end of line (equals start of next line)
* FoldMinLevel: Minimum level on this line. This can be lower than the start/end level. See example:
  begin       // endlevel = 1 ; minlevel = 0
  end  begin // endlevel = 1 ; minlevel = 0
  end         // endlevel = 0 ; minlevel = 0

LastLineFix will not be needed. it is used where a keyword closes a block. but the close ought to be in the last line (fold-able car/type sections)
     a=integer;  // the fold ends with this line
  var               // but it is only known, when parsing the "var"

Let me know if you have any specific questions.


  • New Member
  • *
  • Posts: 47
Re: SynEdit - Add support code folding for Java
« Reply #2 on: August 30, 2009, 12:15:49 pm »
Ok, I'm tryng last SVN version but, first I finished my SynEdit documentation

Thank you
« Last Edit: August 30, 2009, 12:34:32 pm by bubulemaster »


TinyPortal © 2005-2018