]> Sergey Matveev's repositories - dotfiles.git/blob - vim/.vim/pack/stargrave/start/py-flake8/autoload/python/lint.vim
10d3fc208aa0501ce754bb60bf4a49b3c32dfc00
[dotfiles.git] / vim / .vim / pack / stargrave / start / py-flake8 / autoload / python / lint.vim
1 vim9script
2
3 # Asynchronous pylint utility call
4 # Maintainer: Sergey Matveev <stargrave@stargrave.org>
5 # License: GNU General Public License version 3 of the License or later
6 #
7 # This plugin allows you to asynchronously call pylint.
8 #
9 # * Press <F6> to start pylint on current file
10 # * Press <S-F6> to open quickfix window with messages from pylint
11 # * All lines with corresponding pylint existing warning will be highlighted
12 # * If no warning and errors occurred, "pylint is clean" message will be shown
13 # * If existing quickfix window is found, then it won't be overwritten.
14 #   Start pylint manually (<F6>) to force its filling
15
16 export def Status(): string
17     if exists("b:pylint_job") && job_status(b:pylint_job) == "run" | return "LN" | endif
18     return ""
19 enddef
20
21 def Qffill(ch: channel)
22     var msgs = []
23     while ch_status(ch) == "buffered"
24         msgs = add(msgs, ch_read(ch))
25     endwhile
26     cgetexpr msgs
27 enddef
28
29 export def Finish(ch: channel)
30     var errorformat_bak = &errorformat
31     set errorformat=%f:%l:\ [%t]%m,%f:%l:%m
32     Qffill(ch)
33     &errorformat = errorformat_bak
34     sign unplace *
35     var id = 2
36     for item in getqflist()
37         if item.lnum == 0 | continue | endif
38         execute(":sign place " .. id ..
39             " name=LN line=" .. item.lnum .. " buffer=" .. item.bufnr)
40         id = id + 2
41     endfor
42     redraw!
43     if id == 2
44         echohl MoreMsg | echomsg "pylint is clean" | echohl None
45         cclose
46     endif
47 enddef
48
49 export def Start()
50     if exists("b:pylint_job") && job_status(b:pylint_job) == "run"
51         return
52     endif
53     var cmdline = [
54         "flake8",
55         "--ignore=E501",
56         "--format=%(path)s:%(row)d: [%(code)s] %(text)s",
57         "--max-line-length=90",
58         expand("%p")
59     ]
60     b:pylint_job = job_start(cmdline,
61         {"in_mode": "nl",  "err_io": "null", "close_cb": "python#lint#Finish"})
62 enddef