Skip to content

simatic-ax/snippetscollection

Repository files navigation

Snippets collection

A collection of useful user defined snippets for AX Code.

Install the snippets collection

Before installing the snippets collection, the URL to the package registry need to be defined in the apax.yml

registries:
  '@simatic-ax': 'https://npm.pkg.github.com/'

To install the snippets collection to your workspace enter the following command in a terminal:

apax add @simatic-ax/snippetscollection --dev

to install this package you need to login into the GitHub registry. You'll find more information here

AXUnitSupport

Create a test fixture with AxUnit.Assert

"prefix": ["AxUnit test-fixture"]

Output example:

io

Insert Using AxUnit.Assert

"prefix": ["AxUnit, using ax"]

Output:

USING AxUnit.Assert;

AxUnit assertions

"prefix": ["eq, ne, lt, gt"]

Output:

Equal(expected := 0, actual := 0);
NotEqual(expected := 0, actual := 0);
LessThan(expected := 0, actual := 0);
GreaterThan(expected := 0, actual := 0);

Code actions

Increment / Decrement

increment

Select the variable and enter the prefixes: increment or decrement

Surround with

surround

Available surround with:

  • FOR ... END_FOR;
  • IF ... THEN ... ELSE
  • WHILE ... END_WHILE
  • REPEAT .. END_REPEAT

Snippets Namespace Support

NamespaceSupport

"prefix" : ["namespace, Siemens"]

namespace

Snippets for class support

"prefix" : ["class template, End_Class"]

Output:

NAMESPACE Simatic.Ax
    CLASS Untitled
        VAR PUBLIC
            
        END_VAR
        VAR PROTECTED
            
        END_VAR
        
        METHOD PUBLIC MyMethod
            ;
        END_METHOD
    END_CLASS
END_NAMESPACE

ClassMethodSupport

"prefix" : ["method, no return"]

Output:

METHOD PUBLIC|PRIVATE|PROTECTED MyMethod
    ;
END_METHOD

METHOD PUBLIC|PRIVATE|PROTECTED MyMethod : Type
     MyMethod := ;
END_METHOD

// types: BOOL,INT,LREAL,WORD,REAL,DINT,UINT,SINT

VAR sections within classes

"prefix" : ["varc"]

Output:

VAR PUBLIC|PRIVATE|PROTECTED 
    ;
END_VAR

VAR sections within methods and functions

"prefix" : ["vari"]

Output:

VAR_INPUT|VAR_OUTPUT|VAR_IN_OUT|VAR_TEMP|VAR CONSTANT
    count: INT;
END_VAR

Enumeration

"prefix" : ["enum"]

Output:

TYPE
    Colours : (RED, GREEN, BLUE) := RED;
END_TYPE

IO support

"prefix" : ["io"]

Support for creating IO Tags in the VAR_GLOBAL section. Suported types BOOL, BYTE, WORD, DWORD

Output example:

io

Iterate ARRAY[*] Snippet

"prefix" : ["Iterate Array*"]

Output example:

io

Contribution

Thanks for your interest in contributing. Anybody is free to report bugs, unclear documentation, and other problems regarding this repository in the Issues section or, even better, is free to propose any changes to this repository using Merge Requests.

Markdownlint-cli

This workspace will be checked by the markdownlint-cli (there is also documented ho to install the tool) tool in the CI workflow automatically.
To avoid, that the CI workflow fails because of the markdown linter, you can check all markdown files locally by running the markdownlint with:

markdownlint **/*.md --fix

License and Legal information

Please read the Legal information