DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

[Suggestion] Add code action 'Overload' procedure #117

Closed fvet closed 3 years ago

fvet commented 3 years ago

Suppose, function with 4 arguments + code

procedure CreateAlert(pcodAlertID: Code[20]; pvarSourceRecord: Variant; ptxtMessage: Text[250]; pintPageID: Integer) AlertCreated: Boolean
    var
        // vars
    begin
         // Code starts here

I'd like to create an overload functions with a new 'AdditionalRemarks' parameter. Expected result:

procedure CreateAlert(pcodAlertID: Code[20]; pvarSourceRecord: Variant; ptxtMessage: Text[250]; pintPageID: Integer) AlertCreated: Boolean
    var
        AdditionalRemarks: list of [Text[250]];
    begin
        AlertCreated := CreateAlert(pcodAlertID, pvarSourceRecord, ptxtMessage, AdditionalRemarks, pintPageID);
    end;

    procedure CreateAlert(pcodAlertID: Code[20]; pvarSourceRecord: Variant; ptxtMessage: Text[250]; var AdditionalRemarks: List of [Text[250]]; pintPageID: Integer) AlertCreated: Boolean
     var
        // vars
    begin
         // Code starts here

The code action should:

  1. Select a line that has a procedure declaration
  2. Ask for a new procedure parameter : 'var AdditionalRemarks: List of [Text[250]]' (or ask for name / type / var)
  3. Copy the current procedure with it's current signature (without vars / without code) to respect / not break any current procedure calls, place it before the current procedure
  4. Extend the current procedure with a new parameter (at the end of the parameter list > this could be changed by the dev after running the code actions)
  5. Add a variable to the procedure (1) in case either var or a complex datatype (record, ...) had been added If we'd add a simple type (no var) like DateParameter : date, we could call the function with the init value 0D instead (to avoid warnings of the variable not being assigned, ...)
  6. Add code in the function body (1) that calls the new function (2) with all params + the newly added parameter (Mind the case where a return value is needed)

PS: Ideally, we'd run the https://github.com/DavidFeldhoff/al-codeactions/issues/116 first to have clean function parameters.


procedure CreateAlert(pcodAlertID: Code[20]; pvarSourceRecord: Variant; ptxtMessage: Text[250]; pintPageID: Integer) AlertCreated: Boolean
    var
        // vars
    begin
         // Code starts here

Copy result should be

pcodAlertID, pvarSourceRecord, ptxtMessage, pintPageID

This could already help us in calling the new procedure with the same parameters

DavidFeldhoff commented 3 years ago

Hi Frédéric, thanks for your detailed issue. I think I have to re-read this one again to get it in detail, but nevertheless I would like to briefly share my first impression after skimming the issue. Do you know the possibility to create overloads of procedures if you're calling that procedure? If you didn't know it yet, is that enough for your scenarios? https://github.com/DavidFeldhoff/al-codeactions#create-overload

fvet commented 3 years ago

Hi @DavidFeldhoff

I was not aware of the current 'Create Overload' action. My point of view was mainly starting from the function declaration itself, where yours is starting from the place where the function is called (already having the required context of new variables + datatypes). I'll give it a try and think it will cover my needs !!

Thanks ;)

DavidFeldhoff commented 3 years ago

I guess it covers your needs as I didn't hear anything again and instead you created issues for the existing functionalities, so I'll close this one. Feel free to reopen if I misinterpreted the situation.