K2Script — VS Code Extension
Language support for K2Script, the Pascal-dialect scripting language used in K2 ERP.
Status: Early preview / incomplete — expect rough edges.
The extension is actively being developed and tested. Some features may not work correctly in all situations.
Bug reports and feedback: Please report any issues via Microsoft Teams.
Features
Syntax Highlighting
Full TextMate grammar covering K2Script-specific constructs:
- K2 certificate headers —
{!#CERT3=...} blocks shown as documentation comments
- Compiler directives —
{$DESC '...'}, {$TYPE ...} and other {$...} pragmas
- Code-generation markers —
{@GENERATED}, {@ENDGENERATED}, {@MANUAL}, {@ENDMANUAL}
- K2 date/time literals —
%DD.MM.YYYY, %HH:MM:SS
info...end metadata blocks — with property names (Title, Author, Keywords, LANGNUM, …) highlighted
- K2-specific keywords —
pureunit, modules, module, exported, files
- Record-mode constants —
remAppend, remEdit, remDelete, remFree, remReplace, remAll, …
- K2 built-in functions —
K2Now, FirmPath, ExecK2Form, RunScript, ProcessIndicator, …
- Standard Pascal functions —
IntToStr, Format, FormatDateTime, IncMonth, Trim, …
- K2 constant naming patterns —
ec*, er*, mr*, tf*, sdm*, cD_* prefixes
- K2 operators —
^ (AsControlValue) and ° (TDataField field accessor)
- K2 type names —
TDate, TTime, ArrayOfString, TxxxDM data-module types
- K2 global variables —
aktdm, CurrentDM, FirSet, CurrentUFContext, …
- Standard Pascal keywords, control flow, types, numbers, strings, and
// / { } / (* *) comments
The extension bundles a full automatic code formatter for K2Script .PAS files — one of its most important features.
Trigger with the standard VS Code format command:
Shift + Alt + F (Windows / Linux)
Shift + Option + F (macOS)
- Or right-click → Format Document
What the formatter does:
| Rule |
Detail |
| Indentation |
2-space indent, consistent across all block types |
begin/end blocks |
try/except/finally, repeat/until, case/of, record all indented correctly |
| Soft sections |
uses, var, const, type, modules — content indented, section closed automatically when the next section starts |
| Single-statement constructs |
if x then stmt; / for ... do stmt; / while ... do stmt; indented without extra wrap |
info...end blocks |
K2 metadata block indented as a unit |
Multi-line program(...) |
Continuation lines inside unclosed (...) get an extra indent level |
| Blank lines |
Collapses consecutive blank lines to at most one |
Standalone // comments |
Always placed at column 0, regardless of surrounding indent |
| Column-0 markers |
{!#CERT...}, {@GENERATED}, {@ENDGENERATED} never indented |
Error Diagnostics
Basic validation with red-underline diagnostics for common mistakes:
- Mismatched
begin/end block depth
- Unknown or misspelled K2-specific keywords (limited coverage — work in progress)
Supported File Types
.PAS and .pas files are automatically recognised as K2Script.
Requirements
- VS Code 1.80 or newer
- No runtime dependencies — pure TypeScript, no external tools needed
Known Limitations
- Formatter is not perfect. Complex nested constructs (deep
case of, inline end else begin chains, with blocks) may indent incorrectly in edge cases.
- Diagnostics coverage is limited. Only a small subset of possible errors is detected.
- No IntelliSense / autocomplete yet.
- No go-to-definition or hover docs yet.
- Tested only against internal K2 ERP
.PAS scripts — third-party Pascal files may not format correctly.
Release Notes
1.0.9
New:
- Soft-section keywords (
uses, var, const, type, modules) are now forced onto their own line — content that follows on the same line is automatically split to the next line and indented (e.g. modules api: TBVVApiInterface, → modules / api: TBVVApiInterface,)
1.0.8
Bug fixes:
- Standalone
// comments that contain a keyword (begin, end, if, var, etc.) are no longer moved to column 0 — they keep the current indentation level (treated as commented-out code)
1.0.7
Bug fixes:
- Added 6 missing standard modules to the known-modules list:
TExternalDocumentDM, TAdvanceReceivedDM, TinternalDocumentDM, TMatchingSymbolDM, TOfficerDM, TPrPeriodDM
1.0.6
New:
- Standard module validation — modules listed in the
modules section are checked against 1 073 known standard K2 modules; any module not in the list is highlighted with a warning ("není standardní K2 modul"), so custom or misspelled module names stand out without blocking compilation
- Correctly handles the
alias: TypeName, syntax — only the type name is validated, not the alias
1.0.5
Bug fixes:
- Fixed inconsistent
end keyword colors in case...else...end, try...finally...end and all other block structures — begin/end were registered as VS Code bracket pairs which caused the bracket pair colorization to override the grammar color with a different hue at each nesting depth; removed from bracket pairs entirely
1.0.4
Bug fixes:
begin and end now use the same color as if, case, try, finally, else, etc. — previously they used a separate TextMate scope that many themes styled differently, causing inconsistent colors in case...else...end and try...finally...end blocks
1.0.3
Bug fixes:
end keyword no longer shows different colors at different nesting depths — bracket pair colorization is now limited to () and [] only
end; closing an info block now uses the same color as all other end keywords
1.0.2
Bug fixes:
memfile type blocks (type X = memfile ... end;) no longer incorrectly reported as mismatched end
memfile now indented correctly by the formatter (fields inside treated like record fields)
memfile now highlighted as a declaration keyword
pureunit files no longer trigger a false "file must start with program or unit" warning
1.0.1
- Added README with full feature documentation
1.0.0
- Renamed extension to K2 Script Support
- Formatter included as a core feature
0.1.0
Initial public preview:
- Syntax highlighting for K2Script
- Code formatter with K2-specific rules
- Basic error diagnostics
About K2 ERP
K2 is a Czech ERP system. K2Script is a Pascal dialect used to write custom business logic, forms, and integrations directly inside K2. This extension is an unofficial community tool — not affiliated with K2 atmitec s.r.o.
| |