Skip to content

Commit 0339708

Browse files
authored
Merge pull request #919 from krassowski/overrides-fix
Fix `overrides.json` not being picked up in defaults
2 parents c2eba21 + a614259 commit 0339708

File tree

8 files changed

+538
-562
lines changed

8 files changed

+538
-562
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## Changelog
22

3+
### `@jupyter-lsp/jupyterlab-lsp 4.0.1` (unreleased)
4+
5+
- bug fixes
6+
- overrides from `overrides.json` are now picked up again ([#919])
7+
8+
### `jupyter-lsp 2.0.1` (unreleased)
9+
10+
- bug fixes:
11+
- pyright schema now includes required `python.` prefixes ([#919])
12+
13+
[#919]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/919
14+
315
### `@jupyter-lsp/jupyterlab-lsp 4.0.0` (2023-03-15)
416

517
Requires JupyterLab `>=3.6.0,<4.0.0a0` and Python 3.8 or newer.
@@ -9,6 +21,7 @@ Requires JupyterLab `>=3.6.0,<4.0.0a0` and Python 3.8 or newer.
921
- implement settings UI using native JupyterLab 3.3 UI ([#778])
1022
- add option to show hover tooltip automatically ([#864], thanks @yamaton)
1123
- implement eliding for long paths/files in completer ([#893])
24+
- allow to pass default workspace config (`serverSettings`) in specs ([#856])
1225
- bug fixes:
1326
- use correct websocket URL if configured as different from base URL ([#820], thanks @MikeSem)
1427
- clean up all completer styles when completer feature is disabled ([#829]).
@@ -50,6 +63,7 @@ Requires JupyterLab `>=3.6.0,<4.0.0a0` and Python 3.8 or newer.
5063
- performance:
5164
- `entry_point` discovery is deferred until server has started, improving
5265
`jupyter_server` startup time ([#852])
66+
- allow to pass default workspace config (`serverSettings`) in specs ([#856])
5367

5468
[#724]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/724
5569
[#738]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/738
@@ -63,6 +77,7 @@ Requires JupyterLab `>=3.6.0,<4.0.0a0` and Python 3.8 or newer.
6377
[#833]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/833
6478
[#836]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/836
6579
[#852]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/852
80+
[#856]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/856
6681
[#860]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/860
6782
[#864]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/864
6883
[#867]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/867

atest/07_Configuration.robot

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

19-
Python (programmatically)
19+
Python (server-side via overrides.json)
20+
[Documentation] same as "Python" but changing the defaults in server specification via `overrides.json`
21+
Settings Should Change Editor Diagnostics Python style.py pylsp-with-override-json
22+
... settings=100
23+
... before=undefined name 'foo' (pyflakes)
24+
... after=undefined name 'foo' (flake8)
25+
... setting_key=priority
26+
... needs reload=${True}
27+
28+
Python (server-side via spec)
2029
[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
30+
Settings Should Change Editor Diagnostics Python style.py pylsp-with-override-spec
2231
... settings=100
2332
... before=undefined name 'foo' (pyflakes)
2433
... after=undefined name 'foo' (flake8)

atest/Keywords.resource

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Resource Variables.resource
88
Library ./logcheck.py
99
Library ./ports.py
1010
Library ./config.py
11+
Library ./paths.py
1112

1213

1314
*** Keywords ***
@@ -41,13 +42,14 @@ Create Notebok Server Config
4142
Set Environment Variable
4243
... name=JUPYTER_CONFIG_DIR
4344
... value=${NOTEBOOK DIR}
45+
${jupyterlab_dir} = Get JupyterLab Path
4446
${extra_node_roots} = Create List ${ROOT}
4547
${port} = Get Unused Port
4648
Set Global Variable ${PORT} ${port}
4749
Set Global Variable ${URL} http://localhost:${PORT}${BASE URL}
4850
Copy File ${FIXTURES}${/}${JPSERVER CONF JSON} ${conf}
4951
Copy File ${FIXTURES}${/}${JPSERVER CONF PY} ${NOTEBOOK DIR}${/}${JPSERVER CONF PY}
50-
Copy File ${FIXTURES}${/}overrides.json ${NOTEBOOK DIR}${/}overrides.json
52+
Copy File ${FIXTURES}${/}overrides.json ${jupyterlab_dir}${/}settings${/}overrides.json
5153
Update Jupyter Config ${conf} ServerApp
5254
... base_url=${BASE URL}
5355
... port=${PORT}

atest/fixtures/jupyter_server_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88

99
c.LanguageServerManager.language_servers.update({
10-
"pylsp-with-config-override": {
10+
"pylsp-with-override-spec": {
1111
**pylsp_base["pylsp"],
12-
"display_name": "pylsp (with-config-override)",
12+
"display_name": "pylsp (with override via server spec)",
1313
"workspace_configuration": {
1414
"pylsp.plugins.flake8.enabled": True,
1515
"pylsp.plugins.pyflakes.enabled": False
1616
}
17+
},
18+
"pylsp-with-override-json": {
19+
**pylsp_base["pylsp"],
20+
"display_name": "pylsp (with override via overrides.json)"
1721
}
1822
})

atest/fixtures/overrides.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
2-
"@jupyterlab/statusbar-extension:plugin": {
3-
"visible": true
2+
"@jupyterlab/statusbar-extension:plugin": {
3+
"visible": true
4+
},
5+
"@jupyter-lsp/jupyterlab-lsp:plugin": {
6+
"language_servers": {
7+
"pylsp-with-override-json": {
8+
"serverSettings": {
9+
"pylsp.plugins.flake8.enabled": true,
10+
"pylsp.plugins.pyflakes.enabled": false
11+
}
12+
}
413
}
14+
}
515
}

atest/paths.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""work with jupyter paths"""
2+
3+
from jupyterlab.commands import get_app_dir
4+
5+
6+
def get_jupyterlab_path():
7+
"""Get JupyterLab Application Directory path"""
8+
return get_app_dir()

packages/jupyterlab-lsp/src/settings.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,15 @@ export class SettingsSchemaManager {
241241

242242
const defaults: Record<string, any> = {};
243243
const knownServersConfig: Record<string, any> = {};
244+
// `sharedDefaults` may be empty as we do not define/receive custom
245+
// per-property defaults in schema as of the day of writing.
244246
const sharedDefaults = getDefaults(
245247
schema.properties!.language_servers.properties
246248
);
249+
const defaultsOverrides = schema.properties!.language_servers.default as
250+
| Record<string, any>
251+
| undefined;
252+
247253
for (let [serverKey, serverSpec] of languageServerManager.specs.entries()) {
248254
if ((serverKey as string) === '') {
249255
this.console.warn(
@@ -324,6 +330,26 @@ export class SettingsSchemaManager {
324330
configSchema.properties[key].default = value;
325331
}
326332
}
333+
// add server-speficic default overrides from overrides.json (and pre-defined in schema)
334+
const serverDefaultsOverrides =
335+
defaultsOverrides && defaultsOverrides.hasOwnProperty(serverKey)
336+
? defaultsOverrides[serverKey]
337+
: {};
338+
if (serverDefaultsOverrides.serverSettings) {
339+
for (const [key, value] of Object.entries(
340+
serverDefaultsOverrides.serverSettings
341+
)) {
342+
if (!configSchema.properties.hasOwnProperty(key)) {
343+
this.console.warn(
344+
'`overrides.json` includes an override for key not in schema',
345+
key,
346+
serverKey
347+
);
348+
continue;
349+
}
350+
configSchema.properties[key].default = value;
351+
}
352+
}
327353

328354
const defaultMap = getDefaults(configSchema.properties);
329355

@@ -332,6 +358,7 @@ export class SettingsSchemaManager {
332358
knownServersConfig[serverKey] = baseSchemaCopy;
333359
defaults[serverKey] = {
334360
...sharedDefaults,
361+
...serverDefaultsOverrides,
335362
serverSettings: defaultMap
336363
};
337364
}

0 commit comments

Comments
 (0)