Skip to content

Commit 59d7fd7

Browse files
committed
Async code checking
1 parent eda55a7 commit 59d7fd7

File tree

6 files changed

+127
-65
lines changed

6 files changed

+127
-65
lines changed

autoload/pymode.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fun! pymode#QuickfixOpen(onlyRecognized, holdCursor, maxHeight, minHeight, jumpE
3131
exe max([min([line("$"), a:maxHeight]), a:minHeight]) . "wincmd _"
3232
if a:jumpError
3333
cc
34-
elseif a:holdCursor
34+
elseif !a:holdCursor
3535
wincmd p
3636
endif
3737
else

autoload/pymode/lint.vim

+21-25
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ fun! pymode#lint#Check()
22

33
if !g:pymode_lint | return | endif
44

5-
let b:errors = {}
6-
75
if &modifiable && &modified
86
try
97
write
@@ -13,31 +11,25 @@ fun! pymode#lint#Check()
1311
endtry
1412
endif
1513

16-
py check_file()
17-
18-
if g:qf_list != b:qf_list
14+
let g:pymode_lint_buffer = bufnr('%')
1915

20-
call setqflist(b:qf_list, 'r')
16+
py check_file()
2117

22-
let g:qf_list = b:qf_list
18+
endfunction
2319

24-
if g:pymode_lint_message
25-
for v in b:qf_list
26-
let b:errors[v['lnum']] = v['text']
27-
endfor
28-
call pymode#lint#show_errormessage()
29-
endif
3020

31-
if g:pymode_lint_cwindow
32-
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, g:pymode_lint_jump)
33-
endif
21+
fun! pymode#lint#Parse()
3422

35-
endif
23+
call setqflist(g:qf_list, 'r')
3624

3725
if g:pymode_lint_signs
3826
call pymode#PlaceSigns()
3927
endif
4028

29+
if g:pymode_lint_cwindow
30+
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, g:pymode_lint_jump)
31+
endif
32+
4133
endfunction
4234

4335

@@ -74,13 +66,17 @@ endfunction "}}}
7466

7567

7668
fun! pymode#lint#show_errormessage() "{{{
77-
if !len(b:errors) | return | endif
78-
let cursor = getpos(".")
79-
if has_key(b:errors, l:cursor[1])
80-
call pymode#WideMessage(b:errors[l:cursor[1]])
81-
let b:show_message = 1
82-
else
83-
let b:show_message = 0
84-
echo
69+
if g:pymode_lint_buffer != bufnr('%')
70+
return 0
8571
endif
72+
let errors = getqflist()
73+
if !len(errors) | return | endif
74+
let [_, line, _, _] = getpos(".")
75+
for e in errors
76+
if e['lnum'] == line
77+
call pymode#WideMessage(e['text'])
78+
else
79+
echo
80+
endif
81+
endfor
8682
endfunction " }}}

autoload/pymode/troubleshooting.vim

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
" DESC: Get debug information about pymode problem
2+
fun! pymode#troubleshooting#Test() "{{{
3+
new
4+
setlocal buftype=nofile bufhidden=delete noswapfile nowrap
5+
call append('0', ['Pymode diagnostic',
6+
\ '===================',
7+
\ 'VIM:' . v:version . ' multi_byte:' . has('multi_byte') . ' pymode: ' . g:pymode_version,
8+
\ ''])
9+
10+
let python = 1
11+
let output = []
12+
13+
if !exists('#filetypeplugin')
14+
call append('$', ['WARNING: ', 'Python-mode required :filetype plugin indent on', ''])
15+
endif
16+
17+
if !has('python')
18+
call append('$', ['WARNING: ', 'Python-mode required vim compiled with +python.',
19+
\ '"lint, rope, run, doc, virtualenv" features disabled.', ''])
20+
let python = 0
21+
endif
22+
23+
call append('$', 'Pymode variables:')
24+
call append('$', '-------------------')
25+
call append('$', 'pymode:' . g:pymode)
26+
call append('$', 'pymode_lint:' . g:pymode_lint)
27+
call append('$', 'pymode_rope:' . g:pymode_rope)
28+
call append('$', 'pymode_path:' . g:pymode_path)
29+
call append('$', 'pymode_doc:' . g:pymode_doc)
30+
call append('$', 'pymode_run:' . g:pymode_run)
31+
call append('$', 'pymode_virtualenv:' . g:pymode_virtualenv)
32+
call append('$', 'pymode_breakpoint:' . g:pymode_breakpoint)
33+
call append('$', 'pymode_path:' . g:pymode_path)
34+
call append('$', 'pymode_folding:' . g:pymode_folding)
35+
call append('$', 'pymode_syntax:' . g:pymode_syntax)
36+
call append('$', 'pymode_utils_whitespaces:' . g:pymode_utils_whitespaces)
37+
call append('$', 'pymode_options_indent:' . g:pymode_options_indent)
38+
call append('$', 'pymode_options_other:' . g:pymode_options_other)
39+
40+
if len(g:pymode_virtualenv_enabled)
41+
call append('$', 'Enabled virtualenv:')
42+
call append('$', '-------------------')
43+
call append('$', g:pymode_virtualenv_enabled)
44+
call append('$', '')
45+
endif
46+
47+
if python
48+
call append('$', 'VIM python paths:')
49+
call append('$', '-----------------')
50+
python << EOF
51+
vim.command('let l:output = %s' % repr(sys.path))
52+
EOF
53+
call append('$', output)
54+
call append('$', '')
55+
endif
56+
57+
endfunction "}}}

