How nateyjaybee/fanuctpp works
Project type and purpose
• This is a Visual Studio Code extension named CodeFanuc TP Assist.
• Its purpose is to enhance the experience of editing Fanuc Teach Pendant programs by providing:
• Custom syntax definitions & theme for .ls, .kl, .dt, .cf files
• Code-editing utilities (auto-renumbering, auto-semicolon)
• Interactive commands and Webview panels for labels, I/O registers, backups
• Ctrl+Click navigation to other programs in the same folder
File structure
• Top-level directories:
• src/ – TypeScript source, organized into commands/, utils/, webviews/, types/
• syntaxes/ – TextMate grammar files (.tmLanguage.json) for each Fanuc file type
• themes/ – Custom VS Code theme (.tmTheme.json)
• completions/ & langs/ – JSON files for completions & language configurations
• package.json, tsconfig.json – Extension manifest and compiler config
• out/ directory is the compiled JavaScript (ignored when diagramming source)
• Key modules:
• extension.ts – Activation entrypoint
• commands/*.ts – Command handlers registered with VS Code
• webviews/*.ts – Code to spin up and update VS Code WebviewPanels
• utils/*.ts – Shared helper functions (editing, file I/O, navigation, networking)
• state.ts & constants.ts – Global state management and constant definitions
README for additional insights
• Lists features (auto-renumber, webview commands, theme)
• Describes interaction patterns (commands invoked via Ctrl+Shift+P, webviews that allow jumping to lines or replacing identifiers)
• No external services or databases—purely a client-side extension executing inside VS Code
Main components & their interactions
a. VS Code Host
• Activation:
• On startup, VS Code loads extension.ts
• Registers commands, language configurations, theme, syntax
• Event listeners:
• TextDocument change events trigger auto-renumber & semicolon logic
• Ctrl+Click handlers for program navigation
b. Commands layer (labelCommands, nameCommands, backupCommands, openProgramCommands)
• Exposed via package.json command IDs
• Each opens a WebviewPanel or triggers an edit operation
c. Webview UIs (LabelView, NameView, BackupView)
• Run HTML/JS sandboxed in VS Code
• Communicate with the extension via postMessage to request data or navigation commands
d. Utilities & shared modules
• helpers for debounce, decorate, extractors (parsing code), file I/O, navigation, network
• state.ts stores intermediate data between events and UI
e. Language features
• Syntax grammars in syntaxes/ loaded by VS Code for highlighting
• completions/ & langs/ provide IntelliSense and language configurations
Architectural patterns & design principles
• Plugin architecture: extension host ↔ VS Code core UI
• Modular separation:
• Commands (trigger → action → UI)
• Webviews (presentation layer)
• Utils (business logic and file manipulation)
• Event-driven model: document changes and command invocations
• Message-passing interface between extension process and Webview content