Skip to content

Commit 024c234

Browse files
committed
Initialize servers with saved settings
1 parent 60f34d7 commit 024c234

File tree

4 files changed

+75
-41
lines changed

4 files changed

+75
-41
lines changed

README.md

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -198,52 +198,54 @@ Server configurations can be edited using the Advanced Settings editor in Jupyte
198198

199199
```json
200200
{
201-
"language_servers": {
202-
"pyls": {
203-
"serverSettings": {
204-
"pyls.plugins.pydocstyle.enabled": true,
205-
"pyls.plugins.pyflakes.enabled": false,
206-
"pyls.plugins.flake8.enabled": true
207-
}
208-
},
209-
"r-languageserver": {
210-
"serverSettings": {
211-
"r.lsp.debug": false,
212-
"r.lsp.diagnostics": false
213-
}
214-
},
215-
"yaml-language-server": {
216-
"serverSettings": {
217-
"yaml.schemas": {
218-
"http://json.schemastore.org/composer": "/*"
219-
}
220-
}
221-
}
201+
"language_servers": {
202+
"pyls": {
203+
"serverSettings": {
204+
"pyls.plugins.pydocstyle.enabled": true,
205+
"pyls.plugins.pyflakes.enabled": false,
206+
"pyls.plugins.flake8.enabled": true
207+
}
208+
},
209+
"r-languageserver": {
210+
"serverSettings": {
211+
"r.lsp.debug": false,
212+
"r.lsp.diagnostics": false
213+
}
222214
},
215+
"yaml-language-server": {
216+
"serverSettings": {
217+
"yaml.schemas": {
218+
"http://json.schemastore.org/composer": "/*"
219+
}
220+
}
221+
}
222+
}
223223
}
224224
```
225+
225226
The `serverSettings` key specifies the configurations sent to the language servers. These can be written using stringified dot accessors like above (in the VSCode style), or as nested JSON objects, e.g.:
227+
226228
```json
227229
{
228-
"language_servers": {
229-
"pyls": {
230-
"serverSettings": {
231-
"pyls": {
232-
"plugins": {
233-
"pydocstyle": {
234-
"enabled": true
235-
},
236-
"pyflakes": {
237-
"enabled": false
238-
},
239-
"flake8": {
240-
"enabled": true
241-
}
242-
}
230+
"language_servers": {
231+
"pyls": {
232+
"serverSettings": {
233+
"pyls": {
234+
"plugins": {
235+
"pydocstyle": {
236+
"enabled": true
237+
},
238+
"pyflakes": {
239+
"enabled": false
240+
},
241+
"flake8": {
242+
"enabled": true
243243
}
244-
}
244+
}
245+
}
245246
}
246-
}
247+
}
248+
}
247249
}
248250
```
249251

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import * as ConnectionModuleType from './connection';
1010
import {
1111
TLanguageServerId,
1212
ILanguageServerManager,
13-
ILanguageServerConfiguration
13+
ILanguageServerConfiguration,
14+
TLanguageServerConfigurations
1415
} from './tokens';
1516

1617
export interface IDocumentConnectionData {
@@ -55,6 +56,7 @@ export class DocumentConnectionManager {
5556
Map<VirtualDocument.id_path, VirtualDocument>
5657
>;
5758
language_server_manager: ILanguageServerManager;
59+
initial_configurations: TLanguageServerConfigurations;
5860
private ignored_languages: Set<string>;
5961

6062
constructor(options: DocumentConnectionManager.IOptions) {
@@ -206,6 +208,9 @@ export class DocumentConnectionManager {
206208
// TODO: is this still neccessary, e.g. for status bar to update responsively?
207209
this.initialized.emit({ connection, virtual_document });
208210
});
211+
212+
// Initialize using settings stored in the SettingRegistry
213+
this.updateServerConfigurations(this.initial_configurations);
209214
});
210215

211216
connection.on('close', closed_manually => {

packages/jupyterlab-lsp/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
DocumentRegistry
4141
} from '@jupyterlab/docregistry/lib/registry';
4242
import { DocumentConnectionManager } from './connection_manager';
43+
import { TLanguageServerConfigurations } from './tokens';
4344

4445
const lsp_commands: Array<IFeatureCommand> = [].concat(
4546
...lsp_features.map(feature => feature.commands)
@@ -244,14 +245,19 @@ const plugin: JupyterFrontEndPlugin<void> = {
244245
// }
245246
// });
246247

247-
const languageServerSettings = options.language_servers || {};
248+
const languageServerSettings = (options.language_servers ||
249+
{}) as TLanguageServerConfigurations;
248250
connection_manager.updateServerConfigurations(languageServerSettings);
249251
}
250252

251253
settingRegistry
252254
.load(plugin.id)
253255
.then(settings => {
254-
updateOptions(settings);
256+
// Store the initial server settings, to be sent asynchronously
257+
// when the servers are initialized.
258+
connection_manager.initial_configurations = (settings.composite
259+
.language_servers || {}) as TLanguageServerConfigurations;
260+
255261
settings.changed.connect(() => {
256262
updateOptions(settings);
257263
});

packages/jupyterlab-lsp/src/tokens.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ export type TLanguageId = string;
88

99
export type TSessionMap = Map<TLanguageServerId, SCHEMA.LanguageServerSession>;
1010

11+
/**
12+
* TODO: Should this support custom server keys?
13+
*/
14+
export type TServerKeys =
15+
| 'pyls'
16+
| 'bash-language-server'
17+
| 'dockerfile-language-server-nodejs'
18+
| 'javascript-typescript-langserver'
19+
| 'unified-language-server'
20+
| 'vscode-css-languageserver-bin'
21+
| 'vscode-html-languageserver-bin'
22+
| 'vscode-json-languageserver-bin'
23+
| 'yaml-language-server'
24+
| 'r-languageserver';
25+
26+
export type TLanguageServerConfigurations = {
27+
[k in TServerKeys]: {
28+
serverSettings: any;
29+
};
30+
};
31+
1132
export interface ILanguageServerManager {
1233
sessionsChanged: ISignal<ILanguageServerManager, void>;
1334
sessions: TSessionMap;

0 commit comments

Comments
 (0)