1 Snippets_en
kuro edited this page 2026-10-15 20:43:14 +00:00

🚀 Snippets & Quick Fixes

The BMC TPL Code All around extension massively reduces your typing effort. With intelligent code templates (Snippets) and automatic error resolutions (Quick Fixes), you write TPL code not only faster but also error-free.


📝 Smart Snippets (Code Templates)

Snippets are short abbreviations that turn into complete code blocks when typing (or by pressing Ctrl + Space). Tip: After inserting a snippet, you can easily jump through the placeholders (like variable names or conditions) using the Tab key!

The God-Snippet

Keyword Description
tpl_skeleton Generates a completely fresh .tpl file including module definition, mandatory metadata, pattern, triggers, and log statements. Special feature: Automatically pulls your name, the publisher, and the TPL version from your VS Code settings!

Control Structures (New!)

No more forgotten then, do, or end blocks. Just type the keyword and press Tab:

Keyword Generated Code
if Builds if <condition> then ... end if; and places the cursor inside the condition.
elif Builds elif <condition> then ... for seamless if-chains.
else Builds the else ... block.
for Builds for <item> in <list> do ... end for;.
while Builds while <condition> do ... end while;.

TPL Structures & Blocks

Keyword Description
pattern Builds an empty pattern block including a DocString (""") and end pattern;.
syncmapping Builds an empty syncmapping block including a DocString.
define Generates a method definition (define name(params) ... end define;).
table Creates a table including the mandatory default -> "unknown"; fallback.
metadata, body, ... Builds the respective TPL block (metadata ... end metadata;) and places the cursor in the middle.

⚡ Quick Fixes (Code Actions)

When the linter finds an error or a warning, a small lightbulb often appears at the beginning of the line. You can also simply click on the marked line and press Ctrl + . (Windows/Linux) or Cmd + . (Mac) to have the problem fixed automatically.

Currently, the extension supports the following automatic repairs:

1. "Generate missing module metadata"

  • Trigger: You have a metadata block, but mandatory fields are missing (like origin, author, products, publishers, or tree_path).
  • Action: The plugin immediately generates the missing lines with dummy values inside the block, making the code valid again.

2. "Insert log statement"

  • Trigger: The initially required log.debug statement with the pattern name is missing in the body of a pattern.
  • Action: Inserts the missing log.debug("Start pattern <Name>"); right as the first line in the body block.

3. "Tabs to Spaces"

  • Trigger: The linter finds tab characters (\t) in the code. (Spaces are best practice in BMC TPL).
  • Action: Instantly replaces all illegal tabs in the flagged line with 4 clean spaces each.