
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@effect/language-service
Advanced tools
A Language-Service Plugin to Refactor and Diagnostic effect-ts projects
This package implements a TypeScript language service plugin that allows additional refactors and diagnostics with your VSCode editor (or any editor that supports TypeScript's LSP).
npm install @effect/language-service --save-dev
in your project{
"compilerOptions": {
"plugins": [
// ... other LSPs (if any) and as last
{
"name": "@effect/language-service"
}
]
}
}
Ensure that you have installed TypeScript locally in your project and set your editor to use your workspace TypeScript version.
.vscode/settings.json
{
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
And you're done! You'll now be able to use a set of refactors and diagnostics that target Effect!
yield*
of Effect.gen
will show the Effect type parametersEffect.gen
Effect.provide
anti-patternSelf
type parameter for APIs like Effect.Service
or Schema.TaggedError
and similar Effect.gen
or pipe()
Effect.gen
with the old generator adapter patternEffect.gen
and familyX.pipe(Y).pipe(Z)
Effect.Service
with accessors: true
but methods have generics or multiple signaturesEffect.Service
declarationsEffect.Service
, Context.Tag
, Schema.TaggedClass
, Schema.TaggedRequest
and familyEffect.gen
with function*(){}
Effect.fn
with the span name given by the exported memberimport * as Effect from "effect"
Schema.brand
Effect.Service
, Context.Tag
or Effect.Tag
declarationEffect.gen
definitions that contains a single yield
statement.Effect
expression with Effect.gen
X.pipe(Y)
and pipe(X, Y)
Few options can be provided alongside the initialization of the Language Service Plugin.
{
"compilerOptions": {
"plugins": [
{
"name": "@effect/language-service",
"refactors": true, // controls Effect refactors (default: true)
"diagnostics": true, // controls Effect diagnostics (default: true)
"diagnosticSeverity": { // allows to change per-rule default severity of the diagnostic in the whole project
"floatingEffect": "warning" // example for a rule, allowed values are off,error,warning,message,suggestion
},
"quickinfo": true, // controls Effect quickinfo (default: true)
"quickinfoEffectParameters": "whenTruncated", // (default: "whenTruncated") controls when to display effect type parameters always,never,whenTruncated
"completions": true, // controls Effect completions (default: true)
"goto": true, // controls Effect goto references (default: true)
"inlays": true, // controls Effect provided inlayHints (default: true)
"allowedDuplicatedPackages": [], // list of package names that have effect in peer dependencies and are allowed to be duplicated (default: [])
"barrelImportPackages": [], // package names that should be preferred as imported from the top level barrel file (default: [])
"namespaceImportPackages": [], // package names that should be preferred as imported with namespace imports e.g. ["effect", "@effect/*"] (default: [])
"topLevelNamedReexports": "ignore", // for namespaceImportPackages, how should top level named re-exports (e.g. {pipe} from "effect") be treated? "ignore" will leave them as is, "follow" will rewrite them to the re-exported module (e.g. {pipe} from "effect/Function")
"importAliases": { "Array": "Arr" }, // allows to chose some different names for import name aliases (only when not chosing to import the whole module) (default: {})
"noExternal": false // disables features that provides links to external websites (such as links to mermaidchart.com) (default: false)
}
]
}
}
The full list can be found in the diagnostics folder.
TypeScript LSPs are loaded only while editing your files. That means that if you run tsc
in your project, the plugin won't be loaded and you'll miss out on the Effect diagnostics.
We provide two approaches to solve this scenario.
This option works by modifing directly the source code of the tsc compiler and the typescript library in your project node_modules. This allows to get effect's diagnostics even when noEmit is enabled, for composite and incremental projects as well.
After having installed and configured the LSP for editor usage, you can run the following command inside the folder that contains your local project typescript installation:
effect-language-service patch
If everything goes smoothly, something along these lines should be printed out:
/node_modules/typescript/lib/typescript.js patched successfully.
/node_modules/typescript/lib/_tsc.js patched successfully.
Now the CLI has patched the tsc binary and the typescript library to raise effect diagnostics even at build time if the plugin is configured in your tsconfig!
As the command output suggests, you may need to delete your tsbuildinfo files or perform a full rebuild in order to re-check previously existing files.
To make the patch persistent across package installations and updates, we recommend adding the patch command to your package.json prepare scripts:
"scripts": {
"prepare": "effect-language-service patch"
}
so that across updates the patch will be re-applied again.
if you use ts-patch
you can enable the transform as well to get the diagnostics also at compile time.
Your tsconfig.json
should look like this:
{
"compilerOptions": {
"plugins": [
{
"name": "@effect/language-service",
"transform": "@effect/language-service/transform" // enables diagnostics at compile time when using ts-patch
}
]
}
}
To get diagnostics you need to install ts-patch
which will make it possible to run tspc
.
Running tspc
in your project will now also run the plugin and give you the error diagnostics at compile time.
Effect error diagnostics will be shown only after standard TypeScript diagnostics have been satisfied.
Beware that setting noEmit will completely skip the effect diagnostics, and projects using incremental builds may encounter some issues.
$ npx tspc
index.ts:3:1 - error TS3: Effect must be yielded or assigned to a variable.
3 Effect.succeed(1)
~~~~~~~~~~~~~~~~~
Found 1 error in index.ts:3
You can either disable or change the severity of specific diagnostics by using comments in your code.
// @effect-diagnostics effect/floatingEffect:off
Effect.succeed(1); // This will not be reported as a floating effect
// @effect-diagnostics effect/floatingEffect:error
Effect.succeed(1); // This will be reported as a floating effect
or you can set the severity for the entire project in the global plugin configuration
{
"compilerOptions": {
"plugins": [
{
// ...
"diagnosticSeverity": { // allows to change per-rule default severity of the diagnostic in the whole project
"floatingEffect": "warning" // example for a rule, allowed values are off,error,warning,message,suggestion
},
// ...
}
]
}
}
The Svelte LSP does not properly compose with other LSPs when using SvelteKit. So the Effect LSP should be loaded as last entry to ensure proper composition.
If you did not install the Svelte LSP into your local project but instead through the Svelte VSCode extension, we recommend instead to install it locally and add it as the first entry. That way it won't be applied by the VSCode extension.
Your tsconfig.json should look like this:
{
"compilerOptions": {
"plugins": [
{ "name": "typescript-svelte-plugin" },
{ "name": "@effect/language-service" }
]
}
}
FAQs
A Language-Service Plugin to Refactor and Diagnostic effect-ts projects
The npm package @effect/language-service receives a total of 305,065 weekly downloads. As such, @effect/language-service popularity was classified as popular.
We found that @effect/language-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.