// VSCODE-AWK — ENGINEERING REPORT

VS Code / VSCodium support for AWK · standalone TextMate grammar (source.awk) · LSP via awkrs --lsp · DAP via awkrs --dap · verified with vscode-textmate

>_EXECUTIVE SUMMARY

vscode-awk is the VS Code / VSCodium extension for AWK, backed by the awkrs interpreter — a pattern/action engine written in Rust (POSIX / gawk / mawk-style union CLI). It ships a declarative language contribution (filetype, grammar, editor config), an LSP client that launches awkrs --lsp, a debug adapter that launches awkrs --dap, and a TextMate grammar (source.awk) covering the AWK surface.

Design principle: mirror the proven vscode-stryke runtime wiring. The LSP transport is omitted so the client spawns bare awkrs --lsp and never appends --stdio (the arg-rejection / “connection got disposed” failure mode learned from vscode-stryke). The binary is resolved to an absolute path through $PATH plus common install dirs (~/.cargo/bin, /opt/homebrew/bin, …), so it works even when the editor is launched from the macOS Dock and doesn’t inherit the shell $PATH.

22
Built-in functions scoped
21
Built-in variables
16
Keyword tokens
2
Special patterns (BEGIN / END)
1
TextMate grammar
2
Detection paths (ext + shebang)
13
Tokenizer assertions
2
Runtime channels (LSP + DAP)

~COMPONENTS

FileResponsibility
package.jsonExtension manifest — contributes.languages (id awk, *.awk, shebang firstLine), contributes.grammars (source.awk), contributes.configuration (LSP settings), contributes.commands (run / debug), contributes.debuggers (type awk), and the vscode-languageclient dependency.
language-configuration.jsonLine comment #, brackets, auto-closing / surrounding pairs, word pattern, and brace-based indentationRules.
extension.jsActivates on onLanguage:awk. Starts a LanguageClient running awkrs --lsp over stdio, registers the run command (terminal awkrs -f <file>), and registers a DebugAdapterDescriptorFactory launching awkrs --dap. Missing binary → one non-fatal warning; highlighting still works.
lib/resolveBinary.jsPure (vscode-free) resolver that turns the awk.path setting into an absolute, executable path — searching $PATH then the GUI-missed fallback dirs. Unit-tested in CI.
syntaxes/awk.tmLanguage.jsonTextMate grammar — comments, shebang, strings, /.../ regex, numbers, special patterns, keywords, built-in functions / variables, field references, function definitions, and operators.
scripts/tokenize_test.jsLoads the grammar under vscode-textmate + vscode-oniguruma (the engine VS Code itself uses) and asserts the scope of 13 sample tokens.

$SCOPE MAP

Token groupTextMate scopeSample
Special patternskeyword.other.special-pattern.awkBEGIN END
Control flowkeyword.control.awkif else while for next exit return
I/O statementskeyword.other.io.awkprint printf getline
Function introstorage.type.function.awkfunction func
Built-in variablesvariable.language.awkNR NF FS OFS ORS RS FILENAME SUBSEP
String functionssupport.function.string.awklength substr split sub gsub match sprintf
Math functionssupport.function.math.awksin cos atan2 exp log sqrt int rand
I/O functionssupport.function.io.awksystem close fflush
Field referencesvariable.language.field.awk$0 $1 $NF $(NF-1)
Match operatorskeyword.operator.match.awk~ !~
Literalsstring.* / constant.numeric / string.regexpstrings, numbers, /.../ regex

#VERIFICATION

The grammar is loaded under the exact engine VS Code uses at runtime — vscode-textmate driving vscode-oniguruma — and a sample is tokenized with the resulting scopes asserted. This proves the grammar compiles under oniguruma and classifies AWK tokens correctly, including the tricky cases: a /.../ regex literal distinguished from division, a field reference such as $1 against the NF built-in, and the function name capture.

Sample tokenAsserted scope
BEGINkeyword.other.special-pattern.awk
FSvariable.language.awk
/^error/string.regexp.awk
$1variable.language.field.awk
gsubsupport.function.string.awk
function / trimstorage.type.function.awk / entity.name.function.awk