9
9
JSONExt ,
10
10
ReadonlyPartialJSONObject ,
11
11
ReadonlyJSONObject ,
12
+ PartialJSONObject ,
12
13
PromiseDelegate
13
14
} from '@lumino/coreutils' ;
14
15
import { Signal , ISignal } from '@lumino/signaling' ;
@@ -74,6 +75,40 @@ function getDefaults(
74
75
return defaults ;
75
76
}
76
77
78
+ /**
79
+ * Get a mutable property matching a dotted key.
80
+ *
81
+ * Most LSP server schema properties are flattened using dotted convention,
82
+ * e.g. a key for {pylsp: {plugins: {flake8: {enabled: true}}}}` is stored
83
+ * as `pylsp.plugins.flake8.enabled`. However, some servers (e.g. pyright)
84
+ * define specific properties as only partially doted, for example
85
+ * `python.analysis.diagnosticSeverityOverrides` is an object with
86
+ * properties like `reportGeneralTypeIssues` or `reportPropertyTypeMismatch`.
87
+ * Only one level of nesting (on the finale level) is supported.
88
+ */
89
+ function findSchemaProperty (
90
+ properties : PartialJSONObject ,
91
+ key : string
92
+ ) : PartialJSONObject | null {
93
+ if ( properties . hasOwnProperty ( key ) ) {
94
+ return properties [ key ] as PartialJSONObject ;
95
+ }
96
+ const parts = key . split ( '.' ) ;
97
+ const prefix = parts . slice ( 0 , - 1 ) . join ( '.' ) ;
98
+ const suffix = parts [ parts . length - 1 ] ;
99
+ if ( properties . hasOwnProperty ( prefix ) ) {
100
+ const parent = properties [ prefix ] as PartialJSONObject ;
101
+ if ( parent . type !== 'object' ) {
102
+ return null ;
103
+ }
104
+ const parentProperties = parent . properties as PartialJSONObject ;
105
+ if ( parentProperties . hasOwnProperty ( suffix ) ) {
106
+ return parentProperties [ suffix ] as PartialJSONObject ;
107
+ }
108
+ }
109
+ return null ;
110
+ }
111
+
77
112
/**
78
113
* Schema and user data that for validation
79
114
*/
@@ -315,25 +350,24 @@ export class SettingsSchemaManager {
315
350
}
316
351
}
317
352
318
- // add default overrides from spec
353
+ // add default overrides from server-side spec (such as defined in `jupyter_server_config.py`)
319
354
const workspaceConfigurationDefaults =
320
355
serverSpec . workspace_configuration as Record < string , any > | undefined ;
321
356
if ( workspaceConfigurationDefaults ) {
322
357
for ( const [ key , value ] of Object . entries (
323
358
workspaceConfigurationDefaults
324
359
) ) {
325
- if ( ! configSchema . properties . hasOwnProperty ( key ) ) {
360
+ const property = findSchemaProperty ( configSchema . properties , key ) ;
361
+ if ( ! property ) {
326
362
this . console . warn (
327
- '`workspace_configuration` includes an override for key not in schema' ,
328
- key ,
329
- serverKey
363
+ `"workspace_configuration" includes an override for "${ key } " key which was not found in ${ serverKey } schema'`
330
364
) ;
331
365
continue ;
332
366
}
333
- configSchema . properties [ key ] . default = value ;
367
+ property . default = value ;
334
368
}
335
369
}
336
- // add server-specific default overrides from overrides.json (and pre-defined in schema)
370
+ // add server-specific default overrides from ` overrides.json` (and pre-defined in schema)
337
371
const serverDefaultsOverrides =
338
372
defaultsOverrides && defaultsOverrides . hasOwnProperty ( serverKey )
339
373
? defaultsOverrides [ serverKey ]
@@ -342,15 +376,14 @@ export class SettingsSchemaManager {
342
376
for ( const [ key , value ] of Object . entries (
343
377
serverDefaultsOverrides . serverSettings
344
378
) ) {
345
- if ( ! configSchema . properties . hasOwnProperty ( key ) ) {
379
+ const property = findSchemaProperty ( configSchema . properties , key ) ;
380
+ if ( ! property ) {
346
381
this . console . warn (
347
- '`overrides.json` includes an override for key not in schema' ,
348
- key ,
349
- serverKey
382
+ `"overrides.json" includes an override for "${ key } " key which was not found in ${ serverKey } schema`
350
383
) ;
351
384
continue ;
352
385
}
353
- configSchema . properties [ key ] . default = value ;
386
+ property . default = value as any ;
354
387
}
355
388
}
356
389
0 commit comments