Skip to content

Commit b65f669

Browse files
committed
Fix Rope
1 parent 892aa7d commit b65f669

File tree

10 files changed

+233
-54
lines changed

10 files changed

+233
-54
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ clean:
99
.PHONY: test
1010
test:
1111
bundle install
12+
rm -rf $(CURDIR)/.ropeproject
1213
rake test
1314

1415
.PHONY: pylama

autoload/pymode/lint.vim

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
PymodePython from pymode.lint import code_check
22

3+
call pymode#tools#signs#init()
4+
call pymode#tools#loclist#init()
5+
6+
37
fun! pymode#lint#auto() "{{{
48
if !pymode#save()
59
return 0
@@ -13,7 +17,8 @@ endfunction "}}}
1317

1418

1519
fun! pymode#lint#show_errormessage() "{{{
16-
if empty(b:pymode_errors)
20+
let loclist = g:PymodeLocList.current()
21+
if loclist.is_empty()
1722
return
1823
endif
1924

@@ -22,8 +27,8 @@ fun! pymode#lint#show_errormessage() "{{{
2227
return
2328
endif
2429
let b:pymode_error_line = l
25-
if has_key(b:pymode_errors, l)
26-
call pymode#wide_message(b:pymode_errors[l])
30+
if has_key(loclist._messages, l)
31+
call pymode#wide_message(loclist._messages[l])
2732
else
2833
echo
2934
endif
@@ -39,47 +44,39 @@ fun! pymode#lint#toggle() "{{{
3944
end
4045
endfunction "}}}
4146

47+
4248
fun! pymode#lint#check() "{{{
4349
" DESC: Run checkers on current file.
4450
"
4551
if !g:pymode_lint | return | endif
4652

47-
let b:pymode_errors = {}
53+
let loclist = g:PymodeLocList.current()
54+
55+
let b:pymode_error_line = -1
56+
57+
call loclist.clear()
4858

4959
call pymode#wide_message('Code checking is running ...')
5060

5161
PymodePython code_check()
5262

53-
let errors = getqflist()
54-
if empty(errors)
63+
if loclist.is_empty()
5564
call pymode#wide_message('Code checking is completed. No errors found.')
5665
endif
5766

5867
if g:pymode_lint_cwindow
68+
call setqflist(loclist._loclist)
5969
call pymode#quickfix_open(0, g:pymode_quickfix_maxheight, g:pymode_quickfix_minheight, 0)
6070
endif
6171

62-
if g:pymode_lint_signs
63-
for item in b:pymode_signs
64-
execute printf('sign unplace %d buffer=%d', item.lnum, item.bufnr)
65-
endfor
66-
let b:pymode_lint_signs = []
67-
for item in filter(errors, 'v:val.bufnr != ""')
68-
call add(b:pymode_signs, item)
69-
execute printf('sign place %d line=%d name=%s buffer=%d', item.lnum, item.lnum, "Pymode".item.type, item.bufnr)
70-
endfor
71-
endif
72-
73-
for item in errors
74-
let b:pymode_errors[item.lnum] = item.text
75-
endfor
72+
call g:PymodeSigns.refresh(loclist)
7673

77-
let b:pymode_error_line = -1
7874
call pymode#lint#show_errormessage()
79-
call pymode#wide_message('Found errors and warnings: ' . len(errors))
75+
call pymode#wide_message('Found errors and warnings: ' . len(loclist._loclist))
8076

8177
endfunction " }}}
8278

79+
8380
fun! pymode#lint#tick_queue() "{{{
8481

8582
python import time
@@ -96,11 +93,13 @@ fun! pymode#lint#tick_queue() "{{{
9693
endif
9794
endfunction "}}}
9895

96+
9997
fun! pymode#lint#stop() "{{{
10098
au! pymode CursorHold <buffer>
101-
endfunction
99+
endfunction "}}}
100+
102101

103102
fun! pymode#lint#start() "{{{
104103
au! pymode CursorHold <buffer> call pymode#lint#tick_queue()
105104
call pymode#lint#tick_queue()
106-
endfunction
105+
endfunction "}}}

autoload/pymode/tools/loclist.vim

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
let g:PymodeLocList= {}
2+
3+
4+
fun! pymode#tools#loclist#init() "{{{
5+
return
6+
endfunction "}}}
7+
8+
9+
fun! g:PymodeLocList.init(raw_list) "{{{
10+
let obj = copy(self)
11+
let loc_list = filter(copy(a:raw_list), 'v:val["valid"] == 1')
12+
call obj.clear()
13+
return obj
14+
endfunction "}}}
15+
16+
17+
fun! g:PymodeLocList.current() "{{{
18+
if !exists("b:pymode_loclist")
19+
let b:pymode_loclist = g:PymodeLocList.init([])
20+
endif
21+
return b:pymode_loclist
22+
endfunction "}}}
23+
24+
25+
fun! g:PymodeLocList.is_empty() "{{{
26+
return empty(self._loclist)
27+
endfunction "}}}
28+
29+
30+
fun! g:PymodeLocList.clear() "{{{
31+
let self._loclist = []
32+
let self._messages = {}
33+
endfunction "}}}
34+
35+
36+
fun! g:PymodeLocList.extend(raw_list) "{{{
37+
call extend(self._loclist, a:raw_list)
38+
for issue in a:raw_list
39+
let self._messages[issue.lnum] = issue.text
40+
endfor
41+
return self
42+
endfunction "}}}
43+
44+
45+
fun! g:PymodeLocList.filter(filters) "{{{
46+
let loclist = []
47+
for error in self._loclist
48+
let passes_filters = 1
49+
for key in keys(a:filters)
50+
if get(error, key, '') !=? a:filters[key]
51+
let passes_filters = 0
52+
break
53+
endif
54+
endfor
55+
56+
if passes_filters
57+
call add(loclist, error)
58+
endif
59+
60+
endfor
61+
return loclist
62+
endfunction "}}}

