1
1
import { PageConfig } from '@jupyterlab/coreutils' ;
2
+ import { ReadonlyJSONObject , ReadonlyJSONValue } from '@lumino/coreutils' ;
2
3
import mergeWith from 'lodash.mergewith' ;
3
4
4
5
const RE_PATH_ANCHOR = / ^ f i l e : \/ \/ ( [ ^ \/ ] + | \/ [ A - Z ] : ) / ;
@@ -139,15 +140,17 @@ export function uri_to_contents_path(child: string, parent?: string) {
139
140
* VSCode converts that dot notation to JSON behind the scenes,
140
141
* as the language servers themselves don't accept that syntax.
141
142
*/
142
- const vscodeStyleSettingParser = ( settingString : string , value : any ) => {
143
- const propArr = settingString . split ( '.' ) ;
143
+ export const expandPath = (
144
+ path : string [ ] ,
145
+ value : ReadonlyJSONValue
146
+ ) : ReadonlyJSONObject => {
144
147
const obj : any = { } ;
145
148
146
149
let curr = obj ;
147
- propArr . forEach ( ( prop : string , i : any ) => {
150
+ path . forEach ( ( prop : string , i : any ) => {
148
151
curr [ prop ] = { } ;
149
152
150
- if ( i === propArr . length - 1 ) {
153
+ if ( i === path . length - 1 ) {
151
154
curr [ prop ] = value ;
152
155
} else {
153
156
curr = curr [ prop ] ;
@@ -157,10 +160,12 @@ const vscodeStyleSettingParser = (settingString: string, value: any) => {
157
160
return obj ;
158
161
} ;
159
162
160
- export const vscodeStyleSettingsParser = ( settingsObject : any ) => {
163
+ export const expandDottedPaths = (
164
+ obj : ReadonlyJSONObject
165
+ ) : ReadonlyJSONObject => {
161
166
const settings : any = [ ] ;
162
- for ( let setting in settingsObject ) {
163
- const parsed = vscodeStyleSettingParser ( setting , settingsObject [ setting ] ) ;
167
+ for ( let key in obj ) {
168
+ const parsed = expandPath ( key . split ( '.' ) , obj [ key ] ) ;
164
169
settings . push ( parsed ) ;
165
170
}
166
171
return mergeWith ( { } , ...settings ) ;
0 commit comments