python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.9k stars 196 forks source link

Autocomplete does not insert imports #557

Open sblask opened 4 months ago

sblask commented 4 months ago

I think I have autocomplete set up in Neovim so it should work:

lspconfig["pylsp"].setup({
    on_attach = function(_client, buffer)
        setup_format_on_save(buffer)
    end,
    settings = {
        pylsp = {
            plugins = {
                jedi_completion = {
                    enabled = false,
                },
                rope_completion = {
                    enabled = true,
                },
                rope_autoimport = {
                    enabled = true,
                    completions = {
                        enabled = true,
                    },
                    code_actions = {
                        enabled = true,
                    },
                },
            },
        },
    },
})

and rope is installed alongside python-lsp-server:

$ ~/.opt/pylsp/bin/pip freeze
docstring-to-markdown==0.15
jedi==0.19.1
packaging==24.0
parso==0.8.3
platformdirs==4.2.1
pluggy==1.4.0
python-lsp-jsonrpc==1.1.2
python-lsp-server==1.11.0
pytoolconfig==1.3.1
rope==1.13.0
ujson==5.9.0

If I for example type typ followed by ctrl-x ctrl-o I get a completion menu:

Screenshot 2024-05-10 at 1 40 37 AM

Choosing types from the menu does complete the word, but I don't get an import for types. I couldn't find anything in the logs. Is there anything I am missing? Code actions are not available either, but that's another story.