Warning: This is a work in progress and probably won't work for you. Use at your own risk!
A language server (implementing the language server protocol) for Svelte with macroforge TypeScript plugin support.
Requires Node 12 or later.
From https://microsoft.github.io/language-server-protocol/overview
The idea behind a Language Server is to provide the language-specific smarts inside a server that can communicate with development tooling over a protocol that enables inter-process communication.
In simpler terms, this allows editor and addon devs to add support for svelte specific 'smarts' (e.g. diagnostics, autocomplete, etc) to any editor without reinventing the wheel.
Svelte language server is under development and the list of features will surely grow over time.
Currently Supported:
Install a plugin for your editor:
The language server has quite a few settings to toggle features. They are listed below. When using the VS Code extension, you can set these through the settings UI or in the settings.json using the keys mentioned below.
When using the language server directly, put the settings as JSON inside initializationOptions.configuration for the initialize command. When using the didChangeConfiguration command, pass the JSON directly. The language server also accepts configuration for Emmet (key: emmet; settings reference), Prettier (key: prettier), CSS (key: css / less / scss; settings reference) and TypeScript (keys: javascript and typescript for JS/TS config; settings reference).
Example:
Init:
{
initializationOptions: {
configuration: {
svelte: {
plugin: {
css: { enable: false },
// ...
}
},
typescript: { /* .. */ },
javascript: { /* .. */ },
prettier: { /* .. */ },
// ...
}
}
}
Update:
{
svelte: {
plugin: {
css: { enable: false },
// ...
}
},
typescript: { /* .. */ },
javascript: { /* .. */ },
prettier: { /* .. */ },
// ...
}
}
svelte.plugin.typescript.enableEnable the TypeScript plugin. Default: true
svelte.plugin.typescript.diagnostics.enableEnable diagnostic messages for TypeScript. Default: true
svelte.plugin.typescript.hover.enableEnable hover info for TypeScript. Default: true
svelte.plugin.typescript.documentSymbols.enableEnable document symbols for TypeScript. Default: true
svelte.plugin.typescript.completions.enableEnable completions for TypeScript. Default: true
svelte.plugin.typescript.codeActions.enableEnable code actions for TypeScript. Default: true
svelte.plugin.typescript.selectionRange.enableEnable selection range for TypeScript. Default: true
svelte.plugin.typescript.signatureHelp.enableEnable signature help (parameter hints) for JS/TS. Default: true
svelte.plugin.typescript.semanticTokens.enableEnable semantic tokens (semantic highlight) for TypeScript. Default: true
svelte.plugin.typescript.workspaceSymbols.enableEnable workspace symbols for TypeScript. You can disable this if the language server client you're using doesn't deduplicate results from the TSServer. Default: true.
svelte.plugin.css.enableEnable the CSS plugin. Default: true
svelte.plugin.css.globalsWhich css files should be checked for global variables (--global-var: value;). These variables are added to the css completions. String of comma-separated file paths or globs relative to workspace root.
svelte.plugin.css.diagnostics.enableEnable diagnostic messages for CSS. Default: true
svelte.plugin.css.hover.enableEnable hover info for CSS. Default: true
svelte.plugin.css.completions.enableEnable auto completions for CSS. Default: true
svelte.plugin.css.completions.emmetEnable emmet auto completions for CSS. Default: true
If you want to disable emmet completely everywhere (not just Svelte), you can also set "emmet.showExpandedAbbreviation": "never" in your settings.
svelte.plugin.css.documentColors.enableEnable document colors for CSS. Default: true
svelte.plugin.css.colorPresentations.enableEnable color picker for CSS. Default: true
svelte.plugin.css.documentSymbols.enableEnable document symbols for CSS. Default: true
svelte.plugin.css.selectionRange.enableEnable selection range for CSS. Default: true
svelte.plugin.html.enableEnable the HTML plugin. Default: true
svelte.plugin.html.hover.enableEnable hover info for HTML. Default: true
svelte.plugin.html.completions.enableEnable auto completions for HTML. Default: true
svelte.plugin.html.completions.emmetEnable emmet auto completions for HTML. Default: true
If you want to disable emmet completely everywhere (not just Svelte), you can also set "emmet.showExpandedAbbreviation": "never" in your settings.
svelte.plugin.html.tagComplete.enableEnable HTML tag auto closing. Default: true
svelte.plugin.html.documentSymbols.enableEnable document symbols for HTML. Default: true
svelte.plugin.html.linkedEditing.enableEnable Linked Editing for HTML. Default: true
svelte.plugin.svelte.enableEnable the Svelte plugin. Default: true
svelte.plugin.svelte.diagnostics.enableEnable diagnostic messages for Svelte. Default: true
svelte.plugin.svelte.compilerWarningsSvelte compiler warning codes to ignore or to treat as errors. Example: { 'css-unused-selector': 'ignore', 'unused-export-let': 'error'}
svelte.plugin.svelte.format.enableEnable formatting for Svelte (includes css & js) using prettier-plugin-svelte. Default: true
You can set some formatting options through this extension. They will be ignored if there's any kind of configuration file, for example a .prettierrc file. Read more about Prettier's configuration file here.
svelte.plugin.svelte.format.config.svelteSortOrderFormat: join the keys options, scripts, markup, styles with a - in the order you want. Default: options-scripts-markup-styles
This option is ignored if there's any kind of configuration file, for example a .prettierrc file.
svelte.plugin.svelte.format.config.svelteStrictModeMore strict HTML syntax. Default: false
This option is ignored if there's any kind of configuration file, for example a .prettierrc file.
svelte.plugin.svelte.format.config.svelteAllowShorthandOption to enable/disable component attribute shorthand if attribute name and expression are the same. Default: true
This option is ignored if there's any kind of configuration file, for example a .prettierrc file.
svelte.plugin.svelte.format.config.svelteBracketNewLinePut the > of a multiline element on a new line. Default: true
This option is ignored if there's any kind of configuration file, for example a .prettierrc file.
svelte.plugin.svelte.format.config.svelteIndentScriptAndStyleWhether or not to indent code inside <script> and <style> tags. Default: true
This option is ignored if there's any kind of configuration file, for example a .prettierrc file.
svelte.plugin.svelte.format.config.printWidthMaximum line width after which code is tried to be broken up. This is a Prettier core option. If you have the Prettier extension installed, this option is ignored and the corresponding option of that extension is used instead. This option is also ignored if there's any kind of configuration file, for example a .prettierrc file. Default: 80
svelte.plugin.svelte.format.config.singleQuoteUse single quotes instead of double quotes, where possible. This is a Prettier core option. If you have the Prettier extension installed, this option is ignored and the corresponding option of that extension is used instead. This option is also ignored if there's any kind of configuration file, for example a .prettierrc file. Default: false
svelte.plugin.svelte.hover.enableEnable hover info for Svelte (for tags like #if/#each). Default: true
svelte.plugin.svelte.completions.enableEnable autocompletion for Svelte (for tags like #if/#each). Default: true
svelte.plugin.svelte.rename.enableEnable rename/move Svelte files functionality. Default: true
svelte.plugin.svelte.codeActions.enableEnable code actions for Svelte. Default: true
svelte.plugin.svelte.selectionRange.enableEnable selection range for Svelte. Default: true
svelte.plugin.svelte.runesLegacyModeCodeLens.enableWhether or not to show a code lens at the top of Svelte files indicating if they are in runes mode or legacy mode. Only visible in Svelte 5 projects. Default: true
svelte.plugin.svelte.defaultScriptLanguageThe default language to use when generating new script tags in Svelte. Default: none
svelte.plugin.svelte.documentHighlight.enableEnable document highlight support. Requires a restart. Default: true
Some projects rely on the @macroforge/typescript-plugin TypeScript plugin to
inject macro-generated APIs (for example toJSON() or toString() for classes
decorated with @derive). tsserver plugins are not guaranteed to load when the
Svelte language server runs inside sandboxed editor runtimes (Zed, WASM, etc.),
so we mirrored the plugin’s logic in the language server itself.
Implementation outline:
src/plugins/typescript/macroforgeAugmenter.ts contains the decorator scan and
interface generation logic extracted from the original plugin. It exposes a
small configuration struct (macroNames, mixinModule, mixinTypes) plus an
augmentWithMacroforges helper that rewrites source text when decorated classes
are found.src/plugins/typescript/service.ts) we read
any @macroforge/typescript-plugin entry from the workspace tsconfig and build
the augmentation config from it. The config travels with the parsed compiler
options and is passed to every snapshot factory.DocumentSnapshot applies the augmentation for both Svelte snapshots and
plain JS/TS snapshots (src/plugins/typescript/DocumentSnapshot.ts). The
rewritten text—including the synthetic mixin interfaces—is what the
TypeScript language service consumes, so diagnostics/completions in .svelte
files “see” the macro-generated methods even without tsserver plugin support.This keeps the plugin available for plain TypeScript projects (via VTSLS) while ensuring the Svelte LS behaves consistently in sandboxed environments.