Skip to content

Commit 85e35e4

Browse files
authored
(chore) language server restructure (#891)
- move docs on settings into language server readme and add some explanatory comments about how to set them for non-VS Code users - trim README of VS Code accordingly - harmonize configuration structure of initialize/update in a backwards-compatible way
1 parent d612204 commit 85e35e4

File tree

4 files changed

+274
-204
lines changed

4 files changed

+274
-204
lines changed

packages/language-server/README.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,253 @@ Install a plugin for your editor:
5050

5151
- [VS Code](../svelte-vscode)
5252

53+
## Settings
54+
55+
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.
56+
57+
When using the language server directly, put the settings as JSON inside `initializationOptions.configuration` for the [initialize command](https://microsoft.github.io/language-server-protocol/specification#initialize). When using the [didChangeConfiguration command](https://microsoft.github.io/language-server-protocol/specification#workspace_didChangeConfiguration), pass the JSON directly. The language server also accepts configuration for Emmet (key: `emmet`), Prettier (key: `prettier`) and TypeScript (keys: `javascript` and `typescript` for JS/TS config).
58+
59+
Example:
60+
61+
Init:
62+
63+
```js
64+
{
65+
initializationOptions: {
66+
configuration: {
67+
svelte: {
68+
plugin: {
69+
css: { enable: false },
70+
// ...
71+
}
72+
},
73+
typescript: { /* .. */ },
74+
javascript: { /* .. */ },
75+
prettierConfig: { /* .. */ },
76+
// ...
77+
}
78+
}
79+
}
80+
```
81+
82+
Update:
83+
84+
```js
85+
{
86+
svelte: {
87+
plugin: {
88+
css: { enable: false },
89+
// ...
90+
}
91+
},
92+
typescript: { /* .. */ },
93+
javascript: { /* .. */ },
94+
prettierConfig: { /* .. */ },
95+
// ...
96+
}
97+
}
98+
```
99+
100+
### List of settings
101+
102+
##### `svelte.plugin.typescript.enable`
103+
104+
Enable the TypeScript plugin. _Default_: `true`
105+
106+
##### `svelte.plugin.typescript.diagnostics.enable`
107+
108+
Enable diagnostic messages for TypeScript. _Default_: `true`
109+
110+
##### `svelte.plugin.typescript.hover.enable`
111+
112+
Enable hover info for TypeScript. _Default_: `true`
113+
114+
##### `svelte.plugin.typescript.documentSymbols.enable`
115+
116+
Enable document symbols for TypeScript. _Default_: `true`
117+
118+
##### `svelte.plugin.typescript.completions.enable`
119+
120+
Enable completions for TypeScript. _Default_: `true`
121+
122+
##### `svelte.plugin.typescript.findReferences.enable`
123+
124+
Enable find-references for TypeScript. _Default_: `true`
125+
126+
##### `svelte.plugin.typescript.definitions.enable`
127+
128+
Enable go to definition for TypeScript. _Default_: `true`
129+
130+
##### `svelte.plugin.typescript.codeActions.enable`
131+
132+
Enable code actions for TypeScript. _Default_: `true`
133+
134+
##### `svelte.plugin.typescript.selectionRange.enable`
135+
136+
Enable selection range for TypeScript. _Default_: `true`
137+
138+
##### `svelte.plugin.typescript.rename.enable`
139+
140+
Enable rename functionality for JS/TS variables inside Svelte files. _Default_: `true`
141+
142+
##### `svelte.plugin.typescript.signatureHelp.enable`
143+
144+
Enable signature help (parameter hints) for JS/TS. _Default_: `true`
145+
146+
##### `svelte.plugin.typescript.semanticTokens.enable`
147+
148+
Enable semantic tokens (semantic highlight) for TypeScript. Doesn't apply to JavaScript. _Default_: `true`
149+
150+
##### `svelte.plugin.css.enable`
151+
152+
Enable the CSS plugin. _Default_: `true`
153+
154+
##### `svelte.plugin.css.globals`
155+
156+
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.
157+
158+
##### `svelte.plugin.css.diagnostics.enable`
159+
160+
Enable diagnostic messages for CSS. _Default_: `true`
161+
162+
##### `svelte.plugin.css.hover.enable`
163+
164+
Enable hover info for CSS. _Default_: `true`
165+
166+
##### `svelte.plugin.css.completions.enable`
167+
168+
Enable auto completions for CSS. _Default_: `true`
169+
170+
##### `svelte.plugin.css.completions.emmet`
171+
172+
Enable emmet auto completions for CSS. _Default_: `true`
173+
If you want to disable emmet completely everywhere (not just Svelte), you can also set `"emmet.showExpandedAbbreviation": "never"` in your settings.
174+
175+
##### `svelte.plugin.css.documentColors.enable`
176+
177+
Enable document colors for CSS. _Default_: `true`
178+
179+
##### `svelte.plugin.css.colorPresentations.enable`
180+
181+
Enable color picker for CSS. _Default_: `true`
182+
183+
##### `svelte.plugin.css.documentSymbols.enable`
184+
185+
Enable document symbols for CSS. _Default_: `true`
186+
187+
##### `svelte.plugin.css.selectionRange.enable`
188+
189+
Enable selection range for CSS. _Default_: `true`
190+
191+
##### `svelte.plugin.html.enable`
192+
193+
Enable the HTML plugin. _Default_: `true`
194+
195+
##### `svelte.plugin.html.hover.enable`
196+
197+
Enable hover info for HTML. _Default_: `true`
198+
199+
##### `svelte.plugin.html.completions.enable`
200+
201+
Enable auto completions for HTML. _Default_: `true`
202+
203+
##### `svelte.plugin.html.completions.emmet`
204+
205+
Enable emmet auto completions for HTML. _Default_: `true`
206+
If you want to disable emmet completely everywhere (not just Svelte), you can also set `"emmet.showExpandedAbbreviation": "never"` in your settings.
207+
208+
##### `svelte.plugin.html.tagComplete.enable`
209+
210+
Enable HTML tag auto closing. _Default_: `true`
211+
212+
##### `svelte.plugin.html.documentSymbols.enable`
213+
214+
Enable document symbols for HTML. _Default_: `true`
215+
216+
##### `svelte.plugin.html.linkedEditing.enable`
217+
218+
Enable Linked Editing for HTML. _Default_: `true`
219+
220+
##### `svelte.plugin.html.renameTags.enable`
221+
222+
Enable rename tags for the opening/closing tag pairs in HTML. _Default_: `true`
223+
224+
##### `svelte.plugin.svelte.enable`
225+
226+
Enable the Svelte plugin. _Default_: `true`
227+
228+
##### `svelte.plugin.svelte.diagnostics.enable`
229+
230+
Enable diagnostic messages for Svelte. _Default_: `true`
231+
232+
##### `svelte.plugin.svelte.compilerWarnings`
233+
234+
Svelte compiler warning codes to ignore or to treat as errors. Example: { 'css-unused-selector': 'ignore', 'unused-export-let': 'error'}
235+
236+
##### `svelte.plugin.svelte.format.enable`
237+
238+
Enable formatting for Svelte (includes css & js) using [prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte). _Default_: `true`
239+
240+
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](https://prettier.io/docs/en/configuration.html).
241+
242+
##### `svelte.plugin.svelte.format.config.svelteSortOrder`
243+
244+
Format: join the keys `options`, `scripts`, `markup`, `styles` with a `-` in the order you want. _Default_: `options-scripts-markup-styles`
245+
246+
This option is ignored if there's any kind of configuration file, for example a `.prettierrc` file.
247+
248+
##### `svelte.plugin.svelte.format.config.svelteStrictMode`
249+
250+
More strict HTML syntax. _Default_: `false`
251+
252+
This option is ignored if there's any kind of configuration file, for example a `.prettierrc` file.
253+
254+
##### `svelte.plugin.svelte.format.config.svelteAllowShorthand`
255+
256+
Option to enable/disable component attribute shorthand if attribute name and expression are the same. _Default_: `true`
257+
258+
This option is ignored if there's any kind of configuration file, for example a `.prettierrc` file.
259+
260+
##### `svelte.plugin.svelte.format.config.svelteBracketNewLine`
261+
262+
Put the `>` of a multiline element on a new line. _Default_: `true`
263+
264+
This option is ignored if there's any kind of configuration file, for example a `.prettierrc` file.
265+
266+
##### `svelte.plugin.svelte.format.config.svelteIndentScriptAndStyle`
267+
268+
Whether or not to indent code inside `<script>` and `<style>` tags. _Default_: `true`
269+
270+
This option is ignored if there's any kind of configuration file, for example a `.prettierrc` file.
271+
272+
##### `svelte.plugin.svelte.format.config.printWidth`
273+
274+
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`
275+
276+
##### `svelte.plugin.svelte.format.config.singleQuote`
277+
278+
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`
279+
280+
##### `svelte.plugin.svelte.hover.enable`
281+
282+
Enable hover info for Svelte (for tags like #if/#each). _Default_: `true`
283+
284+
##### `svelte.plugin.svelte.completions.enable`
285+
286+
Enable autocompletion for Svelte (for tags like #if/#each). _Default_: `true`
287+
288+
##### `svelte.plugin.svelte.rename.enable`
289+
290+
Enable rename/move Svelte files functionality. _Default_: `true`
291+
292+
##### `svelte.plugin.svelte.codeActions.enable`
293+
294+
Enable code actions for Svelte. _Default_: `true`
295+
296+
##### `svelte.plugin.svelte.selectionRange.enable`
297+
298+
Enable selection range for Svelte. _Default_: `true`
299+
53300
## Credits
54301

55302
- [UnwrittenFun](https://github.com/UnwrittenFun) for creating the foundation which this language server is built on

packages/language-server/src/server.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,27 @@ export function startServer(options?: LSOptions) {
105105
watcher.onDidChangeWatchedFiles(onDidChangeWatchedFiles);
106106
}
107107

108-
configManager.update(evt.initializationOptions?.config || {});
109-
configManager.updateTsJsUserPreferences(evt.initializationOptions?.typescriptConfig || {});
110-
configManager.updateEmmetConfig(evt.initializationOptions?.emmetConfig || {});
111-
configManager.updatePrettierConfig(evt.initializationOptions?.prettierConfig || {});
108+
// Backwards-compatible way of setting initialization options (first `||` is the old style)
109+
configManager.update(
110+
evt.initializationOptions?.configuration?.svelte?.plugin ||
111+
evt.initializationOptions?.config ||
112+
{}
113+
);
114+
configManager.updateTsJsUserPreferences(
115+
evt.initializationOptions?.configuration ||
116+
evt.initializationOptions?.typescriptConfig ||
117+
{}
118+
);
119+
configManager.updateEmmetConfig(
120+
evt.initializationOptions?.configuration?.emmet ||
121+
evt.initializationOptions?.emmetConfig ||
122+
{}
123+
);
124+
configManager.updatePrettierConfig(
125+
evt.initializationOptions?.configuration?.prettier ||
126+
evt.initializationOptions?.prettierConfig ||
127+
{}
128+
);
112129

113130
pluginHost.initialize({
114131
filterIncompleteCompletions: !evt.initializationOptions

0 commit comments

Comments
 (0)