Skip to content

Commit 4d2859f

Browse files
authored
Merge branch 'python-lsp:develop' into advance-flake8
2 parents 9a6bba7 + d3f97f7 commit 4d2859f

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed

CONFIGURATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This server can be configured using `workspace/didChangeConfiguration` method. E
2222
| `pylsp.plugins.jedi_completion.enabled` | `boolean` | Enable or disable the plugin. | `true` |
2323
| `pylsp.plugins.jedi_completion.include_params` | `boolean` | Auto-completes methods and classes with tabstops for each parameter. | `true` |
2424
| `pylsp.plugins.jedi_completion.include_class_objects` | `boolean` | Adds class objects as a separate completion item. | `true` |
25+
| `pylsp.plugins.jedi_completion.include_function_objects` | `boolean` | Adds function objects as a separate completion item. | `true` |
2526
| `pylsp.plugins.jedi_completion.fuzzy` | `boolean` | Enable fuzzy when requesting autocomplete. | `false` |
2627
| `pylsp.plugins.jedi_completion.eager` | `boolean` | Resolve documentation and detail eagerly. | `false` |
2728
| `pylsp.plugins.jedi_completion.resolve_at_most` | `number` | How many labels and snippets (at most) should be resolved? | `25` |

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ If you get an error similar to `'install_requires' must be a string or list of s
4343
pip install -U setuptools
4444
```
4545

46+
### Windows and Linux installation
47+
48+
If you use Anaconda/Miniconda, you can install `python-lsp-server` using this conda command
49+
50+
```
51+
conda install -c conda-forge python-lsp-server
52+
```
53+
54+
Python-lsp-server is available in the repos of every major Linux distribution, and it is usually called `python-lsp-server`.
55+
56+
For example, here is how to install it in Debian and Debian-based distributions (E.g. Ubuntu, Pop!_OS, Linux Mint)
57+
58+
```
59+
sudo apt-get install python-lsp-server
60+
```
61+
62+
or Fedora Linux
63+
64+
```
65+
sudo dnf install python-lsp-server
66+
```
67+
68+
Only on Alpine Linux the package is named differently. You can install it there by typing this command in your terminal:
69+
70+
```
71+
apk add py3-lsp-server
72+
```
73+
4674
### 3rd Party Plugins
4775

4876
Installing these plugins will add extra functionality to the language server:

pylsp/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _hookexec(
3232
try:
3333
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
3434
except Exception as e: # pylint: disable=broad-except
35-
log.warning(f"Failed to load hook {hook_name}: {e}")
35+
log.warning(f"Failed to load hook {hook_name}: {e}", exc_info=True)
3636
return []
3737

3838

pylsp/config/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@
120120
"default": true,
121121
"description": "Adds class objects as a separate completion item."
122122
},
123+
"pylsp.plugins.jedi_completion.include_function_objects": {
124+
"type": "boolean",
125+
"default": true,
126+
"description": "Adds function objects as a separate completion item."
127+
},
123128
"pylsp.plugins.jedi_completion.fuzzy": {
124129
"type": "boolean",
125130
"default": false,

pylsp/plugins/jedi_completion.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def pylsp_completions(config, document, position):
5454

5555
should_include_params = settings.get('include_params')
5656
should_include_class_objects = settings.get('include_class_objects', True)
57+
should_include_function_objects = settings.get('include_function_objects', True)
5758

5859
max_to_resolve = settings.get('resolve_at_most', 25)
5960
modules_to_cache_for = settings.get('cache_for', None)
@@ -63,6 +64,7 @@ def pylsp_completions(config, document, position):
6364

6465
include_params = snippet_support and should_include_params and use_snippets(document, position)
6566
include_class_objects = snippet_support and should_include_class_objects and use_snippets(document, position)
67+
include_function_objects = snippet_support and should_include_function_objects and use_snippets(document, position)
6668

6769
ready_completions = [
6870
_format_completion(
@@ -88,6 +90,19 @@ def pylsp_completions(config, document, position):
8890
completion_dict['label'] += ' object'
8991
ready_completions.append(completion_dict)
9092

93+
if include_function_objects:
94+
for i, c in enumerate(completions):
95+
if c.type == 'function':
96+
completion_dict = _format_completion(
97+
c,
98+
False,
99+
resolve=resolve_eagerly,
100+
resolve_label_or_snippet=(i < max_to_resolve)
101+
)
102+
completion_dict['kind'] = lsp.CompletionItemKind.TypeParameter
103+
completion_dict['label'] += ' object'
104+
ready_completions.append(completion_dict)
105+
91106
for completion_dict in ready_completions:
92107
completion_dict['data'] = {
93108
'doc_uri': document.uri

test/plugins/test_completion.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,26 @@ def test_completion_with_class_objects(config, workspace):
356356
assert completions[1]['kind'] == lsp.CompletionItemKind.TypeParameter
357357

358358

359+
def test_completion_with_function_objects(config, workspace):
360+
doc_text = 'def foobar(): pass\nfoob'
361+
com_position = {'line': 1, 'character': 4}
362+
doc = Document(DOC_URI, workspace, doc_text)
363+
config.capabilities['textDocument'] = {
364+
'completion': {'completionItem': {'snippetSupport': True}}}
365+
config.update({'plugins': {'jedi_completion': {
366+
'include_params': True,
367+
'include_function_objects': True,
368+
}}})
369+
completions = pylsp_jedi_completions(config, doc, com_position)
370+
assert len(completions) == 2
371+
372+
assert completions[0]['label'] == 'foobar()'
373+
assert completions[0]['kind'] == lsp.CompletionItemKind.Function
374+
375+
assert completions[1]['label'] == 'foobar() object'
376+
assert completions[1]['kind'] == lsp.CompletionItemKind.TypeParameter
377+
378+
359379
def test_snippet_parsing(config, workspace):
360380
doc = 'divmod'
361381
completion_position = {'line': 0, 'character': 6}

0 commit comments

Comments
 (0)