8000 Improve schema type compliance, improve CONFIGURATION.md (#228) · JesusTorrado/python-lsp-server@50841c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 50841c1

Browse files
authored
Improve schema type compliance, improve CONFIGURATION.md (python-lsp#228)
1 parent 624b6d4 commit 50841c1

File tree

3 files changed

+79
-60
lines changed

3 files changed

+79
-60
lines changed

CONFIGURATION.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ This server can be configured using `workspace/didChangeConfiguration` method. E
33

44
| **Configuration Key** | **Type** | **Description** | **Default**
55
|----|----|----|----|
6-
| `pylsp.configurationSources` | `array` of unique `string` items | List of configuration sources to use. | `["pycodestyle"]` |
6+
| `pylsp.configurationSources` | `array` of unique `string` (one of: `pycodestyle`, `pyflakes`) items | List of configuration sources to use. | `["pycodestyle"]` |
77
| `pylsp.plugins.flake8.config` | `string` | Path to the config file that will be the authoritative config source. | `null` |
88
| `pylsp.plugins.flake8.enabled` | `boolean` | Enable or disable the plugin. | `false` |
9-
| `pylsp.plugins.flake8.exclude` | `array` | List of files or directories to exclude. | `null` |
9+
| `pylsp.plugins.flake8.exclude` | `array` of `string` items | List of files or directories to exclude. | `[]` |
1010
| `pylsp.plugins.flake8.executable` | `string` | Path to the flake8 executable. | `"flake8"` |
1111
| `pylsp.plugins.flake8.filename` | `string` | Only check for filenames matching the patterns in this list. | `null` |
1212
| `pylsp.plugins.flake8.hangClosing` | `boolean` | Hang closing bracket instead of matching indentation of opening bracket's line. | `null` |
13-
| `pylsp.plugins.flake8.ignore` | `array` | List of errors and warnings to ignore (or skip). | `null` |
13+
| `pylsp.plugins.flake8.ignore` | `array` of `string` items | List of errors and warnings to ignore (or skip). | `[]` |
1414
| `pylsp.plugins.flake8.maxLineLength` | `integer` | Maximum allowed line length for the entirety of this run. | `null` |
1515
| `pylsp.plugins.flake8.indentSize` | `integer` | Set indentation spaces. | `null` |
16-
| `pylsp.plugins.flake8.perFileIgnores` | `array` | A pairing of filenames and violation codes that defines which violations to ignore in a particular file, for example: `["file_path.py:W305,W304"]`). | `null` |
17-
| `pylsp.plugins.flake8.select` | `array` | List of errors and warnings to enable. | `null` |
18-
| `pylsp.plugins.jedi.extra_paths` | `array` | Define extra paths for jedi.Script. | `[]` |
16+
| `pylsp.plugins.flake8.perFileIgnores` | `array` of `string` items | A pairing of filenames and violation codes that defines which violations to ignore in a particular file, for example: `["file_path.py:W305,W304"]`). | `[]` |
17+
| `pylsp.plugins.flake8.select` | `array` of unique `string` items | List of errors and warnings to enable. | `null` |
18+
| `pylsp.plugins.jedi.extra_paths` | `array` of `string` items | Define extra paths for jedi.Script. | `[]` |
1919
| `pylsp.plugins.jedi.env_vars` | `object` | Define environment variables for jedi.Script and Jedi.names. | `null` |
2020
| `pylsp.plugins.jedi.environment` | `string` | Define environment for jedi.Script and Jedi.names. | `null` |
2121
| `pylsp.plugins.jedi_completion.enabled` | `boolean` | Enable or disable the plugin. | `true` |
@@ -24,7 +24,7 @@ This server can be configured using `workspace/didChangeConfiguration` method. E
2424
| `pylsp.plugins.jedi_completion.fuzzy` | `boolean` | Enable fuzzy when requesting autocomplete. | `false` |
2525
| `pylsp.plugins.jedi_completion.eager` | `boolean` | Resolve documentation and detail eagerly. | `false` |
2626
| `pylsp.plugins.jedi_completion.resolve_at_most` | `number` | How many labels and snippets (at most) should be resolved? | `25` |
27-
| `pylsp.plugins.jedi_completion.cache_for` | `array` of `string` items | Modules for which labels and snippets should be cached. | `["pandas", "numpy", "tensorflow", "matplotlib"]` |
27+
| `pylsp.plugins.jedi_completion.cache_for` | `array` of `string` items | Modules for which labels and snippets should be cached. | `["pandas", "numpy", "tensorflow", "matplotlib"]` |
2828
| `pylsp.plugins.jedi_definition.enabled` | `boolean` | Enable or disable the plugin. | `true` |
2929
| `pylsp.plugins.jedi_definition.follow_imports` | `boolean` | The goto call will follow imports. | `true` |
3030
| `pylsp.plugins.jedi_definition.follow_builtin_imports` | `boolean` | If follow_imports is True will decide if it follow builtin imports. | `true` |
@@ -37,31 +37,31 @@ This server can be configured using `workspace/didChangeConfiguration` method. E
3737
| `pylsp.plugins.mccabe.enabled` | `boolean` | Enable or disable the plugin. | `true` |
3838
| `pylsp.plugins.mccabe.threshold` | `number` | The minimum threshold that triggers warnings about cyclomatic complexity. | `15` |
3939
| `pylsp.plugins.preload.enabled` | `boolean` | Enable or disable the plugin. | `true` |
40-
| `pylsp.plugins.preload.modules` | `array` of unique `string` items | List of modules to import on startup | `null` |
40+
| `pylsp.plugins.preload.modules` | `array` of unique `string` items | List of modules to import on startup | `[]` |
4141
| `pylsp.plugins.pycodestyle.enabled` | `boolean` | Enable or disable the plugin. | `true` |
42-
| `pylsp.plugins.pycodestyle.exclude` | `array` of unique `string` items | Exclude files or directories which match these patterns. | `null` |
43-
| `pylsp.plugins.pycodestyle.filename` | `array` of unique `string` items | When parsing directories, only check filenames matching these patterns. | `null` |
44-
| `pylsp.plugins.pycodestyle.select` | `array` of unique `string` items | Select errors and warnings | `null` |
45-
| `pylsp.plugins.pycodestyle.ignore` | `array` of unique `string` items | Ignore errors and warnings | `null` |
42+
| `pylsp.plugins.pycodestyle.exclude` | `array` of unique `string` items | Exclude files or directories which match these patterns. | `[]` |
43+
| `pylsp.plugins.pycodestyle.filename` | `array` of unique `string` items | When parsing directories, only check filenames matching these patterns. | `[]` |
44+
| `pylsp.plugins.pycodestyle.select` | `array` of unique `string` items | Select errors and warnings | `[]` |
45+
| `pylsp.plugins.pycodestyle.ignore` | `array` of unique `string` items | Ignore errors and warnings | `[]` |
4646
| `pylsp.plugins.pycodestyle.hangClosing` | `boolean` | Hang closing bracket instead of matching indentation of opening bracket's line. | `null` |
4747
| `pylsp.plugins.pycodestyle.maxLineLength` | `number` | Set maximum allowed line length. | `null` |
4848
| `pylsp.plugins.pycodestyle.indentSize` | `integer` | Set indentation spaces. | `null` |
4949
| `pylsp.plugins.pydocstyle.enabled` | `boolean` | Enable or disable the plugin. | `false` |
50-
| `pylsp.plugins.pydocstyle.convention` | `string` | Choose the basic list of checked errors by specifying an existing convention. | `null` |
51-
| `pylsp.plugins.pydocstyle.addIgnore` | `array` of unique `string` items | Ignore errors and warnings in addition to the specified convention. | `null` |
52-
| `pylsp.plugins.pydocstyle.addSelect` | `array` of unique `string` items | Select errors and warnings in addition to the specified convention. | `null` |
53-
| `pylsp.plugins.pydocstyle.ignore` | `array` of unique `string` items | Ignore errors and warnings | `null` |
54-
| `pylsp.plugins.pydocstyle.select` | `array` of unique `string` items | Select errors and warnings | `null` |
50+
| `pylsp.plugins.pydocstyle.convention` | `string` (one of: `pep257`, `numpy`, `None`) | Choose the basic list of checked errors by specifying an existing convention. | `null` |
51+
| `pylsp.plugins.pydocstyle.addIgnore` | `array` of unique `string` items | Ignore errors and warnings in addition to the specified convention. | `[]` |
52+
| `pylsp.plugins.pydocstyle.addSelect` | `array` of unique `string` items | Select errors and warnings in addition to the specified convention. | `[]` |
53+
| `pylsp.plugins.pydocstyle.ignore` | `array` of unique `string` items | Ignore errors and warnings | `[]` |
54+
| `pylsp.plugins.pydocstyle.select` | `array` of unique `string` items | Select errors and warnings | `[]` |
5555
| `pylsp.plugins.pydocstyle.match` | `string` | Check only files that exactly match the given regular expression; default is to match files that don't start with 'test_' but end with '.py'. | `"(?!test_).*\\.py"` |
5656
| `pylsp.plugins.pydocstyle.matchDir` | `string` | Search only dirs that exactly match the given regular expression; default is to match dirs which do not begin with a dot. | `"[^\\.].*"` |
5757
| `pylsp.plugins.pyflakes.enabled` | `boolean` | Enable or disable the plugin. | `true` |
5858
| `pylsp.plugins.pylint.enabled` | `boolean` | Enable or disable the plugin. | `false` |
59-
| `pylsp.plugins.pylint.args` | `array` of non-unique `string` items | Arguments to pass to pylint. | `null` |
59+
| `pylsp.plugins.pylint.args` | `array` of non-unique `string` items | Arguments to pass to pylint. | `[]` |
6060
| `pylsp.plugins.pylint.executable` | `string` | Executable to run pylint with. Enabling this will run pylint on unsaved files via stdin. Can slow down workflow. Only works with python3. | `null` |
6161
| `pylsp.plugins.rope_completion.enabled` | `boolean` | Enable or disable the plugin. | `false` |
6262
| `pylsp.plugins.rope_completion.eager` | `boolean` | Resolve documentation and detail eagerly. | `false` |
6363
| `pylsp.plugins.yapf.enabled` | `boolean` | Enable or disable the plugin. | `true` |
6464
| `pylsp.rope.extensionModules` | `string` | Builtin and c-extension modules that are allowed to be imported and inspected by rope. | `null` |
65-
| `pylsp.rope.ropeFolder` | `array` of unique `string` items | The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all. | `null` |
65+
| `pylsp.rope.ropeFolder` | `array` of unique `string` items | The name of the folder in which rope stores project configurations and data. Pass `null` for not using such a folder at all. | `null` |
6666

