@typesugar/ts-plugin
v0.1.0
Published
๐ง TypeScript language service plugin for typesugar
Maintainers
Readme
@typesugar/ts-plugin
TypeScript Language Service Plugin for typesugar that enables full IDE support including:
- Type-aware transformation โ Custom syntax (
|>,::,F<_>) and macros are transformed before TypeScript processes the code - Accurate diagnostics โ Error positions map back to your original source
- Go-to-definition โ Navigate to original source locations, not transformed code
- Completions โ IntelliSense works on both original and generated code
- Hover info โ See type information for original symbols
- Find references โ Find all references to symbols across transformed code
Installation
npm install @typesugar/ts-plugin --save-dev
# or
pnpm add -D @typesugar/ts-pluginConfiguration
Add the plugin to your tsconfig.json:
{
"compilerOptions": {
"plugins": [
{
"name": "@typesugar/ts-plugin",
"verbose": false,
"extensions": ["hkt", "pipeline", "cons"]
}
]
}
}Options
| Option | Type | Default | Description |
| ------------ | ---------- | ----------------------------- | ---------------------------------------------------------------- |
| verbose | boolean | false | Enable verbose logging for debugging |
| extensions | string[] | ["hkt", "pipeline", "cons"] | Syntax extensions to enable |
| legacyMode | boolean | false | Use legacy error-suppression mode instead of full transformation |
Extensions
hktโ Higher-kinded type syntax (F<_>โ$<F, A>)pipelineโ Pipe operator (a |> fโf(a))consโ Cons operator (x :: xsโcons(x, xs))
Legacy Mode
If you encounter issues with the transform-first approach, you can fall back to legacy mode which simply suppresses errors for typesugar syntax:
{
"compilerOptions": {
"plugins": [
{
"name": "@typesugar/ts-plugin",
"legacyMode": true
}
]
}
}Legacy mode is less accurate but more stable. It's recommended as a fallback if you experience problems with the default mode.
VS Code Integration
When using the typesugar VS Code extension, you can configure the plugin via VS Code settings:
{
"typesugar.useLegacyPlugin": false,
"typesugar.enableVerboseLogging": false
}The extension also provides commands for debugging:
- typesugar: Show Transformed Source โ View the transformed code in a diff view
Debugging
If you encounter issues:
- Enable verbose logging to see plugin activity
- Use "Show Transformed Source" to see what TypeScript is actually processing
- Check the TypeScript server log for errors (VS Code: "TypeScript: Open TS Server Log")
- Try legacy mode if the transform-first approach causes problems
Architecture
This plugin uses a transform-first architecture:
- Preprocessing โ Custom syntax is converted to valid TypeScript
- Macro expansion โ Macros (
@derive,comptime, etc.) are expanded - Source mapping โ A source map tracks the transformation
- Position mapping โ IDE features map positions back to original source
The same transformation pipeline is used by:
- Build tools (via
unplugin-typesugar) - CLI (via
@typesugar/transformer) - This language service plugin
This ensures consistent behavior across all tools.
