A language server (implementing the language server protocol) for Svelte.
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:
- Svelte
- Diagnostic messages for warnings and errors
- Svelte specific formatting (via prettier-plugin-svelte)
- HTML (via vscode-html-languageservice)
- Hover info
- Autocompletions
- Emmet
- Symbols in Outline panel
- CSS / SCSS / LESS (via vscode-css-languageservice)
- TypeScript / JavaScript (via TypeScript)
- Diagnostics messages for syntax errors, semantic errors, and suggestions
- Hover info
- Formatting (via prettier)
- Symbols in Outline panel
- Autocompletions
- Go to definition
- Code Actions
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: { /* .. */ },
// ...
}
}
Enable the TypeScript plugin. Default: true
Enable diagnostic messages for TypeScript. Default: true
Enable hover info for TypeScript. Default: true
Enable document symbols for TypeScript. Default: true
Enable completions for TypeScript. Default: true
Enable code actions for TypeScript. Default: true
Enable selection range for TypeScript. Default: true
Enable signature help (parameter hints) for JS/TS. Default: true
Enable semantic tokens (semantic highlight) for TypeScript. Default: true
Enable the CSS plugin. Default: true
Which 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.
Enable diagnostic messages for CSS. Default: true
Enable hover info for CSS. Default: true
Enable auto completions for CSS. Default: true
Enable 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.
Enable document colors for CSS. Default: true
Enable color picker for CSS. Default: true
Enable document symbols for CSS. Default: true
Enable selection range for CSS. Default: true
Enable the HTML plugin. Default: true
Enable hover info for HTML. Default: true
Enable auto completions for HTML. Default: true
Enable 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.
Enable HTML tag auto closing. Default: true
Enable document symbols for HTML. Default: true
Enable Linked Editing for HTML. Default: true
Enable the Svelte plugin. Default: true
Enable diagnostic messages for Svelte. Default: true
Svelte compiler warning codes to ignore or to treat as errors. Example: { 'css-unused-selector': 'ignore', 'unused-export-let': 'error'}
Enable 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.
Format: 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.
More strict HTML syntax. Default: false
This option is ignored if there's any kind of configuration file, for example a .prettierrc
file.
Option 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.
Put 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.
Whether 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.
Maximum 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
Use 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
Enable hover info for Svelte (for tags like #if/#each). Default: true
Enable autocompletion for Svelte (for tags like #if/#each). Default: true
Enable rename/move Svelte files functionality. Default: true
Enable code actions for Svelte. Default: true
Enable selection range for Svelte. Default: true
The default language to use when generating new script tags in Svelte. Default: none
- James Birtles for creating the foundation which this language server is built on
- Vue's Vetur language server which heavily inspires this project