Skip to content

Commit 36314ae

Browse files
authored
Merge pull request #856 from krassowski/set-workspace-config-in-schema
Allow to pass default workspace config (`serverSettings`) in specs
2 parents df1c7c3 + d481e8f commit 36314ae

File tree

11 files changed

+342
-199
lines changed

11 files changed

+342
-199
lines changed

atest/07_Configuration.robot

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ Python
1616
... undefined name 'foo' (pyflakes)
1717
... undefined name 'foo' (flake8)
1818

19+
Python (programmatically)
20+
[Documentation] same as "Python" but changing the defaults in server specification via `workspace_configuration`
21+
Settings Should Change Editor Diagnostics Python style.py pylsp-with-config-override
22+
... settings=100
23+
... before=undefined name 'foo' (pyflakes)
24+
... after=undefined name 'foo' (flake8)
25+
... setting_key=priority
26+
... needs reload=${True}
27+
1928
YAML
2029
[Documentation] Composer YAML files don't allow a "greetings" key
2130
Settings Should Change Editor Diagnostics YAML example.yaml yaml-language-server
@@ -47,7 +56,7 @@ LaTeX
4756

4857
*** Keywords ***
4958
Settings Should Change Editor Diagnostics
50-
[Arguments] ${language} ${file} ${server} ${settings} ${before} ${after} ${save command}=${EMPTY} ${needs reload}=${False}
59+
[Arguments] ${language} ${file} ${server} ${settings} ${before} ${after} ${save command}=${EMPTY} ${needs reload}=${False} ${setting_key}=serverSettings
5160
${before diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title*="${before}"]
5261
${after diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title*="${after}"]
5362
${tab} = Set Variable ${JLAB XP DOCK TAB}\[contains(., '${file}')]
@@ -65,7 +74,7 @@ Settings Should Change Editor Diagnostics
6574
END
6675
Page Should Not Contain ${after diagnostic}
6776
Capture Page Screenshot 01-default-diagnostics-and-settings.png
68-
Set Editor Content {"language_servers": {"${server}": {"serverSettings": ${settings}}}} ${CSS USER SETTINGS}
77+
Set Editor Content {"language_servers": {"${server}": {"${setting_key}": ${settings}}}} ${CSS USER SETTINGS}
6978
Wait Until Page Contains No errors found
7079
Capture Page Screenshot 02-default-diagnostics-and-unsaved-settings.png
7180
Click Element css:button[title^\='Save User Settings']

atest/Keywords.resource

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ Initialize Global Variables
4040
Create Notebok Server Config
4141
[Documentation] Copies in notebook server config file and updates accordingly
4242
[Arguments] ${server_extension_enabled}=${True}
43-
${conf} = Set Variable ${NOTEBOOK DIR}${/}${NBSERVER CONF}
43+
${conf} = Set Variable ${NOTEBOOK DIR}${/}${JPSERVER CONF JSON}
4444
${extra_node_roots} = Create List ${ROOT}
4545
${port} = Get Unused Port
4646
Set Global Variable ${PORT} ${port}
4747
Set Global Variable ${URL} http://localhost:${PORT}${BASE URL}
48-
Copy File ${FIXTURES}${/}${NBSERVER CONF} ${conf}
48+
Copy File ${FIXTURES}${/}${JPSERVER CONF JSON} ${conf}
49+
Copy File ${FIXTURES}${/}${JPSERVER CONF PY} ${NOTEBOOK DIR}${/}${JPSERVER CONF PY}
50+
Copy File ${FIXTURES}${/}overrides.json ${NOTEBOOK DIR}${/}overrides.json
4951
Update Jupyter Config ${conf} ServerApp
5052
... base_url=${BASE URL}
5153
... port=${PORT}

atest/Variables.resource

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Variables ***
22
${FIXTURES} ${CURDIR}${/}fixtures
3-
${NBSERVER CONF} jupyter_server_config.json
3+
${JPSERVER CONF JSON} jupyter_server_config.json
4+
${JPSERVER CONF PY} jupyter_server_config.py
45
${SPLASH} id:jupyterlab-splash
56
# to help catch hard-coded paths and encoding issues
67
${BASE URL} /@est/

atest/fixtures/jupyter_server_config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"tornado_settings": {
88
"page_config_data": {
99
"buildCheck": false,
10-
"buildAvailable": false
10+
"buildAvailable": false,
11+
"disabledExtensions": {
12+
"jupyterlab-unfold": true
13+
}
1114
}
1215
}
1316
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from jupyter_lsp.specs.python_lsp_server import PythonLSPServer
2+
from jupyter_lsp.types import LanguageServerManagerAPI
3+
4+
5+
manager: LanguageServerManagerAPI = None # type: ignore
6+
pylsp_base: dict = PythonLSPServer()(manager)
7+
8+
9+
c.LanguageServerManager.language_servers.update({
10+
"pylsp-with-config-override": {
11+
**pylsp_base["pylsp"],
12+
"display_name": "pylsp (with-config-override)",
13+
"workspace_configuration": {
14+
"pylsp.plugins.flake8.enabled": True,
15+
"pylsp.plugins.pyflakes.enabled": False
16+
}
17+
}
18+
})

atest/fixtures/overrides.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@jupyterlab/statusbar-extension:plugin": {
3+
"visible": true
4+
}
5+
}

