Recent

Author Topic: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}  (Read 111429 times)

Pascal

  • Hero Member
  • *****
  • Posts: 832
It seems that Highlighter.EndLine() does not work correct for "for" "while" "if" "do".
If theese keywords are alone on a line Endline() is 0!
TSynFoldNodeInfo.FoldLvlStart and FoldLvlEnd are always the same for this lines. FoldLvlEnd should be one higher than FoldLvlStart!
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Code: Pascal  [Select]
  1. function TSynPasSyn.FoldEndLine(ALineIndex, FoldIndex: Integer): integer;
  2. var
  3.   lvl, cnt, atype : Integer;
  4.   node: TSynFoldNodeInfo;
  5. begin
  6.   node := FoldNodeInfo[ALineIndex].NodeInfoEx(FoldIndex, [sfaOpenFold, sfaFold]);
  7.   if sfaInvalid in node.FoldAction then exit(-1); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This causes EndLine to be 0 (ToPos(-1) = 0)
  8.   if sfaOneLineOpen in node.FoldAction then exit(ALineIndex);
  9.   case TPascalCodeFoldBlockType(PtrUInt(node.FoldType)) of
  10.     cfbtRegion:
  11.       atype := 2;
  12.     cfbtIfDef:
  13.       atype := 3;
  14.    .
  15.    .
  16.    .                                                              

EndLine does not work for nodes which have no real folding.

I added a patch to use the endline of the next outer node with real folding until this is fixed by martin_fr.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

x2nie

  • Sr. Member
  • ****
  • Posts: 478
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #242 on: September 02, 2016, 09:09:29 am »
x2nie,

did you test the patch?


I have had big problem running my app demo that uses synedit+SynEditMarkupFoldColoring.pas, something has been changed somewhere in months.
But I found the bugfix. The problem is in my demo app (that earlier works):


Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.    M : TSynEditMarkupFoldColors;
  4.    S : TSynEdit;
  5. begin
  6.    s := SynEdit1;
  7.    s.Highlighter := nil;   // my original markupcoloring unit doesn't require this
  8.    M := TSynEditMarkupFoldColors.Create(s);
  9.    s.MarkupManager.AddMarkUp(M);
  10.    s.Highlighter := SynFreePascalSyn1; // so this reseting doesn't required by my original markupcoloring unit.
  11. end;
  12.  




Interesting to see in SynEditMarkupFoldColoring, that the error occurred from this line:

  NestCount := FNestList.Count;


that forwarding to:

function TLazSynEditNestedFoldsList.Count: Integer;
begin
  if (FCount < 0) then begin
    InitCount;
  end;
  if FIncludeOpeningOnLine and (FOpeningOnLineCount < 0) then begin
    InitOpeningOnLine;
  end;


  Result := FCount + OpeningOnLineCount;
end;


and finally this triggering error on:

procedure TLazSynEditNestedFoldsList.InitCount;
begin
  if FHighLighter = nil then exit;
  FHighLighter.CurrentLines := FLines;


  FCount := FHighlighter.FoldBlockEndLevel(FLine - 1, FFoldGroup, FFoldFlags); <-------------------- Why it is needed on InitCount ????
  FEvaluationIndex := FCount;
  SetLength(FNestInfo, FCount+1);
end;

which is end up with this line:
Code: Pascal  [Select]
  1. function TSynPasSyn.FoldBlockEndLevel(ALineIndex: TLineIdx;
  2.   const AFilter: TSynFoldBlockFilter): integer;
  3. var
  4.   inf: TSynPasRangeInfo;
  5.   r, r2: Pointer;
  6. begin
  7.   Assert(CurrentRanges <> nil, 'TSynCustomFoldHighlighter.FoldBlockEndLevel requires CurrentRanges');      
  8.  

However, we can make next progress.
Thanks @Pascal !
« Last Edit: September 02, 2016, 09:13:00 am by x2nie »
When you were logged in, you can see attachments.
Lazarus Trunk @ Windows7 64bit, XP 32bit, Debian under VirtualMachine

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #243 on: September 02, 2016, 03:15:16 pm »
I have had big problem running my app demo that uses synedit+SynEditMarkupFoldColoring.pas, something has been changed somewhere in months.
But I found the bugfix. The problem is in my demo app (that earlier works):


Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.    M : TSynEditMarkupFoldColors;
  4.    S : TSynEdit;
  5. begin
  6.    s := SynEdit1;
  7.    s.Highlighter := nil;   // my original markupcoloring unit doesn't require this
  8.    M := TSynEditMarkupFoldColors.Create(s);
  9.    s.MarkupManager.AddMarkUp(M);
  10.    s.Highlighter := SynFreePascalSyn1; // so this reseting doesn't required by my original markupcoloring unit.
  11. end;
  12.  

