From 3822d495f8dbd849e34997694feb47cb0e190628 Mon Sep 17 00:00:00 2001
From: Sergey Matveev <stargrave@stargrave.org>
Date: Sun, 21 Nov 2021 16:27:03 +0300
Subject: [PATCH] python#importcompl#all works with LSP

---
 vim/.vim/autoload/python/importcompl.vim | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/vim/.vim/autoload/python/importcompl.vim b/vim/.vim/autoload/python/importcompl.vim
index cc26c79..aa9a168 100644
--- a/vim/.vim/autoload/python/importcompl.vim
+++ b/vim/.vim/autoload/python/importcompl.vim
@@ -56,13 +56,12 @@ function! python#importcompl#all() abort
             let imports[m[2]] = m[1]
         endfor
     endfor
-    let lines = getloclist(winnr())
-    if len(lines) == 0 | let lines = getqflist() | endif
     let result = []
-    for line in lines
-        let m = matchlist(line.text, '\(E0602\|F821\).*' . "'" . '\(\w\+\)' . "'$")
-        if len(m) == 0 || !has_key(imports, m[2]) | continue | endif
-        call insert(result, imports[m[2]])
+    for diag in lsp#ui#vim#diagnostics#get_all_buffer_diagnostics()
+        if diag["message"] !~ "^undefined name" | continue | endif
+        let m = diag["message"][strridx(diag["message"][:-2], "'")+1:-2]
+        if len(m) == 0 || !has_key(imports, m) | continue | endif
+        call insert(result, imports[m])
     endfor
     call sort(result, "i")
     call uniq(result)
-- 
2.51.0