Is there any way to make ycm's(Youcompleteme) diagnostics for python more convenient in vi

298 Views Asked by At

Ycm build-in in Jedi doesn't support diagnostics. I tried some ways, like YCM's LSP and Syntastics, but various problems appear when using other plugins.

For ycm, lsp, and pyright, it works well except hover. When I toggle on semantic completion and select words, a docstring displays in a popup with no problem. Only hover( <plug>(YCMHover) ) vimrc

...
let g:ycm_language_server += [
            \   {
            \       'name': 'pyright',
            \       'filetypes': [ 'python' ],
            \       'cmdline': [ 'node', substitute(system('which pyright-langserver'), '\n', '', ''), '--stdio' ],
            \   },
            \ ]
...

global_extra_conf.py

def Settings(**kwargs):
    return {
        "ls": {
            "python": {
                "analysis": {
                    "useLibraryCodeForTypes": True,
                    "typeCheckingMode": "basic",  # ["off", "basic", "strict"]
                    "logLevel": "Infomation",
                },
                "pythonPath": "/home/jizhou/venv/bin/python",
            }
        }
    }

For ycm lsp and jedi-language-server, hover doesn't work too. But it can't solve virtualenv. global_extra_conf.py

def Settings(**kwargs):
    return {
        "ls": {
            "diagnostic": {"enable": True},
            "hover": {"enable": True},
            "workspace": {
                "environmentPath": "~/venv/bin/python"
            },
        }
    }

For syntastics with pylint, syntastics plugin works well but performance and function problem usually appear. It can't check on insert mode exist. And if turn on check on open, it will slow down vim's starting up.

My question is:

Is there any way to make ycm not only complete the modules of the virtual environment, but also quickly check for errors like lsp without reducing the performance of vim, and at the same time ensure the normal operation of the hover function?

1

There are 1 best solutions below

0
ieeya On

At present, my solution is checking with syntastic with flake8 in virtualenv and completing with built-in Jedi. Note that a Python linter must be available in virtualenv, which means the package globally installed by pacman is invalid.

My view of syntastic is:

...
let g:syntastic_check_on_open = 0   " avoid slow on start up
let g:syntastic_python_checkers = ['flake8']
let g:syntastic_python_flake8_exec = "$HOME/venv/bin/flake8"
let g:syntastic_python_flake8_args = "--max-line-length=132"

let g:syntastic_cursor_column = 0 " disable to speed up navigation significantly
...

Moreover, I found that syntastic will report an error when close a split buffer. I forked and fixed this bug by add a silent, which can be install by

Plug 'ieeyaY/syntastic', {'branch': 'ieeyaFix'}