Skip to content

Commit e00fcf9

Browse files
committed
Allow to customize the modules to caching labels for in pandas
1 parent 0c8ea37 commit e00fcf9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CONFIGURATION.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This server can be configured using `workspace/didChangeConfiguration` method. E
1313
| `pylsp.plugins.jedi_completion.fuzzy` | `boolean` | Enable fuzzy when requesting autocomplete. | `false` |
1414
| `pylsp.plugins.jedi_completion.eager` | `boolean` | Resolve documentation and detail eagerly. | `false` |
1515
| `pylsp.plugins.jedi_completion.resolve_at_most_labels` | `number` | How many labels (at most) should be resolved? | `false` |
16+
| `pylsp.plugins.jedi_completion.cache_labels_for` | `array` of `string` items | Modules for which the labels should be cached. | `["pandas", "numpy", "tensorflow", "matplotlib"]` |
1617
| `pylsp.plugins.jedi_definition.enabled` | `boolean` | Enable or disable the plugin. | `true` |
1718
| `pylsp.plugins.jedi_definition.follow_imports` | `boolean` | The goto call will follow imports. | `true` |
1819
| `pylsp.plugins.jedi_definition.follow_builtin_imports` | `boolean` | If follow_imports is True will decide if it follow builtin imports. | `true` |

pylsp/config/schema.json

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
"default": false,
6060
"description": "How many labels (at most) should be resolved?"
6161
},
62+
"pylsp.plugins.jedi_completion.cache_labels_for": {
63+
"type": "array",
64+
"items": {
65+
"type": "string"
66+
},
67+
"default": ["pandas", "numpy", "tensorflow", "matplotlib"],
68+
"description": "Modules for which the labels should be cached."
69+
},
6270
"pylsp.plugins.jedi_definition.enabled": {
6371
"type": "boolean",
6472
"default": true,

pylsp/plugins/jedi_completion.py

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def pylsp_completions(config, document, position):
5858
should_include_class_objects = settings.get('include_class_objects', True)
5959

6060
max_labels_resolve = settings.get('resolve_at_most_labels', 25)
61+
modules_to_cache_labels_for = settings.get('cache_labels_for', None)
62+
if modules_to_cache_labels_for is not None:
63+
LABEL_RESOLVER.cached_modules = modules_to_cache_labels_for
6164

6265
include_params = snippet_support and should_include_params and use_snippets(document, position)
6366
include_class_objects = snippet_support and should_include_class_objects and use_snippets(document, position)
@@ -243,6 +246,14 @@ def __init__(self, format_label_callback, time_to_live=60 * 30):
243246
# see https://github.com/davidhalter/jedi/blob/master/jedi/inference/helpers.py#L194-L202
244247
self._cached_modules = {'pandas', 'numpy', 'tensorflow', 'matplotlib'}
245248

249+
@property
250+
def cached_modules(self):
251+
return self._cached_modules
252+
253+
@cached_modules.setter
254+
def cached_modules(self, new_value):
255+
self._cached_modules = set(new_value)
256+
246257
def clear_outdated(self):
247258
now = self.time_key()
248259
to_clear = [

0 commit comments

Comments
 (0)