6767
This documentation was generated from `pylsp/config/schema.json`. Please do not edit this file directly.

pylsp/config/schema.json

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"uniqueItems": true
1616
},
1717
"pylsp.plugins.flake8.config": {
18-
"type": "string",
18+
"type": ["string", "null"],
1919
"default": null,
2020
"description": "Path to the config file that will be the authoritative config source."
2121
},
@@ -26,7 +26,10 @@
2626
},
2727
"pylsp.plugins.flake8.exclude": {
2828
"type": "array",
29-
"default": null,
29+
"default": [],
30+
"items": {
31+
"type": "string"
32+
},
3033
"description": "List of files or directories to exclude."
3134
},
3235
"pylsp.plugins.flake8.executable": {
@@ -35,52 +38,65 @@
3538
"description": "Path to the flake8 executable."
3639
},
3740
"pylsp.plugins.flake8.filename": {
38-
"type": "string",
41+
"type": ["string", "null"],
3942
"default": null,
4043
"description": "Only check for filenames matching the patterns in this list."
4144
},
4245
"pylsp.plugins.flake8.hangClosing": {
43-
"type": "boolean",
46+
"type": ["boolean", "null"],
4447
"default": null,
4548
"description": "Hang closing bracket instead of matching indentation of opening bracket's line."
4649
},
4750
"pylsp.plugins.flake8.ignore": {
4851
"type": "array",
49-
"default": null,
52+
"default": [],
53+
"items": {
54+
"type": "string"
55+
},
5056
"description": "List of errors and warnings to ignore (or skip)."
5157
},
5258
"pylsp.plugins.flake8.maxLineLength": {
53-
"type": "integer",
59+
"type": ["integer", "null"],
5460
"default": null,
5561
"description": "Maximum allowed line length for the entirety of this run."
5662
},
5763
"pylsp.plugins.flake8.indentSize": {
58-
"type": "integer",
64+
"type": ["integer", "null"],
5965
"default": null,
6066
"description": "Set indentation spaces."
6167
},
6268
"pylsp.plugins.flake8.perFileIgnores": {
63-
"type": "array",
64-
"default": null,
69+
"type": ["array"],
70+
"default": [],
71+
"items": {
72+
"type": "string"
73+
},
6574
"description": "A pairing of filenames and violation codes that defines which violations to ignore in a particular file, for example: `[\"file_path.py:W305,W304\"]`)."
6675
},
6776
"pylsp.plugins.flake8.select": {
68-
"type": "array",
77+
"type": ["array", "null"],
6978
"default": null,
79+
"items": {
80+
"type": "string"
81+
},
82+
"uniqueItems": true,
7083
"description": "List of errors and warnings to enable."
7184
},
7285
"pylsp.plugins.jedi.extra_paths": {
7386
"type": "array",
7487
"default": [],
88+
"items": {
89+
"type": "string"
90+
},
7591
"description": "Define extra paths for jedi.Script."
7692
},
7793
"pylsp.plugins.jedi.env_vars": {
78-
"type": "object",
94+
"type": ["object", "null"],
7995
"default": null,
8096
"description": "Define environment variables for jedi.Script and Jedi.names."
8197
},
8298
"pylsp.plugins.jedi.environment": {
83-
"type": "string",
99+
"type": ["string", "null"],
84100
"default": null,
85101
"description": "Define environment for jedi.Script and Jedi.names."
86102
},
@@ -184,7 +200,7 @@
184200
},
185201
"pylsp.plugins.preload.modules": {
186202
"type": "array",
187-
"default": null,
203+
"default": [],
188204
"items": {
189205
"type": "string"
190206
},
@@ -198,7 +214,7 @@
198214
},
199215
"pylsp.plugins.pycodestyle.exclude": {
200216
"type": "array",
201-
"default": null,
217+
"default": [],
202218
"items": {
203219
"type": "string"
204220
},
@@ -207,7 +223,7 @@
207223
},
208224
"pylsp.plugins.pycodestyle.filename": {
209225
"type": "array",
210-
"default": null,
226+
"default": [],
211227
"items": {
212228
"type": "string"
213229
},
@@ -216,7 +232,7 @@
216232
},
217233
"pylsp.plugins.pycodestyle.select": {
218234
"type": "array",
219-
"default": null,
235+
"default": [],
220236
"items": {
221237
"type": "string"
222238
},
@@ -225,25 +241,25 @@
225241
},
226242
"pylsp.plugins.pycodestyle.ignore": {
227243
"type": "array",
228-
"default": null,
244+
"default": [],
229245
"items": {
230246
"type": "string"
231247
},
232248
"uniqueItems": true,
233249
"description": "Ignore errors and warnings"
234250
},
235251
"pylsp.plugins.pycodestyle.hangClosing": {
236-
"type": "boolean",
252+
"type": ["boolean", "null"],
237253
"default": null,
238254
"description": "Hang closing bracket instead of matching indentation of opening bracket's line."
239255
},
240256
"pylsp.plugins.pycodestyle.maxLineLength": {
241-
"type": "number",
257+
"type": ["number", "null"],
242258
"default": null,
243259
"description": "Set maximum allowed line length."
244260
},
245261
"pylsp.plugins.pycodestyle.indentSize": {
246-
"type": "integer",
262+
"type": ["integer", "null"],
247263
"default": null,
248264
"description": "Set indentation spaces."
249265
},
@@ -253,17 +269,14 @@
253269
"description": "Enable or disable the plugin."
254270
},
255271
"pylsp.plugins.pydocstyle.convention": {
256-
"type": "string",
272+
"type": ["string", "null"],
257273
"default": null,
258-
"enum": [
259-
"pep257",
260-
"numpy"
261-
],
274+
"enum": ["pep257", "numpy", null],
262275
"description": "Choose the basic list of checked errors by specifying an existing convention."
263276
},
264277
"pylsp.plugins.pydocstyle.addIgnore": {
265278
"type": "array",
266-
"default": null,
279+
"default": [],
267280
"items": {
268281
"type": "string"
269282
},
@@ -272,7 +285,7 @@
272285
},
273286
"pylsp.plugins.pydocstyle.addSelect": {
274287
"type": "array",
275-
"default": null,
288+
"default": [],
276289
"items": {
277290
"type": "string"
278291
},
@@ -281,7 +294,7 @@
281294
},
282295
"pylsp.plugins.pydocstyle.ignore": {
283296
"type": "array",
284-
"default": null,
297+
"default": [],
285298
"items": {
286299
"type": "string"
287300
},
@@ -290,7 +303,7 @@
290303
},
291304
"pylsp.plugins.pydocstyle.select": {
292305
"type": "array",
293-
"default": null,
306+
"default": [],
294307
"items": {
295308
"type": "string"
296309
},
@@ -319,15 +332,15 @@
319332
},
320333
"pylsp.plugins.pylint.args": {
321334
"type": "array",
322-
"default": null,
335+
"default": [],
323336
"items": {
324337
"type": "string"
325338
},
326339
"uniqueItems": false,
327340
"description": "Arguments to pass to pylint."
328341
},
329342
"pylsp.plugins.pylint.executable": {
330-
"type": "string",
343+
"type": ["string", "null"],
331344
"default": null,
332345
"description": "Executable to run pylint with. Enabling this will run pylint on unsaved files via stdin. Can slow down workflow. Only works with python3."
333346
},
@@ -347,12 +360,12 @@
347360
"description": "Enable or disable the plugin."
348361
},
349362
"pylsp.rope.extensionModules": {
350-
"type": "string",
363+
"type": ["null", "string"],
351364
"default": null,
352365
"description": "Builtin and c-extension modules that are allowed to be imported and inspected by rope."
353366
},
354367
"pylsp.rope.ropeFolder": {
355-
"type": "array",
368+
"type": ["null", "array"],
356369
"default": null,
357370
"items": {
358371
"type": "string"

scripts/jsonschema2md.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def describe_array(prop: dict) -> str:
1010
if "uniqueItems" in prop:
1111
unique_qualifier = "unique" if prop["uniqueItems"] else "non-unique"
1212
item_type = describe_type(prop["items"])
13-
extra += f" of {unique_qualifier} {item_type} items"
13+
extra = " ".join(filter(bool, ["of", unique_qualifier, item_type, "items"]))
1414
return extra
1515

1616

@@ -31,13 +31,19 @@ def describe_number(prop: dict) -> str:
3131

3232
def describe_type(prop: dict) -> str:
3333
prop_type = prop["type"]
34-
label = f"`{prop_type}`"
35-
if prop_type in EXTRA_DESCRIPTORS:
36-
label += " " + EXTRA_DESCRIPTORS[prop_type](prop)
37-
if "enum" in prop:
38-
allowed_values = [f"`{value}`" for value in prop["enum"]]
39-
label += "one of: " + ", ".join(allowed_values)
40-
return label
34+
types = prop_type if isinstance(prop_type, list) else [prop_type]
35+
if "null" in types:
36+
types.remove("null")
37+
if len(types) == 1:
38+
prop_type = types[0]
39+
parts = [f"`{prop_type}`"]
40+
for option in types:
41+
if option in EXTRA_DESCRIPTORS:
42+
parts.append(EXTRA_DESCRIPTORS[option](prop))
43+
if "enum" in prop:
44+
allowed_values = [f"`{value}`" for value in prop["enum"]]
45+
parts.append("(one of: " + ", ".join(allowed_values) + ")")
46+
return " ".join(parts)
4147

4248

4349
def convert_schema(schema: dict, source: str = None) -> str:

0 commit comments

Comments
 (0)
0