Recent

Author Topic: Using AI to generate fpdoc comments  (Read 254 times)

dstrenz

  • New member
  • *
  • Posts: 7
Using AI to generate fpdoc comments
« on: June 24, 2025, 02:24:34 pm »
I've got a program that's grown so much that it's hard to keep track of what everything does. So, I thought I'd add fpdoc comments to get the big picture, so I thought I'd try to use it to add fpdoc comments to a unit.

I own a paid version of jetbrains pycharm which comes with a free tier of Junie, their ai agent. Thought I'd try to use it to do the work. I didn't expect much but was surprised how good the results were. Here are the steps:

generate fpdoc comments for a pas file.
1. load a project directory in pycharm. Make sure the project is in git. Git/Commit the file you want to document so that git/diff will show only the changes junie made.
2. click on junie icon
3. click + sign to add the file to the junie query
4. enter the prompt 'generate fpdoc comments' and let 'er rip.
5. Before clicking the junie [Done] button, click the commit button on the left in pycharm, double click the file to view diff of the changes.
5. If you want to keep the changes, click the junie [Done] button, or clck [Decline] to undo them. Note that [Done] will just insert the comments in the file, i.e. it doesn't git/commit them. To commit, just do a git/commit.

It generates fpdoc comments for all types, methods, etc. for the whole file. It's pretty amazing how deep the code analysis goes. For example, here  is a function it documented:
Code: Pascal  [Select][+][-]
  1. { Converts an array of bytes into a DWORD value using Roland's data format.
  2.   @param d Array of bytes to convert. Each byte represents a 4-bit value.
  3.   @returns DWORD value converted from the input bytes.
  4.  
  5.   Input values typically range from 12768 to 52768, representing -20000 to 20000
  6.   in Roland's format. The function processes each byte as a 4-bit nibble and
  7.   combines them into a single DWORD value.
  8.  
  9.   Example:
  10.     Input bytes: [08, 00, 06, 04]
  11.     Result: Combined into single DWORD with each byte shifted and added
  12. }
  13. class function TDataInterpreter.DataToDWord(d: array of byte): DWORD;
  14. var
  15.   i : integer;
  16.   dwrd : dword;
  17. begin
  18.   dwrd := 0;
  19.   for i := 0 to length(d)-1 do
  20.     dwrd := dwrd shl 4 + d[i];
  21.   result := dwrd;
  22. end;
  23.  

That describes exactly what it does! Note that I didn't mention 'Roland' anywhere. It seems to have figured it out on its own. There is a different unit with a function named 'GetRolandChecksum'. Maybe it looked there?!


 

TinyPortal © 2005-2018