Skip to content

Commit 60c3101

Browse files
committed
initial autoimport work
1 parent 4bffc39 commit 60c3101

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

pylsp/config/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@
335335
"type": "boolean",
336336
"default": true,
337337
"description": "Enable or disable the plugin."
338+
},"pylsp.plugins.rope_autoimport.enabled": {
339+
"type": "boolean",
340+
"default": true,
341+
"description": "Enable or disable the plugin."
338342
},
339343
"pylsp.plugins.rope_completion.eager": {
340344
"type": "boolean",

pylsp/plugins/rope_autoimport.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import logging
2+
3+
from rope.contrib.autoimport import AutoImport
4+
5+
from pylsp import hookimpl, lsp
6+
from pylsp.config.config import Config
7+
from pylsp.workspace import Workspace
8+
9+
log = logging.getLogger(__name__)
10+
11+
12+
@hookimpl
13+
def pylsp_settings():
14+
# Default rope_completion to disabled
15+
return {"plugins": {"rope_autoimport": {"enabled": True}}}
16+
17+
18+
@hookimpl
19+
def pylsp_completions(config: Config, workspace: Workspace, document, position):
20+
rope_config = config.settings(document_path=document.path).get("rope", {})
21+
rope_project = workspace._rope_project_builder(rope_config)
22+
autoimport = AutoImport(rope_project, memory=False)
23+
autoimport.close()
24+
25+
26+
@hookimpl
27+
def pylsp_initialize(config: Config, workspace: Workspace):
28+
rope_config = config.settings().get("rope", {})
29+
rope_project = workspace._rope_project_builder(rope_config)
30+
autoimport = AutoImport(rope_project, memory=False)
31+
autoimport.generate_modules_cache()
32+
autoimport.close()

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pylsp =
7575
pylint = pylsp.plugins.pylint_lint
7676
rope_completion = pylsp.plugins.rope_completion
7777
rope_rename = pylsp.plugins.rope_rename
78+
rope_autoimport = pylsp.plugins.rope_autoimport
7879
yapf = pylsp.plugins.yapf_format
7980

8081
[pycodestyle]

0 commit comments

Comments
 (0)