Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code completions to rope_autoimport plugin #471

Merged
merged 21 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
black
  • Loading branch information
tkrabel-db committed Oct 23, 2023
commit b97c0963d41e50b024fe3ae4e6586484922d71fb
4 changes: 3 additions & 1 deletion pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def pylsp_code_actions(
if "undefined name" not in diagnostic.get("message", "").lower():
continue
expr = parso.parse(document.lines[diagnostic["range"]["start"]["line"]])
word = expr.get_leaf_for_position((1, diagnostic["range"]["start"]["character"] + 1)).value
word = expr.get_leaf_for_position(
(1, diagnostic["range"]["start"]["character"] + 1)
).value
log.debug(f"autoimport: searching for word: {word}")
rope_config = config.settings(document_path=document.path).get("rope", {})
autoimport = workspace._rope_autoimport(rope_config, feature="code_actions")
Expand Down
1 change: 1 addition & 0 deletions pylsp/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, root_uri, endpoint, config=None):
self.__rope_config = None
# We have a sperate AutoImport object for each feature to avoid sqlite errors
tkrabel-db marked this conversation as resolved.
Show resolved Hide resolved
# from accessing the same database from multiple threads.
# An upstream fix discussion is here: https://github.com/python-rope/rope/issues/713
self.__rope_autoimport = (
{}
) # Type: Dict[Literal["completions", "code_actions"], rope.contrib.autoimport.sqlite.AutoImport]
Expand Down
5 changes: 4 additions & 1 deletion test/plugins/test_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ class sfa:


# Tests ruff, flake8 and pylfakes messages
tkrabel-db marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("message", ["Undefined name `os`", "F821 undefined name 'numpy'", "undefined name 'numpy'"])
@pytest.mark.parametrize(
"message",
["Undefined name `os`", "F821 undefined name 'numpy'", "undefined name 'numpy'"],
)
def test_autoimport_code_actions(config, autoimport_workspace, message):
source = "os"
autoimport_workspace.put_document(DOC_URI, source=source)
Expand Down
Loading