Skip to content

Commit

Permalink
Implement sopme fixes for rope completions (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Nov 2, 2017
1 parent 698325d commit c4fd7a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions pyls/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _apply(impl):
# imap unordered gives us an iterator over the items in the order they finish.
# We have to be careful to set chunksize to 1 to ensure hooks each get their own thread.
# Unfortunately, there's no way to interrupt these threads, so we just have to leave them be.
first_impl, result = next(pool.imap_unordered(_apply, impls, chunksize=1))
log.debug("Hook from plugin %s returned: %s", first_impl.plugin_name, result)
return result
for impl, result in pool.imap_unordered(_apply, impls, chunksize=1):
if result is not None:
log.debug("Hook from plugin %s returned: %s", impl.plugin_name, result)
return result
10 changes: 7 additions & 3 deletions pyls/plugins/rope_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
@hookimpl
def pyls_completions(document, position):
log.debug('Launching Rope')
mock_position = dict(position)
mock_position['character'] -= 1
word = document.word_at_position(mock_position)

# Rope is a bit rubbish at completing module imports, so we'll return None
word = document.word_at_position({
# The -1 should really be trying to look at the previous word, but that might be quite expensive
# So we only skip import completions when the cursor is one space after `import`
'line': position['line'], 'character': position['character'] - 1,
})
if word == 'import':
return None

Expand Down
3 changes: 1 addition & 2 deletions pyls/python_ls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
from multiprocessing import dummy as multiprocessing

from . import config, lsp, _utils
from .language_server import LanguageServer
from .workspace import Workspace
Expand Down Expand Up @@ -70,7 +69,7 @@ def completions(self, doc_uri, position):
)
return {
'isIncomplete': False,
'items': flatten(completions)
'items': completions or []
}

def definitions(self, doc_uri, position):
Expand Down

0 comments on commit c4fd7a2

Please sign in to comment.