davidfeldhoff / al-codeactions Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
If I create a new procedure inside the same file it should be local.
Currently each created procedure is global.
The change of 0.2.10 "Procedures are now placed before the global var section if there is no procedure in the file yet." violates the best practice guide:
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/compliance/apptest-bestpracticesforalcode#file-structure
procedure MyFunction()
var
MyCode5Variable: Code[5];
begin
MyCode5Variable := MyNewFunction('CCCCC'); // missing
end;
"Create procedure":
Currently:
local procedure MyNewFunction(arg: Text): Variant
begin
Error('Procedure not implemented.');
end;
Expected:
local procedure MyNewFunction(arg: Text): Code[5]
begin
Error('Procedure not implemented.');
end;
That would be great :)
Hi,
A new quick fix to generate the body of CU that implements an interface (with all procedures). In my current project, I have already 6 interfaces for enums and this is one of the things that I really miss
Codeactions are not created for procedures that contain parameters which contain closing brackets in their option strings. Example:
procedure CreateObject(PosPrinter: Option " ","TM-T88R"; LineDisplay: Option " ","DM-D101","IBM VFD (serielle Direktverbindung)")
begin
...
end;
There should be a possibility to extract a few selected lines to a new procedure.
The variables and parameters needed should be identified automatically.
If I use an affix for event signatures in table extensions (e.g. XXX_OnBeforeDoSomething), I don't receive the quickfix for creating an event.
Maybe it is possible to check for the Affix in the AppSourceCop.json?
At the moment i solved this problem for me by using a suffix. (OnBeforeDoSomething_XXX)
What do you think about that?
I would suggest this little thing, give procedure name in error by default.
local procedure ProcedureName()
begin
Error('Procedure ProcedureName not implemented.');
end;
When extracting a function it nicely includes local variables from its original parenting function in the newly created procedure.
But unfortunately it leaves it declaration behind if it's no longer used there.
Can this be fixed?
If I try to create a procedure which has another (already existing) procedure call as parameter which has mulitple parameters itself, then the procedure which is going to be created will have two parameters - in this example. Not one.
My suggestions are based on my personal need only; probably they should be controlled by settings instead:
[IntegrationEvent(false, false)]
Local variables and parameters are handed over as parameter to the extracted procedure - That's fine. But the return variable is not, so it is unknown in the extracted procedure.
The creation of eventsubscirbers (possible if procedure starts with "On..") works fine if it's in the same file, but as far as there's a different table, e.g. Customer.OnDoSomething, a normal procedure is created.
Not using Page.RunModal(0, Rec) but use the Page Management Codeunit instead.
The same goes for: Not using a CONFIRM() but using Confirmation Management
Requested by Erik on Twitter
https://twitter.com/eHougaard/status/1308879940075565057
If the creatable procedure is in an if statement then it won't be created.
The "Unable to get position to insert the procedure" error seems to be back again
(#70)
"AZ AL Dev Tools/AL Code Outline" v2.0.8
"AL CodeActions" v0.2.14
VSCode v1.47.3
AL Language v3.0.106655
I get the error, when I try to run the "Create Procedure OnTestSomething" action in the following example:
codeunit 50000 "Test"
{
trigger OnRun()
var
A: Text;
B: Integer;
OK: Boolean;
begin
OK := OnTestSomething(A, B);
end;
var
myInt: Integer;
}
Thanks.
Hi David,
would it be possible to extend the functionality a bit to also create a procedure in the Source Table of a Page?
When I am in a custom page, I would like to have the business logic in my custom table instead of the page.
Maybe by adding a second option "Create Procedure 'XYZ' in Table 'CustomTable'"?
Not sure if that is too complicated, but I had two cases where I needed that :-)
In a test codeunit, create the following procedure:
local procedure AssertMyFunction_True(MyText: Text)
var
Assert: Codeunit Assert;
begin
Assert.IsTrue(MyFunction(MyText), '');
end;
Run the quick fix on MyFunction. Actual result:
local procedure MyFunction(MyText: Text)
begin
Error('Procedure MyFunction not implemented.');
end;
Expected result:
local procedure MyFunction(MyText: Text) : Boolean
begin
Error('Procedure MyFunction not implemented.');
end;
Currently a quoted type is missing the quotes, e.g. a "Sales Order" parameter is inserted as
SalesOrder: Page Sales Order
which is a compiler issue
I am having the following issue. When i have a procedure call which return value is written to a variable everything is working as expected:
procedure GetReceivedFlag(var rData: Text): Boolean
var
lOk: Boolean;
begin
lOk := GetReceivedFlagRemote(rData);
exit(lOk);
end;
Creates
local procedure GetReceivedFlagRemote(var rData: Text): Boolean
begin
Error('Procedure GetReceivedFlagRemote not implemented.');
end;
But when writing it into an one liner the return value is missing:
procedure GetReceivedFlag(var rData: Text): Boolean
begin
exit(GetReceivedFlagRemote(rData));
end;
Creates:
local procedure GetReceivedFlagRemote(var rData: Text)
begin
Error('Procedure GetReceivedFlagRemote not implemented.');
end;
Hi David,
Creating a new procedure for
MyFunction(Database::"Sales Header");
or
MyFunction(Page::"Sales Order");
etc.
returns
local procedure MyFunction(arg: Variant)
begin
Error('Procedure MyFunction not implemented.');
end;
instead of
local procedure MyFunction(i: Integer)
begin
Error('Procedure MyFunction not implemented.');
end;
Reported by Erik Hougard
Extract procedure cannot figure out variables that are defined as:
d,m,y : Integer;
The new allowed syntax in 5.0
Hi David,
when I create a procedure from a page or table where I have an implicit "Rec", I sometimes want to pass this variable into a new procedure. For example in this PageAction I would like to create the new procedure "CreateOrderFromWebshopOrder".
The new procedure will have a parameter "Rec: Record "Webshop Sales Header WEB11 CCO".
Would it be possible to automatically rename this parameter Rec by using the object name?
Instead of "Rec: Record "Webshop Sales Header WEB11 CCO"----
...this? WebshopSalesHeader: Record "Webshop Sales Header WEB11 CCO"
Basically by using the same functionality that is already implemented in the AL Variable Helper when you create a new record:
But maybe I am the only one who would like to have that :-D
Sorry if I've overlooked it somehwere:
Create the following code line:
MyNewProcedure(Enum::"Sales Document Type"::Order);
and run code action "Create Procedure".
Result:
local procedure MyNewProcedure(Enum: Enum)
begin
Error('Procedure MyNewProcedure not implemented.');
end;
Expected:
local procedure MyNewProcedure(SalesDocumentType: Enum "Sales Document Type")
begin
Error('Procedure MyNewProcedure not implemented.');
end;
For a quick test, please use this very stupid code:
if not (1 in [2, 3]) then begin
end;
Imagine, you would like to extract the "complicated" expression into a procedure.
If you mark everything from (
to )
, then the code action won't be not provided:
It will be provided only if you mark the leading space:
Bug or feature?
Not sure if feasible, but would it be possible to select a large chunk of code, then have a Code Action that replaces any
Rec.Field := [something];
With
Rec.Validate(Field,[something]);
When using the 'Create procedure' functionality with variables that for example contain german special characters, then the character is removed from the created parameter.
How to reproduce:
Create a new Codeunit
codeunit 99952 Test
{
procedure MyProcedure()
var
Länge: Integer;
begin
MySecondProcedure(Länge);
end;
}
Now use 'Create Procedure' on the reference to MySecondProcedure.
That creates this:
codeunit 99952 Test
{
procedure MyProcedure()
var
Länge: Integer;
begin
MySecondProcedure(Länge);
end;
local procedure MySecondProcedure(Lnge: Integer)
begin
Error('Procedure MySecondProcedure not implemented.');
end;
}
expected:
codeunit 99952 Test
{
procedure MyProcedure()
var
Länge: Integer;
begin
MySecondProcedure(Länge);
end;
local procedure MySecondProcedure(Länge: Integer)
begin
Error('Procedure MySecondProcedure not implemented.');
end;
}
Hi David,
would it be possible to add a new Functionality "Insert all missing parenthesis" similiar to your function "Remove all With-usages"?
I would try to do it myself, but I figured it would be way easier for you as you probably already know how to do that :-)
I think it could be usefult to add Result parameters as var to automatically created events:
procedure TestSomething(Input: Integer) Result: Boolean
var
IsHandled: Boolean;
begin
IsHandled := false;
OnCheckSomething(Input, Result, IsHandled)
end;
This would result in the following Event:
[IntegrationEvent(false, false)]
local procedure OnCheckSomething(Input: Integer; var Result: Boolean; IsHandled: Boolean)
begin
end;
At the moment Result
is added without var
.
Then I only have to change the IsHandled
parameter manually to var
.
In the case of an interface there shouldn't be a body
If there's a string literal it would be nice if the literal could be declared as a label.
If the procedure to create is a parameter of another (existing) procedure call then it is not possible to create that one.
If the selection which should be extracted is inside a begin..end
Block, then variables which are assigned before this block aren't passed to the extracted procedure as parameter. Instead they are just normal variables.
Example:
local procedure MyProcedure()
var
MyInt: Integer;
SalesLine: Record "Sales Line";
begin
MyInt := 5;
if true then begin
SalesLine.SetRange("Document Type", "Sales Document Type"::Order);
if SalesLine.FindSet(true) then begin
SalesLine.Quantity := MyInt;
SalesLine.Modify();
end;
end;
end;
results in
local procedure MyProcedure()
var
MyInt: Integer;
SalesLine: Record "Sales Line";
begin
MyInt := 5;
if true then begin
ExtractedProcedure();
end;
end;
local procedure ExtractedProcedure()
var
MyInt: Integer;
SalesLine: Record "Sales Line";
begin
SalesLine.SetRange("Document Type", "Sales Document Type"::Order);
if SalesLine.FindSet(true) then begin
SalesLine.Quantity := MyInt;
SalesLine.Modify();
end;
end;
I've just added a field to a page. The value is returned by a (still missing) function/method CalcValue:
field("My Page Field Name"; CalcValue())
{
}
When I run "Create Procedure" on CalcValue, it has no return value:
local procedure CalcValue()
begin
Error('Procedure CalcValue not implemented.');
end;
I am aware that you cannot know which return data type to expect.
Nevertheless, could a dummy data type, e.g. text, be added?
Example:
local procedure CalcValue() ReturnVariable : Text
begin
// Please update the ReturnVariable data type and name
Error('Procedure CalcValue not implemented.');
end;
I recieve the error:
Unable to get the position to insert the procedure
ERR Invalid arguments: Error: Invalid arguments
at new e (c:\Users\asdf\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:438:373)
at new e (c:\Users\asdf\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:434:44)
at asRange (c:\Users\asdf\.vscode\extensions\microsoft.al-3.0.268718\node_modules\vscode-languageclient\lib\protocolConverter.js:59:16)
at asCodeLens (c:\Users\asdf\.vscode\extensions\microsoft.al-3.0.268718\node_modules\vscode-languageclient\lib\protocolConverter.js:472:53)
I don't what causes this error. Mabe runtime 3.2?
I recieved this error while for every inseriton method (procedure, integration/business event)
I suggest an error handling that I get the action on this notification to copy the event to clipboard. Then I could insert the event manually, als long as this error might occur.
We love your functionality to automatically create missing Eventpublishers. Having the var keyword on all variables would make it even more useful. If this is not suitable for everyone we would suggest to at least add them to variables called "IsHandled" and "ReturnValue".
I don't know if your extensions is the right point to share my idea.
So please do what you want with it.
Have you thought about an QuickFix for adding missing Permissions to Codeunits or Reports?
After the annoying CodeCop AL0214 there might be the information about which Records/Table are used (Read, Insert, Modify, Delete) inside this object.
I would really love a QuickFix that would add the minimum required (indirect) permissions.
Imagine a function like this:
local procedure JustATest()
var
SalesLine: Record "Sales Line";
begin
MyNewFunction(SalesLine."Document Type"::Order); // <--- new procedure
end;
SalesLine."Document Type" is an enum since BC 16.
When a use function "Create procedure", you will get:
local procedure MyNewFunction(arg: Variant)
begin
Error('Procedure not implemented.');
end;
I expect:
local procedure MyNewFunction(SalesDocumentType: Enum "Sales Document Type")
begin
Error('Procedure not implemented.');
end;
Is that possible?
An enum-object does not support a procedure, but the codeaction is also active there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.