Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrabel-db committed Oct 22, 2023
1 parent a442e3b commit 6703485
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 13 additions & 5 deletions pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2022- Python Language Server Contributors.

import code
import logging
from typing import Any, Dict, Generator, List, Optional, Set, Union

Expand Down Expand Up @@ -164,7 +163,7 @@ def _process_statements(
"kind": "quickfix",
"edit": {"changes": {doc_uri: [edit]}},
# data is a supported field for codeAction responses
# See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction
# See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction # pylint: disable=line-too-long
"data": {"sortText": _sort_import(score)},
}
else:
Expand Down Expand Up @@ -202,7 +201,9 @@ def pylsp_completions(
suggestions = list(autoimport.search_full(word, ignored_names=ignored_names))
results = list(
sorted(
_process_statements(suggestions, document.uri, word, autoimport, document, "completions"),
_process_statements(
suggestions, document.uri, word, autoimport, document, "completions"
),
key=lambda statement: statement["sortText"],
)
)
Expand Down Expand Up @@ -238,7 +239,7 @@ def pylsp_code_actions(
config: Config,
workspace: Workspace,
document: Document,
range: Dict,
range: Dict, # pylint: disable=redefined-builtin
context: Dict,
) -> List[Dict]:
"""
Expand Down Expand Up @@ -274,7 +275,14 @@ def pylsp_code_actions(
log.debug("autoimport: suggestions: %s", suggestions)
results = list(
sorted(
_process_statements(suggestions, document.uri, word, autoimport, document, "code_actions"),
_process_statements(
suggestions,
document.uri,
word,
autoimport,
document,
"code_actions",
),
key=lambda statement: statement["data"]["sortText"],
)
)
Expand Down
18 changes: 11 additions & 7 deletions test/plugins/test_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ def autoimport_workspace(tmp_path_factory) -> Workspace:
uris.from_fs_path(str(tmp_path_factory.mktemp("pylsp"))), Mock()
)
workspace._config = Config(workspace.root_uri, {}, 0, {})
workspace._config.update({"rope_autoimport": {"memory": True, "completions": {"enabled": True}, "code_actions": {"enabled": True}}})
workspace._config.update(
{
"rope_autoimport": {
"memory": True,
"completions": {"enabled": True},
"code_actions": {"enabled": True},
}
}
)
pylsp_initialize(workspace._config, workspace)
yield workspace
workspace.close()
Expand Down Expand Up @@ -181,9 +189,7 @@ def test_autoimport_code_actions(config, autoimport_workspace):
config, autoimport_workspace, doc, None, context
)
autoimport_workspace.rm_document(DOC_URI)
assert any(
action.get("title") == "import os" for action in actions
)
assert any(action.get("title") == "import os" for action in actions)


class TestShouldInsert:
Expand Down Expand Up @@ -266,9 +272,7 @@ def test_autoimport_completions_for_notebook_document(
"plugins": {
"rope_autoimport": {
"memory": True,
"completions": {
"enabled": True
},
"completions": {"enabled": True},
},
}
}
Expand Down

0 comments on commit 6703485

Please sign in to comment.