0

I'm trying to use Neovim with Python, and I can't get autocomplete to work. I have created a minimal example of what I'm trying to do:

For this example, I'll run everything in a fresh Alpine container for environment isolation:

docker run -w /root -it --rm alpine:latest sh
apk add git nodejs neovim ripgrep build-base curl python3 --update

Create an example project with numpy in it.

python -m venv /root/myvenv
. /root/myvenv/bin/activate
pip install numpy

Use NvChad and enable python-lsp-server and the python treesitter plugin:

git clone https://github.com/NvChad/starter ~/.config/nvim
cat <<EOF > ~/.config/nvim/lua/plugins/init.lua
return {
  {
    "stevearc/conform.nvim",
    -- event = 'BufWritePre', -- uncomment for format on save
    config = function()
      require "configs.conform"
    end,
  },

  -- These are some examples, uncomment them if you want to see them work!
  {
    "neovim/nvim-lspconfig",
    config = function()
      require("nvchad.configs.lspconfig").defaults()
      require "configs.lspconfig"
    end,
  },

  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "lua-language-server", "stylua",
        "html-lsp", "css-lsp" , "prettier",
        "python-lsp-server"
      },
    },
  },

  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "vim", "lua", "vimdoc",
            "html", "css",
            "python"
      },
    },
  },
}
EOF

Open a new file:

nvim example.py

On the first start, nvim will load the required plugins. (I verified that they do load.) Once nvim is ready, type this in the file:

import numpy

numpy.linalg.matrix_power

This should autocomplete the matrix_power() function, but it doesn't suggest or complete this. Why not?

Edit:

Autocompletion happens automatically, but this is what it shows: (No numpy methods at all.)

Broken autocompletion

2
  • Are you pressing any completion keys? It looks like you are asking why typing the name of a function doesn't automatically complete the function; see :help ins-completion. Usually one presses C-x and another key to trigger completion. (Thanks for the minimal example, btw.)
    – D. Ben Knoble
    Commented May 28 at 17:01
  • With the variety of vim configurations, that's something to consider, but with NvChad, autocompletion happens automatically. I updated my question to include a screenshot of what I see.
    – Travis
    Commented May 28 at 18:21

1 Answer 1

0

I figured it out.

From the list of LSP servers, I found I needed to install python-lsp-server like so:

apk add py3-lsp-server

Then I needed to edit ~/.config/nvim/lua/configs/lspconfig.lua to add pylsp to servers like so:

local servers = { "html", "cssls", "pylsp" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.