typecon_plugin
v0.6.0
Published
TypeCON's plugin VS Code to help with the rules and limitations of TypeCON.
Readme
TypeCON Plugin
This is a TypeScript Language Service Plugin that enforces custom “TypeCON” rules. It applies its checks only to files that import a specific “marker” path (e.g., defs/TCSet100/types or other language set). If the marker file itself contains @typecon, the importing file is flagged for special analysis.
Features
- Marker Import Detection
If a file does:
or another recognized pattern, this plugin runs additional checks (e.g., ensuringimport "defs/TCSet100/types";CON(...)usage, restricting block-scope references, etc.). - Optional Check for
@typecon
The plugin can resolve the import path to the actual file on disk, load that file’s source, and confirm@typeconis present. If found, the main file is considered a “TypeCON” file.
How It Works
- Patches the TypeScript Language Service
The plugin overridesgetSemanticDiagnostics, merges in TypeScript’s normal diagnostics, and then adds its own if the file meets your “marker” criteria. - Resolves the Imported File
Usingts.resolveModuleNameplusprogram.getSourceFile(...), the plugin finds the real source file behind'../defs/TCSet100/types'. - Scans for
@typecon(optional)
If the imported file’s text includes@typecon, we proceed with advanced TypeCON checks. Otherwise, the file is skipped.
Installation & Usage
Install the plugin in your TypeScript project:
npm install --save-dev path/to/this-plugin # or yarn add --dev path/to/this-pluginAdd to your
tsconfig.json:{ "compilerOptions": { "plugins": [ { "name": "typecon-plugin" } ] // ... }, "include": [ "src/**/*.ts" // ... ] }Open your project in VS Code (or your editor of choice that uses the TS server).
Import the marker in any file you want to apply the rules:
import "defs/TCSet100/types"; // That file might contain: // // @typecon // // or other codeCheck your editor’s Problems panel or run
tscto see the plugin’s diagnostics.Restart TS Server open the command pallete and run TypeScript: Restart TS Server, so the plugin can start working.
Example
// main.ts
import "defs/TCSet100/types"; // triggers TypeCON checks
CON(`
qputs 9999 Hello
quote 9999
`); // your plugin can parse & validate this code// ../defs/TCSet100/types.ts
// @typecon
// (Any code or marker you need here)Contributing
- Clone or fork this repository.
- Install dependencies:
npm install - Build the plugin:
npm run build - Test or integrate into a sample TypeScript project to verify the diagnostics appear as expected.
Troubleshooting
Plugin Not Loading
Make sure your main project’stsconfig.jsonincludes:"compilerOptions": { "plugins": [ { "name": "typecon-plugin" } ] }and that the plugin is installed in the project’s
node_modules.Files Not Detected
Ensure your project has"include": ["src/**/*.ts"]or a suitable pattern. Also confirm the plugin logic is referencing the correct import path.Crash on Import Resolution
Double-check you’re using the officialts.resolveModuleNameapproach, and your environment can load the marker file. If the marker file is not in your compilation, the plugin may skip or fail to resolve.No Diagnostics
Verify the file is actually importing the marker path, and the marker file has@typeconif that logic is required.
