Check out my review of the awesome addition to Visual Studio Code to help with AL development, AL CodeActions:
This is the work of https://twitter.com/FeldhoffDavid
In this video, Erik takes a look at a Visual Studio Code extension called AL Code Actions, created by David Feldhoff. This extension enhances the AL development experience in Business Central by adding powerful code generation and refactoring capabilities that many developers are already familiar with from other languages like C#.
Why AL Code Actions?
Visual Studio Code is fundamentally just an editor — its real power comes from extensions. While Microsoft provides the AL compiler extension, community members like David Feldhoff have built tools that make the development experience even better. Erik believes AL Code Actions deserves more recognition than it currently has, and it’s a tool he uses all the time in his workflow.
Feature 1: Generate Procedures from Usage
One of the most valuable features — and something Erik had been missing from his C# days — is the ability to write a procedure call before the procedure exists, and then have the extension generate it for you.
For example, say you’re writing code and you want to call a procedure called GenerateAwesomeMessage that doesn’t exist yet:
trigger OnOpenPage();
begin
Message(GenerateAwesomeMessage(TODAY()));
end;
At this point, GenerateAwesomeMessage doesn’t exist and the compiler will flag an error. But with AL Code Actions installed, you’ll see a “Show Fixes” option appear. Clicking it gives you the ability to generate the procedure automatically.
What’s impressive is how intelligent the generation is. The extension analyzes the context of your call:
- Because the result is passed to the
Messagefunction (which expectsText), it sets the return type toText. - Because
TODAY()is passed as a parameter, it creates a parameter of typeDate.
The result is a properly typed procedure stub that you can immediately start filling in with your logic.
Feature 2: Extract Procedure (Refactoring)
The second major feature Erik demonstrates is the ability to extract a block of code into its own procedure. This is a classic refactoring operation that makes code cleaner and more maintainable.
Starting with some code inside a procedure (nonsensical in this demo, but the principle applies to any real code), you can select a block of lines, invoke the code action, choose “Extract Procedure,” and give it a name. Here’s the final result after Erik’s demonstration:
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
begin
Message(GenerateAwesomeMessage(TODAY()));
end;
local procedure GenerateAwesomeMessage(T: Date): Text
var
d: Integer;
m: Integer;
y: Integer;
begin
d := 3;
m := 4;
y := 5;
newProcedure(d, m);
end;
local procedure newProcedure(var d: Integer; var m: Integer): Text
begin
for d := m to m * 5 do begin
for m := d to d * 5 do begin
if d = m then
exit('Test!!!');
end;
end;
end;
}
Smart Variable Analysis
The extract procedure feature is remarkably smart about variables. When you select a block of code to extract, the extension analyzes which variables are actually used in the selected code and passes only those as parameters. Variables that aren’t referenced in the selection are left out entirely.
In the example above, d and m are used in the extracted code, so they become parameters. The variable y, which isn’t used in the extracted block, is not included — keeping the new procedure’s signature clean and minimal.
A Note on Pass-by-Reference vs. Pass-by-Value
By default, the extracted parameters are passed by reference (using the var keyword). This ensures that any modifications to d and m inside the new procedure are reflected back in the calling procedure — maintaining the same behavior as before the extraction.
However, Erik notes that if you prefer a more functional programming approach (which he typically does), you might want to change these to pass-by-value and use return values instead. That’s a manual adjustment, but the extension gives you a solid starting point.
Additional Features
Erik briefly mentions that AL Code Actions also helps with handler function definitions — particularly useful because the standard Go to Definition (F12) and Find All References (Shift+F12) don’t currently work for handler functions in AL.
Conclusion
AL Code Actions is a must-try extension for anyone doing AL development in Business Central. Its two standout features — generating procedures from usage and extracting code into new procedures — are the kind of refactoring tools that can dramatically speed up your development workflow. The extension is intelligent about parameter types, return types, and variable analysis, making it a remarkably polished tool. Erik gives it a strong five-star recommendation, and if it fits into your workflow as well as it fits into his, it’s well worth installing.