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:
{ Converts an array of bytes into a DWORD value using Roland's data format.
@param d Array of bytes to convert. Each byte represents a 4-bit value.
@returns DWORD value converted from the input bytes.
Input values typically range from 12768 to 52768, representing -20000 to 20000
in Roland's format. The function processes each byte as a 4-bit nibble and
combines them into a single DWORD value.
Example:
Input bytes: [08, 00, 06, 04]
Result: Combined into single DWORD with each byte shifted and added
}
class function TDataInterpreter.DataToDWord(d: array of byte): DWORD;
var
i : integer;
dwrd : dword;
begin
dwrd := 0;
for i := 0 to length(d)-1 do
dwrd := dwrd shl 4 + d[i];
result := dwrd;
end;
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?!