How spgennard/vscode_cobol works
Project purpose and type
• This is a Visual Studio Code extension (written in TypeScript, bundled with webpack) that provides COBOL (and related languages) syntax highlighting, IntelliSense, navigation, linting, snippets and auxiliary commands.
Top-level components
• VS Code Host (the editor core)
• Extension Host (node process where your code runs)
• Bundled Extension Package (webpack bundle produced from src/, syntaxes/, snippets/, theme/, resources/, package.json)
• External Dependencies (file system, optional compilers via tasks/problem matchers, Docker/dev-container)
Core internal modules (all under src/)
a. Activation & Registration
– extension.ts / web/extension.ts
– extensionDefaults.ts (default settings)
– Registers commands, configuration listeners, language feature providers
b. TextMate Grammar Layer
– syntaxes/*.tmLanguage.json
– Registered in package.json contributions → VS Code’s TextMate engine does syntax highlighting
c. Scanner & Parser Engine
– cobscanner.ts / cobscanner_worker.ts (tokenizes source)
– cobolsourcescanner.ts, icobolsourcescanner.ts (dialect-specific logic)
– splittoken.ts, stringutils.ts, caseformatter.ts for low-level operations
d. Cache & Symbol Management
– cobolworkspacecache.ts / cobolglobalcache.ts + globalcachehelper.ts
– cobolprogram.ts, cobolsymboltableeventhelper.ts (manages symbol tables & events)
e. Language Feature Providers
– Hover: vshoverprovider.ts
– Definition/References: vssourcedefinitionprovider.ts, vsreferenceprovider.ts
– Completion/Semantic: vssnippetprovider.ts, vssemanticprovider.ts, vskeywordprovider.ts
– Rename: vsrenameprovider.ts
– Outline / Breadcrumbs: sourceItem.ts + feedbacktree.ts, vscommon_commands.ts
– Call Hierarchy: vscallhierarchyprovider.ts / vscobolcalltargetprovider.ts
f. Linter & Problem Matcher Definitions
– cobollinter.ts, problem matcher JSONs in package.json & schemas/tmlanguage.json
g. Utility & CLI Integration
– fileutils.ts, filesourcehandler.ts
– consoleexternalfeatures.ts, externalfeatures.ts for commands (e.g., remove comments, re-sequence)
h. Snippets, Themes & Resources
– snippets/*.json → snippet insertion
Data flows & interactions
• VS Code Core → loads the extension bundle at activation.
• Extension activation → reads configuration (extensionDefaults), registers grammar, commands, providers
• On document open/edits:
– TextMate grammar highlights tokens (via syntaxes)
– The scanner engine runs in the extension host (possibly in a web worker) to produce tokens/events
– Parser builds symbol tables, updates caches
– Providers (hover, go-to, completion) query the caches/symbol tables to respond
• User invokes commands (via command palette or keybindings) → consoleexternalfeatures/externalfeatures run tasks or code transforms
• Linter runs on-the-fly or in tasks → problem matchers pick up compiler output
• Optional tasks invoke external compilers (cobol, cobc, ccbl32) for build errors
Architectural patterns & principles
• Event-driven & provider-based architecture (the VS Code extension model)
• Layered separation: Syntax (grammar) → Scanning → Caching/Parsing → Feature Providers → UI
• Worker offloading: heavy scanning done in cobscanner_worker for responsiveness
• Configuration-driven behavior (multiple .configuration.json files for dialects)