ftplugin/python/pymode.vim

+1-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ endif
6363

6464
if pymode#Option('lint')
6565

66-
let b:qf_list = []
66+
let b:errors = []
6767

6868
" DESC: Set commands
6969
command! -buffer -nargs=0 PyLintToggle :call pymode#lint#Toggle()
@@ -81,16 +81,8 @@ if pymode#Option('lint')
8181
endif
8282

8383
if pymode#Option('lint_message')
84-
85-
" DESC: Show message flag
86-
let b:show_message = 0
87-
88-
" DESC: Errors dict
89-
let b:errors = {}
90-
9184
au CursorHold <buffer> call pymode#lint#show_errormessage()
9285
au CursorMoved <buffer> call pymode#lint#show_errormessage()
93-
9486
endif
9587

9688
endif

plugin/pymode.vim

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ endif
5757
if !pymode#Default("g:pymode_lint", 1) || g:pymode_lint
5858

5959
let g:qf_list = []
60+
let g:pymode_lint_buffer = 0
6061

6162
" OPTION: g:pymode_lint_write -- bool. Check code every save.
6263
call pymode#Default("g:pymode_lint_write", 1)

pylibs/pymode.py

+46-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import StringIO
22
import locale
3+
import threading
34

45
import vim
56

@@ -8,41 +9,56 @@
89

910

1011
def check_file():
11-
filename = vim.current.buffer.name
1212
checkers = vim.eval("pymode#Option('lint_checker')").split(',')
1313
ignore = vim.eval("pymode#Option('lint_ignore')")
1414
ignore = ignore and ignore.split(',') or []
1515
select = vim.eval("pymode#Option('lint_select')")
1616
select = select and select.split(',') or []
17-
errors = []
18-
19-
for c in checkers:
20-
checker = globals().get(c)
21-
if checker:
22-
try:
23-
for e in checker(filename):
24-
e.update(
25-
col=e.get('col') or '',
26-
text="%s [%s]" % (e.get('text', '').replace("'", "\"").split('\n')[0], c),
27-
filename=filename,
28-
bufnr=vim.current.buffer.number,
29-
)
30-
errors.append(e)
31-
32-
except SyntaxError, e:
33-
errors.append(dict(
34-
lnum=e.lineno,
35-
col=e.offset,
36-
text=e.args[0]
37-
))
38-
break
39-
except Exception, e:
40-
print e
41-
42-
errors = filter(lambda e: _ignore_error(e, select, ignore), errors)
43-
errors = sorted(errors, key=lambda x: x['lnum'])
44-
45-
vim.command(('let b:qf_list = %s' % repr(errors)).replace('\': u', '\': '))
17+
thread = Checker(vim.current.buffer, select, ignore, checkers)
18+
thread.start()
19+
20+
21+
class Checker(threading.Thread):
22+
def __init__(self, buffer, select, ignore, checkers):
23+
self.buffer = buffer.number
24+
self.filename = buffer.name
25+
self.select = select
26+
self.ignore = ignore
27+
self.checkers = checkers
28+
super(Checker, self).__init__()
29+
30+
def run(self):
31+
32+
errors = []
33+
34+
for c in self.checkers:
35+
checker = globals().get(c)
36+
if checker:
37+
try:
38+
for e in checker(self.filename):
39+
e.update(
40+
col=e.get('col') or '',
41+
text="%s [%s]" % (e.get('text', '').replace("'", "\"").split('\n')[0], c),
42+
filename=self.filename,
43+
bufnr=self.buffer,
44+
)
45+
errors.append(e)
46+
47+
except SyntaxError, e:
48+
errors.append(dict(
49+
lnum=e.lineno,
50+
col=e.offset,
51+
text=e.args[0]
52+
))
53+
break
54+
except Exception, e:
55+
print e
56+
57+
errors = filter(lambda e: _ignore_error(e, self.select, self.ignore), errors)
58+
errors = sorted(errors, key=lambda x: x['lnum'])
59+
60+
vim.command(('let g:qf_list = %s' % repr(errors)).replace('\': u', '\': '))
61+
vim.command('call pymode#lint#Parse()')
4662

4763

4864
def mccabe(filename):

0 commit comments

Comments
 (0)