Care to share your pyls config?

Completely new to LSP and lua. I want to give it a try and compare to CoC, but I do not understand how to properly set options for the language server. Currently looking at enabling pylint and black (on save) for pyls. Could anyone share their config or let me know how to do this? I know this is completely basic, I am assuming I don’t have to go through a lua tutorial to get it to work. Just want to get from zero to A.
Thanks.

2 Likes

Hi, I use flake8 with jedi-language-server. Server config is on the 60th line you just have to uncomment it. I also use flake8 with diagnostic-language-server, but I’m going to switch to efm-ls in the near future. Here’s the relevant file: nvim/lsp.lua at master · kuator/nvim · GitHub

Thanks for your reply. So I have two follow up questions

Where did you find that structure starting from capabilities? That seems to be Jedi specific. After capabilities, I think it’s coming from here, though I am not sure how to read that documentation.

  -- nvim_lsp.jedi_language_server.setup{
  --   on_attach=on_attach,
  --   init_options = {
  --     disableSnippets = false,
  --   },
  --   capabilities = {
  --      textDocument = {
  --        completion = {
  --         completionItem = {
  --           snippetSupport=true
  --         }
  --        }
  --      }
  --   },
  -- }

Second tangent question. I think I derived the right structure for the setup of pyls (see below), but I don’t think it’s taking in. First I create a brand new virtual env then I open a python file. Since numpy is not installed I expected to get an error there, but it’s not there. I also get a warning for line too-long > 79 (which I set to 88 in my pylint config) that should not be there.
So it seems that it’s not using my virtual environment and it’s not using the pylintrc file that I specify in the config below. I often switch between different Python environment, so I need to easily have the linting and everything else switch to those other environment. With CoC I only had to set the interpreter. Not sure how LSP works in that regard. I can only assume it’s using the default system python (which I avoid like the plague as I prefer to screw up conda envs).

lua << EOF
local lsp=require('lspconfig')
lsp.pyls.setup{
    settings = {
        plugins = {
            pylint = {
                enabled = true,
                executable = 'pylint',
                args={'--rcfile', '~/.pylintrc'}
            }
        }
    }
}
EOF

The part with capabilities enables snippet support, it’s not jedi specific thought. I found it here: Snippets support · neovim/nvim-lspconfig Wiki · GitHub. I don’t know why pyls doesn’t pick up your config, to be honest. Do you source your virtual environment before you open up neovim? Terminal neovim doesn’t pick up venv, if it’s not sourced in the same shell instance.