Hi, Readers.
Today I would like to talk about AL Code Actions.
The AL Language extension offers users the option to help fix issues in code. Code Actions is a Visual Studio Code feature providing the user with possible corrective actions right next to an error or warning. If actions are available, a light bulb appears next to the error or warning. When the user clicks the light bulb (or presses Ctrl+.), a list of available code actions is presented.
So, Code Actions provides possible corrective actions which will help the developer to code in a better way.
In AL Language extension these code actions are available in the current version (v11 04/03/2023):
- Multiple IF to CASE converting code action
- Spell check code action
- Interface implementer
- Make method local
- Use parenthesis for method call fix for instance, document, project, or workspace.
- Fix explicit
with
statements - Fix implicit with statements
- Fix old report layout and replace with
rendering
layout section - Fix for AW0013
- Convert pages or page extensions to use the
actionRef
syntax for promoted actions on the action bar. Fix for instance, document, project, or workspace. For more information, see Code action for actions. - Set the default value for
ApplicationArea
on a page or a report level and remove all duplicates on field level. This code action can be applied to an object, a document, a project, or a workspace. - Convert existing event parameter in event subscribers from string literal to new identifier format. Fix event subscriber on the specific EventSubscriber instance, the active file, the active project, or the whole workspace. This makes it easy and controllable to opt in to the new syntax.
To enable AL Code Actions, open the Settings Page, navigate to Extensions > AL Language extension configuration, then click on the Enable Code Actions checkbox.
Alternatively:
Open the settings.json file, then enter the setting al.enableCodeActions and set it to true like this “al.enableCodeActions”: true.
Let’s look at a few examples.
1. Convert the ‘with’ statement to fully qualified statements.
2. Qualify with ‘Rec’ -> All occurrences in this object.
3. Fix typo.
4. Convert to ‘case of’.
Update from Business Central Launch Event (2022 release wave 2)
Update 2022.12.02: AL Code Actions
- Fix old report layout and replace with
rendering
layout section - Fix for AW0013
- Convert pages or page extensions to use the
actionRef
syntax for promoted actions on the action bar. Fix for instance, document, project, or workspace. For more information, see Code action for actions.
Add some examples:
The spell check code action is triggered on certain syntax errors:
The make method local action is triggered to fix the CodeCop Warning AA0207:
Code actions for promoted actions:
Use the code action to convert legacy syntax for promoted actions to the actionref
syntax, which is introduced with Business Central 2022 release wave 2. In-client customizations, user personalization, and profile configurations are automatically converted into the new syntax, so this is primarily applicable to DEV extensions. The code action can apply to a single instance, the document, the project, or the workspace.
More details:
- Business Central 2022 wave 2 (BC21) new features: Promoted action groups, action references, and ShowAs Property (New Modern Action Bar)
- Business Central 2022 wave 2 (BC21): Where is the Process tab on documents, cards, worksheets and listplus pages? (Home tab)
Note:
For Designer extensions, use F6 to open Designer, which opens the page where the legacy syntax is used. Choose the Lock symbol and use Unlock page to automatically convert the legacy syntax for the running code. Pressing Alt+F6 will bring you back into Visual Studio Code, and show the converted actionref
code.
More details: Dynamics 365 Business Central: Pull designer changes into VS Code (F6 -> Design in BC -> Alt + F6)
Update 2023.04.17: Business Central 2023 wave 1 (BC22): Code actions for refactoring ApplicationArea property
Update 2024.09.09: Business Central 2024 wave 2 (BC25): Run code action for ‘with’ for file, project, or workspace
END
Hope this will help.
Thanks for reading.
ZHU
コメント