Skip to content

Commit c507ee0

Browse files
committed
Update utils with better typing
1 parent 024c234 commit c507ee0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { LSPConnection } from './connection';
33

44
import { Signal } from '@lumino/signaling';
55
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
6-
import { sleep, until_ready, vscodeStyleSettingsParser } from './utils';
6+
import { sleep, until_ready, expandDottedPaths } from './utils';
77

88
// Name-only import so as to not trigger inclusion in main bundle
99
import * as ConnectionModuleType from './connection';
@@ -162,7 +162,7 @@ export class DocumentConnectionManager {
162162
*/
163163
public updateServerConfigurations(allServerSettings: any) {
164164
for (let language_server_id in allServerSettings) {
165-
const parsedSettings = vscodeStyleSettingsParser(
165+
const parsedSettings = expandDottedPaths(
166166
allServerSettings[language_server_id].serverSettings
167167
);
168168

packages/jupyterlab-lsp/src/utils.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PageConfig } from '@jupyterlab/coreutils';
2+
import { ReadonlyJSONObject, ReadonlyJSONValue } from '@lumino/coreutils';
23
import mergeWith from 'lodash.mergewith';
34

45
const RE_PATH_ANCHOR = /^file:\/\/([^\/]+|\/[A-Z]:)/;
@@ -139,15 +140,17 @@ export function uri_to_contents_path(child: string, parent?: string) {
139140
* VSCode converts that dot notation to JSON behind the scenes,
140141
* as the language servers themselves don't accept that syntax.
141142
*/
142-
const vscodeStyleSettingParser = (settingString: string, value: any) => {
143-
const propArr = settingString.split('.');
143+
export const expandPath = (
144+
path: string[],
145+
value: ReadonlyJSONValue
146+
): ReadonlyJSONObject => {
144147
const obj: any = {};
145148

146149
let curr = obj;
147-
propArr.forEach((prop: string, i: any) => {
150+
path.forEach((prop: string, i: any) => {
148151
curr[prop] = {};
149152

150-
if (i === propArr.length - 1) {
153+
if (i === path.length - 1) {
151154
curr[prop] = value;
152155
} else {
153156
curr = curr[prop];
@@ -157,10 +160,12 @@ const vscodeStyleSettingParser = (settingString: string, value: any) => {
157160
return obj;
158161
};
159162

160-
export const vscodeStyleSettingsParser = (settingsObject: any) => {
163+
export const expandDottedPaths = (
164+
obj: ReadonlyJSONObject
165+
): ReadonlyJSONObject => {
161166
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]);
164169
settings.push(parsed);
165170
}
166171
return mergeWith({}, ...settings);

0 commit comments

Comments
 (0)