packages/jupyterlab-lsp/src/components/serverSettings.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,22 @@ const TabbedObjectTemplateFactory = (options: {
210210
);
211211
};
212212
const renderServerMetadata = (spec: TLanguageServerSpec) => {
213+
const workspaceConfig = spec.workspace_configuration as Record<
214+
string,
215+
any
216+
>;
213217
return (
214218
<div>
215219
<h4 className={'lsp-ServerSettings-content-name'}>
216220
{spec.display_name}
217221
</h4>
218222
<ServerLinksList specification={spec} />
223+
{workspaceConfig ? (
224+
<p className={'lsp-ServerSettings-content-specOverrides'}>
225+
{trans.__('Default values set programatically for: ') +
226+
Object.keys(workspaceConfig).join(', ')}
227+
</p>
228+
) : null}
219229
</div>
220230
);
221231
};

packages/jupyterlab-lsp/src/index.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
ICodeOverridesRegistry,
5050
ILSPCodeOverridesManager
5151
} from './overrides/tokens';
52-
import { SettingsUIManager } from './settings';
52+
import { SettingsUIManager, SettingsSchemaManager } from './settings';
5353
import {
5454
IAdapterTypeOptions,
5555
ILSPAdapterManager,
@@ -154,7 +154,7 @@ export class LSPExtension implements ILSPExtension {
154154
connection_manager: DocumentConnectionManager;
155155
language_server_manager: LanguageServerManager;
156156
feature_manager: ILSPFeatureManager;
157-
private _settingsUI: SettingsUIManager;
157+
private _settingsSchemaManager: SettingsSchemaManager;
158158

159159
constructor(
160160
public app: JupyterFrontEnd,
@@ -201,42 +201,42 @@ export class LSPExtension implements ILSPExtension {
201201

202202
this.feature_manager = new FeatureManager();
203203

204-
this._settingsUI = new SettingsUIManager({
204+
this._settingsSchemaManager = new SettingsSchemaManager({
205205
settingRegistry: this.setting_registry,
206-
formRegistry: formRegistry,
207-
console: this.console.scope('SettingsUIManager'),
208206
languageServerManager: this.language_server_manager,
209207
trans: trans,
208+
console: this.console.scope('SettingsSchemaManager'),
210209
restored: app.restored
211210
});
212-
this._settingsUI
213-
.setupSchemaForUI(plugin.id)
211+
212+
if (formRegistry != null) {
213+
const settingsUI = new SettingsUIManager({
214+
settingRegistry: this.setting_registry,
215+
console: this.console.scope('SettingsUIManager'),
216+
languageServerManager: this.language_server_manager,
217+
trans: trans,
218+
schemaValidated: this._settingsSchemaManager.schemaValidated
219+
});
220+
// register custom UI field for `language_servers` property
221+
formRegistry.addRenderer(
222+
'language_servers',
223+
settingsUI.renderForm.bind(settingsUI)
224+
);
225+
}
226+
227+
this._settingsSchemaManager
228+
.setupSchemaTransform(plugin.id)
214229
.then(this._activate.bind(this))
215230
.catch(this._activate.bind(this));
216231
}
217232

218233
private _activate(): void {
219234
this.setting_registry
220235
.load(plugin.id)
221-
.then(settings => {
222-
const options = this._settingsUI.normalizeSettings(
223-
settings.composite as Required<LanguageServer>
224-
);
225-
226-
// Store the initial server settings, to be sent asynchronously
227-
// when the servers are initialized.
228-
const initial_configuration = (options.language_servers ||
229-
{}) as TLanguageServerConfigurations;
230-
this.connection_manager.initial_configurations = initial_configuration;
231-
// update the server-independent part of configuration immediately
232-
this.connection_manager.updateConfiguration(initial_configuration);
233-
this.connection_manager.updateLogging(
234-
options.logAllCommunication,
235-
options.setTrace
236-
);
237-
238-
settings.changed.connect(() => {
239-
this.updateOptions(settings);
236+
.then(async settings => {
237+
await this._updateOptions(settings, false);
238+
settings.changed.connect(async () => {
239+
await this._updateOptions(settings, true);
240240
});
241241
})
242242
.catch((reason: Error) => {
@@ -271,18 +271,28 @@ export class LSPExtension implements ILSPExtension {
271271
return this.code_overrides_manager.registry;
272272
}
273273

274-
private updateOptions(settings: ISettingRegistry.ISettings) {
275-
const options = this._settingsUI.normalizeSettings(
274+
private async _updateOptions(
275+
settings: ISettingRegistry.ISettings,
276+
afterInitialization = false
277+
) {
278+
const options = await this._settingsSchemaManager.normalizeSettings(
276279
settings.composite as Required<LanguageServer>
277280
);
278-
281+
// Store the initial server settings, to be sent asynchronously
282+
// when the servers are initialized.
279283
const languageServerSettings = (options.language_servers ||
280284
{}) as TLanguageServerConfigurations;
281285

282286
this.connection_manager.initial_configurations = languageServerSettings;
283287
// TODO: if priorities changed reset connections
288+
289+
// update the server-independent part of configuration immediately
284290
this.connection_manager.updateConfiguration(languageServerSettings);
285-
this.connection_manager.updateServerConfigurations(languageServerSettings);
291+
if (afterInitialization) {
292+
this.connection_manager.updateServerConfigurations(
293+
languageServerSettings
294+
);
295+
}
286296
this.connection_manager.updateLogging(
287297
options.logAllCommunication,
288298
options.setTrace

0 commit comments

Comments
 (0)