[Needs work] Problem with Jedi Code Format lazarus / 9-Editor ---------------------------------------------------------------------- BrunoK · 2022-09-30 16:50 Lazarus >= 2.2 Could someone test the formatting of the following code with Ctrl+D on selected lines 15 to 17. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit2; { JCF code formatting } {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils; // implementation // Comment out of this line damages formatting of                  // following selection procedure ini_dummy;  // In the editor, Select from this linebeginend;                  // to this line then Ctrl+D (JCF) locally on the selection                      // -> the  procedure ini_dummy; line 15 disappearsend. I ask because, either I may have made a mistake while adding "features ..." to my JCF, or the problem is in the releases and some bug correction should be envisaged. ---------------------------------------------------------------------- dseligo · 2022-09-30 19:53 I tried in Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 x86_64-win64-win32/win64. Line 18 is deleted, this one: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                     // -> the  procedure ini_dummy; line 15 disappears ---------------------------------------------------------------------- ASerge · 2022-10-01 00:50 Quote from: dseligo on September 30, 2022, 09:53:25 pmI tried in Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 x86_64-win64-win32/win64. Line 18 is deleted, this one: Same thing in version 2.2.4. ---------------------------------------------------------------------- Bogen85 · 2022-10-01 04:21 When I try to parse the whole file I get (yeah, to be expected per the comment in the code...): Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ./lazforum/60771/Unit2.pas(16,5) Error Exception TEParseError  Unexpected token, expected "IMPLEMENTATION"Near BEGIN As far as Lazarus version, I don't use the IDE, but I do use "Jedi Code Format" JCF from the command line (which is in the Lazarus sources). I'm using JCF built from Lazarus gitlab main. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ cat ide/revision.inc// Created by Svn2RevisionIncconst RevisionStr = 'main-2_3-2072-gdd3cb67d40'; When I add the missing implementation I get: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit2; { JCF code formatting }     {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils; implementation // Comment out of this line damages formatting of // following selection procedure ini_dummy;  // In the editor, Select from this line  begin  end;                  // to this line then Ctrl+D (JCF) locally on the selection // -> the  procedure ini_dummy; line 15 disappearsend. Granted, I don't have my settings tuned for comment alignment, and I do have my settings to remove blank lines... But I don't see that it removed lines? Or am I missing some from the original post on this topic? ---------------------------------------------------------------------- ASerge · 2022-10-01 05:52 Quote from: Bogen85 on October 01, 2022, 06:21:07 amOr am I missing some from the original post on this topic? Yes: "...with Ctrl+D on selected lines 15 to 17". ---------------------------------------------------------------------- Bogen85 · 2022-10-01 06:16 Quote from: ASerge on October 01, 2022, 07:52:04 amQuote from: Bogen85 on October 01, 2022, 06:21:07 amOr am I missing some from the original post on this topic? Yes: "...with Ctrl+D on selected lines 15 to 17". Ok... I don't run the GUI so I don't know how is going to work on lines where it can't parse the whole file... (since the whole file in question can't be parsed with interface commented out...) ---------------------------------------------------------------------- BrunoK · 2022-10-01 08:30 @dseligo, @ASerge Thanks for the replies. Will see if something can be done while updating my "features...". ---------------------------------------------------------------------- DomingoGP · 2022-10-01 14:10 Yes its a bug. While I was looking to fix this bug, I found that JCF leaks memory when it finds errors in the code to be formatted. I have a patch almost ready that I will send to the issue tracker when it is ready and then I will send another one fixing this problem. In the meantime if anyone wants to fix this bug here are the changes to fix it (patch copied from TortoiseSVN not sure if it can be applied directly). The final patch will probably not be identical, I will move the StrTrimLastEof function to jcfStringUtils. Regards Domingo Code: [Select]diff --git a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas index 3c151210ff..e79940a621 100644 --- a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas +++ b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas @@ -230,6 +230,26 @@ begin    LazarusIDE.DoOpenIDEOptions(TfFiles);  end; +function StrTrimLastEndOfLine(const aStr:string):string; +var +  len:integer; +  c:char; +begin +  len:=length(aStr); +  // TRIM right spaces +  //  while (len>0) and (aStr[len]=' ') do +  //    dec(len); +  if (len>0) and (aStr[len]=#10) then +  begin +    dec(len); +    if (len>0) and (aStr[len]=#13) then +      dec(len); +    result:=Copy(aStr,1,len); +  end +  else +    result:=aStr; +end; +  procedure TJcfIdeMain.DoFormatSelection(Sender: TObject);  var    srcEditor: TSourceEditorInterface; @@ -252,7 +272,7 @@ var    BlockBegin, BlockEnd: TPoint;    fcConverter: TConverter;    lineStartOffset,lineEndOffset: integer; -  wi: integer; +  wi,EndY: integer;    outputstr: string;  begin    if (SourceEditorManagerIntf = nil) or (SourceEditorManagerIntf.ActiveEditor = nil) then @@ -278,6 +298,7 @@ begin        while (wI > 1) and (fcConverter.OutputCode[wI] in [#10, #13, ' ']) do          Dec(wI);        outputstr := Copy(fcConverter.OutputCode, 1, wI); +//ShowMessage('['+outputstr+']'+IntToStr(BlockBegin.Y)+'  '+IntToStr(BlockEnd.Y));        DiffMergeEditor(srcEditor,outputstr,BlockBegin.Y,BlockEnd.Y);      end      else @@ -286,15 +307,25 @@ begin        BlockBegin := srcEditor.BlockBegin;        BlockBegin.X := 1;     // full lines.        BlockEnd := srcEditor.BlockEnd; +      EndY:=BlockEnd.Y;        if BlockEnd.X > 1 then -        BlockEnd.Y := BlockEnd.Y + 1; +        BlockEnd.Y := BlockEnd.Y + 1 +      else +      begin +        if EndY>1 then +          EndY:=EndY-1; +      end;        BlockEnd.X := 1;        srcEditor.SelectText(BlockBegin, BlockEnd); //extend selection to full lines.        fcConverter.InputCode := srcEditor.GetText(True);  // only selected text.        fcConverter.GuiMessages := true;        fcConverter.ConvertUsingFakeUnit;        if not fcConverter.ConvertError then -        DiffMergeEditor(srcEditor,fcConverter.OutputCode,BlockBegin.Y ,BlockEnd.Y); +      begin +        outputstr:=StrTrimLastEndOfLine(fcConverter.OutputCode); +//ShowMessage('['+outputstr+']'+IntToStr(BlockBegin.Y)+'  '+IntToStr(EndY)); +        DiffMergeEditor(srcEditor,outputstr,BlockBegin.Y,EndY); +      end;      end;    finally      fcConverter.Free; ---------------------------------------------------------------------- Thaddy · 2022-10-01 17:04 JCF? only if you use the Lazarus IDE. ---------------------------------------------------------------------- Bogen85 · 2022-10-01 17:44 Quote from: Thaddy on October 01, 2022, 07:04:46 pmJCF? only if you use the Lazarus IDE. Not sure what you mean. I use JCF from the command line. The command line project for JCF is in the Lazarus distribution. ---------------------------------------------------------------------- DomingoGP · 2022-10-01 18:55 QuoteJCF? only if you use the Lazarus IDE. Memory leaks both command line JCF and IDE. Format selection bug only the IDE, the command line only formats the whole files.