autoload/pymode/tools/signs.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
let g:PymodeSigns = {}
2+
3+
4+
fun! pymode#tools#signs#init() "{{{
5+
call g:PymodeSigns.setup()
6+
endfunction "}}}
7+
8+
9+
fun! g:PymodeSigns.enabled() "{{{
10+
return (g:pymode_lint_signs && has('signs'))
11+
endfunction "}}}
12+
13+
14+
fun! g:PymodeSigns.setup() "{{{
15+
if self.enabled()
16+
execute 'sign define PymodeW text=' . g:pymode_lint_todo_symbol . " texthl=Todo"
17+
execute 'sign define PymodeC text=' . g:pymode_lint_comment_symbol . " texthl=Comment"
18+
execute 'sign define PymodeR text=' . g:pymode_lint_visual_symbol . " texthl=Visual"
19+
execute 'sign define PymodeE text=' . g:pymode_lint_error_symbol . " texthl=Error"
20+
execute 'sign define PymodeI text=' . g:pymode_lint_info_symbol . " texthl=Info"
21+
execute 'sign define PymodeF text=' . g:pymode_lint_pyflakes_symbol . " texthl=Info"
22+
endif
23+
let self._sign_ids = []
24+
let self._next_id = 10000
25+
let self._messages = {}
26+
endfunction "}}}
27+
28+
29+
fun! g:PymodeSigns.refresh(loclist) "{{{
30+
if self.enabled()
31+
call self.clear()
32+
call self.place(a:loclist)
33+
endif
34+
endfunction "}}}
35+
36+
37+
fun! g:PymodeSigns.clear() "{{{
38+
let ids = copy(self._sign_ids)
39+
for i in ids
40+
execute "sign unplace " . i
41+
call remove(self._sign_ids, index(self._sign_ids, i))
42+
endfor
43+
endfunction "}}}
44+
45+
46+
fun! g:PymodeSigns.place(loclist) "{{{
47+
let seen = {}
48+
let buf = bufnr('')
49+
for issue in a:loclist._loclist
50+
if !has_key(seen, issue.lnum)
51+
let seen[issue.lnum] = 1
52+
call add(self._sign_ids, self._next_id)
53+
execute printf('sign place %d line=%d name=%s buffer=%d', self._next_id, issue.lnum, "Pymode".issue.type[0], buf)
54+
let self._next_id += 1
55+
endif
56+
endfor
57+
endfunction "}}}

plugin/pymode.vim

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ com! PymodeTroubleshooting call pymode#troubleshooting#test()
66

77
" Enable pymode by default :)
88
call pymode#default('g:pymode', 1)
9+
call pymode#default('g:pymode_debug', 0)
910

1011
" DESC: Disable script loading
1112
if !g:pymode || &cp
@@ -119,17 +120,6 @@ call pymode#default("g:pymode_lint_error_symbol", "EE")
119120
call pymode#default("g:pymode_lint_info_symbol", "II")
120121
call pymode#default("g:pymode_lint_pyflakes_symbol", "FF")
121122

122-
if g:pymode_lint_signs && has('signs')
123-
124-
execute 'sign define PymodeW text=' . g:pymode_lint_todo_symbol . " texthl=Todo"
125-
execute 'sign define PymodeC text=' . g:pymode_lint_comment_symbol . " texthl=Comment"
126-
execute 'sign define PymodeR text=' . g:pymode_lint_visual_symbol . " texthl=Visual"
127-
execute 'sign define PymodeE text=' . g:pymode_lint_error_symbol . " texthl=Error"
128-
execute 'sign define PymodeI text=' . g:pymode_lint_info_symbol . " texthl=Info"
129-
execute 'sign define PymodeF text=' . g:pymode_lint_pyflakes_symbol . " texthl=Info"
130-
131-
endif
132-
133123
" }}}
134124

135125
" SET/UNSET BREAKPOINTS {{{

pymode/lint.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88

99
def code_check():
10-
""" Run pylama and check current file. """
10+
""" Run pylama and check current file.
11+
12+
:return bool:
13+
14+
"""
1115

1216
from pylama.main import parse_options
1317
from pylama.tasks import check_path
@@ -37,15 +41,14 @@ def code_check():
3741
errors = check_path(path, options=options, code=code)
3842
sort_rules = vim.eval('g:pymode_lint_sort')
3943

40-
def sort(e):
44+
def __sort(e):
4145
try:
42-
print(e.get('type'))
4346
return sort_rules.index(e.get('type'))
4447
except ValueError:
4548
return 999
4649

4750
if sort_rules:
48-
print(sort_rules)
49-
errors = sorted(errors, key=sort)
51+
errors = sorted(errors, key=__sort)
5052

51-
vim.command('call setqflist(%s)' % json.dumps(errors))
53+
vim.command(
54+
'call g:PymodeLocList.current().extend(%s)' % json.dumps(errors))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy