8000 Implement sopme fixes for rope completions (#181) · brandonwillard/python-lsp-server@c4fd7a2 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit c4fd7a2

Browse files
authored
Implement sopme fixes for rope completions (python-lsp#181)
1 parent 698325d commit c4fd7a2

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pyls/_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _apply(impl):
4949
# imap unordered gives us an iterator over the items in the order they finish.
5050
# We have to be careful to set chunksize to 1 to ensure hooks each get their own thread.
5151
# Unfortunately, there's no way to interrupt these threads, so we just have to leave them be.
52-
first_impl, result = next(pool.imap_unordered(_apply, impls, chunksize=1))
53-
log.debug("Hook from plugin %s returned: %s", first_impl.plugin_name, result)
54-
return result
52+
for impl, result in pool.imap_unordered(_apply, impls, chunksize=1):
53+
if result is not None:
54+
log.debug("Hook from plugin %s returned: %s", impl.plugin_name, result)
55+
return result

pyls/plugins/rope_completion.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
@hookimpl
1212
def pyls_completions(document, position):
1313
log.debug('Launching Rope')
14-
mock_position = dict(position)
15-
mock_position['character'] -= 1
16-
word = document.word_at_position(mock_position)
14+
15+
# Rope is a bit rubbish at completing module imports, so we'll return None
16+
word = document.word_at_position({
17+
# The -1 should really be trying to look at the previous word, but that might be quite expensive
18+
# So we only skip import completions when the cursor is one space after `import`
19+
'line': position['line'], 'character': position['character'] - 1,
20+
})
1721
if word == 'import':
1822
return None
1923

pyls/python_ls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
33
from multiprocessing import dummy as multiprocessing
4-
54
from . import config, lsp, _utils
65
from .language_server import LanguageServer
76
from .workspace import Workspace
@@ -70,7 +69,7 @@ def completions(self, doc_uri, position):
7069
)
7170
return {
7271
'isIncomplete': False,
73-
'items': flatten(completions)
72+
'items': completions or []
7473
}
7574

7675
def definitions(self, doc_uri, position):

0 commit comments

Comments
 (0)
0