Skip to content

Commit 2b19066

Browse files
committed
Convert settings to allow vscode-style setting strings
1 parent 5ba0ad6 commit 2b19066

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"lodash": "^4.17.15"
34
},
45
"devDependencies": {
56
"bash-language-server": "^1.6.1",
@@ -12,10 +13,10 @@
1213
"lerna": "^3.13.2",
1314
"precise-commits": "^1.0.2",
1415
"prettier": "^1.19.1",
16+
"tslint": "^5.15.0",
1517
"tslint-config-prettier": "^1.18.0",
1618
"tslint-plugin-prettier": "^2.0.1",
1719
"tslint-react": "^4.0.0",
18-
"tslint": "^5.15.0",
1920
"typescript": "~3.7.2",
2021
"unified-language-server": "^0.3.0",
2122
"vscode-css-languageserver-bin": "^1.4.0",

packages/jupyterlab-lsp/schema/plugin.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
"description": "Client and server configurations for a single language server",
2525
"type": "object",
2626
"default": {},
27-
"properties": {
28-
"settings": {
29-
"title": "Language Server Settings",
30-
"description": "Configuration to be sent to language server over LSP when initialized: see the specific language server's documentation for more",
31-
"type": "object",
32-
"default": {}
27+
"patternProperties": {
28+
"^.*$": {
29+
"anyOf": [
30+
{"type": "string"},
31+
{"type": "boolean"}
32+
]
3333
}
3434
}
3535
}

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 10 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 } from './utils';
6+
import { sleep, until_ready, vscodeStyleSettingsParser } from './utils';
77

88
// Name-only import so as to not trigger inclusion in main bundle
99
import * as ConnectionModuleType from './connection';
@@ -157,9 +157,14 @@ export class DocumentConnectionManager {
157157
lsSettings: any
158158
) {
159159
for (let language_server_id in lsSettings) {
160+
const parsedSettings = vscodeStyleSettingsParser(
161+
lsSettings[language_server_id]
162+
);
163+
160164
const serverSettings: ILanguageServerConfiguration = {
161-
settings: lsSettings
165+
settings: parsedSettings
162166
};
167+
163168
Private.updateServerConfiguration(language_server_id, serverSettings);
164169
}
165170
}
@@ -394,6 +399,9 @@ namespace Private {
394399
language_server_id: TLanguageServerId,
395400
settings: ILanguageServerConfiguration
396401
): void {
402+
console.log('Server Update: ', language_server_id);
403+
console.log('Sending settings: ', settings);
404+
397405
const connection = _connections.get(language_server_id);
398406
if (connection) {
399407
connection.sendConfigurationChange(settings);

packages/jupyterlab-lsp/src/utils.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash';
12
import { PageConfig } from '@jupyterlab/coreutils';
23

34
const RE_PATH_ANCHOR = /^file:\/\/([^\/]+|\/[A-Z]:)/;
@@ -130,3 +131,37 @@ export function uri_to_contents_path(child: string, parent?: string) {
130131
}
131132
return null;
132133
}
134+
135+
/**
136+
* The docs for many language servers show settings in the
137+
* VSCode format, e.g.: "pyls.plugins.pyflakes.enabled"
138+
*
139+
* VSCode converts that dot notation to JSON behind the scenes,
140+
* as the language servers themselves don't accept that syntax.
141+
*/
142+
const vscodeStyleSettingParser = (settingString: string, value: any) => {
143+
const propArr: any = settingString.split('.');
144+
const obj: any = {};
145+
146+
let curr = obj;
147+
propArr.forEach((prop: string, i: any) => {
148+
curr[prop] = {};
149+
150+
if (i === propArr.length - 1) {
151+
curr[prop] = value;
152+
} else {
153+
curr = curr[prop];
154+
}
155+
});
156+
157+
return obj;
158+
};
159+
160+
export const vscodeStyleSettingsParser = (settingsObject: any) => {
161+
const settings: any = [];
162+
for (let setting in settingsObject) {
163+
const parsed = vscodeStyleSettingParser(setting, settingsObject[setting]);
164+
settings.push(parsed);
165+
}
166+
return _.merge({}, ...settings);
167+
};

0 commit comments

Comments
 (0)