]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Async flake8
authorSergey Matveev <stargrave@stargrave.org>
Tue, 4 Apr 2023 11:59:16 +0000 (14:59 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 4 Apr 2023 13:04:00 +0000 (16:04 +0300)
vim/.vim/pack/stargrave/start/py-flake8/autoload/python/lint.vim [new file with mode: 0644]
vim/.vim/pack/stargrave/start/py-flake8/ftplugin/lint.vim [new file with mode: 0644]
vim/.vim/plugin/lsp.vim

diff --git a/vim/.vim/pack/stargrave/start/py-flake8/autoload/python/lint.vim b/vim/.vim/pack/stargrave/start/py-flake8/autoload/python/lint.vim
new file mode 100644 (file)
index 0000000..10d3fc2
--- /dev/null
@@ -0,0 +1,62 @@
+vim9script
+
+# Asynchronous pylint utility call
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# License: GNU General Public License version 3 of the License or later
+#
+# This plugin allows you to asynchronously call pylint.
+#
+# * Press <F6> to start pylint on current file
+# * Press <S-F6> to open quickfix window with messages from pylint
+# * All lines with corresponding pylint existing warning will be highlighted
+# * If no warning and errors occurred, "pylint is clean" message will be shown
+# * If existing quickfix window is found, then it won't be overwritten.
+#   Start pylint manually (<F6>) to force its filling
+
+export def Status(): string
+    if exists("b:pylint_job") && job_status(b:pylint_job) == "run" | return "LN" | endif
+    return ""
+enddef
+
+def Qffill(ch: channel)
+    var msgs = []
+    while ch_status(ch) == "buffered"
+        msgs = add(msgs, ch_read(ch))
+    endwhile
+    cgetexpr msgs
+enddef
+
+export def Finish(ch: channel)
+    var errorformat_bak = &errorformat
+    set errorformat=%f:%l:\ [%t]%m,%f:%l:%m
+    Qffill(ch)
+    &errorformat = errorformat_bak
+    sign unplace *
+    var id = 2
+    for item in getqflist()
+        if item.lnum == 0 | continue | endif
+        execute(":sign place " .. id ..
+            " name=LN line=" .. item.lnum .. " buffer=" .. item.bufnr)
+        id = id + 2
+    endfor
+    redraw!
+    if id == 2
+        echohl MoreMsg | echomsg "pylint is clean" | echohl None
+        cclose
+    endif
+enddef
+
+export def Start()
+    if exists("b:pylint_job") && job_status(b:pylint_job) == "run"
+        return
+    endif
+    var cmdline = [
+        "flake8",
+        "--ignore=E501",
+        "--format=%(path)s:%(row)d: [%(code)s] %(text)s",
+        "--max-line-length=90",
+        expand("%p")
+    ]
+    b:pylint_job = job_start(cmdline,
+        {"in_mode": "nl",  "err_io": "null", "close_cb": "python#lint#Finish"})
+enddef
diff --git a/vim/.vim/pack/stargrave/start/py-flake8/ftplugin/lint.vim b/vim/.vim/pack/stargrave/start/py-flake8/ftplugin/lint.vim
new file mode 100644 (file)
index 0000000..cc252c1
--- /dev/null
@@ -0,0 +1,6 @@
+if exists("*python#lint#start") | finish | endif
+sign define LN text=LN texthl=Error
+let b:mein_status_func=function("python#lint#Status")
+map <F6> :unlet! g:pylint_disable<CR>:call python#lint#Start()<CR>
+" Shift-F6:
+map \e[17;2~ :redraw!<CR>:copen<CR>
index ad29aba42b37c9ccaec220714c69eb18578ebbff..1adfbe5a9448533f7fcc4571e71b32ea57ecc26f 100644 (file)
@@ -16,17 +16,6 @@ for d in [
         path: "gopls",
         syncInit: true,
     },
-    {
-        filetype: ["python"],
-        path: "pyls",
-        syncInit: true,
-        workspaceConfig: {pyls: {
-            configurationSources: ["flake8"],
-            plugins: {
-                mccabe: {enabled: false},
-            },
-        }},
-    },
 ]
     if executable(d["path"])
         add(lspServers, d)