I will investigate this. Should work without setting highlighter to nil and back to SynFreePascalSyn1.

Thanks @Pascal !

You are welcome!
Was just self-interest!
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #244 on: September 06, 2016, 05:51:40 am »
I will investigate this. Should work without setting highlighter to nil and back to SynFreePascalSyn1.
I found the problem: SetLines does not recreate FNestList.
Fixed. Try latest patch.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #245 on: September 10, 2016, 02:33:20 pm »

I have had big problem running my app demo that uses synedit+SynEditMarkupFoldColoring.pas, something has been changed somewhere in months.
But I found the bugfix. The problem is in my demo app (that earlier works):


Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.    M : TSynEditMarkupFoldColors;
  4.    S : TSynEdit;
  5. begin
  6.    s := SynEdit1;
  7.    s.Highlighter := nil;   // my original markupcoloring unit doesn't require this
  8.    M := TSynEditMarkupFoldColors.Create(s);
  9.    s.MarkupManager.AddMarkUp(M);
  10.    s.Highlighter := SynFreePascalSyn1; // so this reseting doesn't required by my original markupcoloring unit.
  11. end;
  12.  


Interesting to see in SynEditMarkupFoldColoring, that the error occurred from this line:

  NestCount := FNestList.Count;

From a quick look (not sure if your version, or some patched / older), I can not see where the HL for nestlist if updated, if it changed in synedit.

---
EDIT: I see Pascal found it...
« Last Edit: September 10, 2016, 02:34:51 pm by Martin_fr »

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #246 on: September 12, 2016, 09:11:14 am »
Martin_fr, did you read reply #240 and #241?
TSynPasSyn.FoldEndLine() does not work for "while" "do" "if" "for".
Is there a chance to get it work? At the moment i will use the next outer fold which has real folding to find
the endline for invalidation.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #247 on: September 15, 2016, 10:22:17 pm »
Do you test with
Code: Pascal  [Select]
  1. -Criot -gt -gh  -dSynAssert  -dSynAssertFold
  2.  
Because I get a lot of range check errors...

I added code for finding the end line.
Though I only tested with normal folds, not with if/for/do/...
But it should work for them to.

TLazSynEditNestedFoldsList has now a property NodeEndLine
Code: Pascal  [Select]
  1. NestList.NodeEndLine[i]
should give you the correct (0 based) endline.

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #248 on: September 16, 2016, 12:10:02 pm »
Do you test with
Code: Pascal  [Select]
  1. -Criot -gt -gh  -dSynAssert  -dSynAssertFold
  2.  
No, i didn't before. But with this options i do not get any errors, neither in my testprogramm nor in the ide.
Did you use the latest patch?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #249 on: September 16, 2016, 12:51:27 pm »
patch_v10

Maybe it is, because I used the IDE config (see my patch), and I outline only some, but not all keywords.

I will investigate that later.

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #250 on: September 16, 2016, 12:55:14 pm »
I also use your patch for Outline-Config
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #251 on: September 16, 2016, 01:03:05 pm »
If i disable some keyword for outlining i also get errors.
How can i configure some keywords to not be outlined in a test programm?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5706
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #252 on: September 16, 2016, 01:17:27 pm »
If i disable some keyword for outlining i also get errors.
How can i configure some keywords to not be outlined in a test programm?

Code: Pascal  [Select]
  1.   for i := 0 to HL.FoldConfigCount-1 do begin
  2.     HL.FoldConfig[i].Enabled := ...;
  3.     HL.FoldConfig[i].Modes := ... [fmMarkup, fmFold, fmHide, fmOutline]; // or  subsets..... (some modes may not work on some conf)
  4.   end;
  5.   // or HL.FoldConfig[ord(cfbtBeginEnd)]
  6.  

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #253 on: September 16, 2016, 01:27:36 pm »
I'vefound the bug.

It seems that DoTextChanged gets called with StartLine and Endline as indeces when configuration is saved.
I've added a workaround http://bugs.freepascal.org/file_download.php?file_id=25036&type=bug

By the way: If i disable "Outline (global)" i can not set "Outline" for the individual keyword as it is disabled.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #254 on: September 16, 2016, 01:43:19 pm »
The cause was a wrong call of TextChanged with a StartLine of 0 which is wrong as StartLine is not meant to be an index.

See attached patch.

So you can forget about patch 11  :D
« Last Edit: September 16, 2016, 01:50:55 pm by Pascal »
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)