neovim 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +118 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +5 -0
  6. data/Rakefile +29 -16
  7. data/VimFlavor +1 -0
  8. data/appveyor.yml +2 -0
  9. data/lib/neovim/api.rb +2 -1
  10. data/lib/neovim/buffer.rb +7 -15
  11. data/lib/neovim/client.rb +3 -3
  12. data/lib/neovim/connection.rb +6 -7
  13. data/lib/neovim/event_loop.rb +3 -3
  14. data/lib/neovim/executable.rb +1 -0
  15. data/lib/neovim/host.rb +12 -12
  16. data/lib/neovim/line_range.rb +16 -16
  17. data/lib/neovim/logging.rb +14 -14
  18. data/lib/neovim/message.rb +7 -7
  19. data/lib/neovim/plugin/dsl.rb +4 -4
  20. data/lib/neovim/plugin/handler.rb +3 -3
  21. data/lib/neovim/remote_object.rb +3 -3
  22. data/lib/neovim/ruby_provider.rb +11 -15
  23. data/lib/neovim/ruby_provider/buffer_ext.rb +1 -0
  24. data/lib/neovim/ruby_provider/vim.rb +14 -2
  25. data/lib/neovim/ruby_provider/window_ext.rb +1 -0
  26. data/lib/neovim/session.rb +7 -10
  27. data/lib/neovim/version.rb +1 -1
  28. data/lib/neovim/window.rb +3 -3
  29. data/neovim.gemspec +5 -4
  30. data/script/{dump_api → dump_api.rb} +0 -0
  31. data/script/{generate_docs → generate_docs.rb} +0 -0
  32. data/script/{j2mp → j2mp.rb} +0 -0
  33. data/script/{mp2j → mp2j.rb} +0 -0
  34. data/script/run_acceptance.rb +35 -0
  35. data/script/validate_docs.rb +29 -0
  36. data/spec/acceptance/rplugin_autocmd_spec.vim +20 -10
  37. data/spec/acceptance/rplugin_command_spec.vim +54 -56
  38. data/spec/acceptance/rplugin_function_spec.vim +28 -22
  39. data/spec/acceptance/ruby_spec.vim +40 -48
  40. data/spec/acceptance/rubydo_spec.vim +40 -52
  41. data/spec/acceptance/rubyfile/nested.rb +1 -1
  42. data/spec/acceptance/rubyfile_spec.vim +57 -63
  43. data/spec/acceptance/runtime/init.vim +4 -3
  44. data/spec/acceptance/runtime/rplugin/ruby/autocmds.rb +6 -2
  45. data/spec/acceptance/runtime/rplugin/ruby/commands.rb +17 -16
  46. data/spec/acceptance/runtime/rplugin/ruby/functions.rb +8 -8
  47. data/spec/helper.rb +2 -2
  48. data/spec/neovim/api_spec.rb +1 -1
  49. data/spec/neovim/client_spec.rb +10 -10
  50. data/spec/neovim/connection_spec.rb +5 -6
  51. data/spec/neovim/current_spec.rb +12 -12
  52. data/spec/neovim/executable_spec.rb +2 -2
  53. data/spec/neovim/host/loader_spec.rb +2 -2
  54. data/spec/neovim/host_spec.rb +7 -7
  55. data/spec/neovim/line_range_spec.rb +16 -16
  56. data/spec/neovim/logging_spec.rb +7 -7
  57. data/spec/neovim/plugin_spec.rb +6 -6
  58. data/spec/neovim/ruby_provider/buffer_ext_spec.rb +2 -2
  59. data/spec/neovim/ruby_provider/vim_spec.rb +4 -4
  60. data/spec/neovim/ruby_provider/window_ext_spec.rb +8 -8
  61. data/spec/neovim/session_spec.rb +8 -8
  62. data/spec/neovim/window_spec.rb +0 -1
  63. metadata +41 -27
  64. data/.gitmodules +0 -3
  65. data/.rspec +0 -1
  66. data/spec/acceptance/runtime/vader.vim/autoload/vader.vim +0 -348
  67. data/spec/acceptance/runtime/vader.vim/autoload/vader/assert.vim +0 -116
  68. data/spec/acceptance/runtime/vader.vim/autoload/vader/helper.vim +0 -43
  69. data/spec/acceptance/runtime/vader.vim/autoload/vader/parser.vim +0 -179
  70. data/spec/acceptance/runtime/vader.vim/autoload/vader/syntax.vim +0 -73
  71. data/spec/acceptance/runtime/vader.vim/autoload/vader/window.vim +0 -205
  72. data/spec/acceptance/runtime/vader.vim/plugin/vader.vim +0 -37
  73. data/spec/acceptance_spec.rb +0 -85
@@ -1,116 +0,0 @@
1
- " Copyright (c) 2013 Junegunn Choi
2
- "
3
- " MIT License
4
- "
5
- " Permission is hereby granted, free of charge, to any person obtaining
6
- " a copy of this software and associated documentation files (the
7
- " "Software"), to deal in the Software without restriction, including
8
- " without limitation the rights to use, copy, modify, merge, publish,
9
- " distribute, sublicense, and/or sell copies of the Software, and to
10
- " permit persons to whom the Software is furnished to do so, subject to
11
- " the following conditions:
12
- "
13
- " The above copyright notice and this permission notice shall be
14
- " included in all copies or substantial portions of the Software.
15
- "
16
- " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- " NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
-
25
- let s:assertions = [0, 0]
26
-
27
- let s:type_names = {
28
- \ 0: 'Number',
29
- \ 1: 'String',
30
- \ 2: 'Funcref',
31
- \ 3: 'List',
32
- \ 4: 'Dictionary',
33
- \ 5: 'Float',
34
- \ 6: 'Boolean',
35
- \ 7: 'Null' }
36
-
37
- function! vader#assert#reset()
38
- let s:assertions = [0, 0]
39
- endfunction
40
-
41
- function! vader#assert#stat()
42
- return s:assertions
43
- endfunction
44
-
45
- function! vader#assert#true(...)
46
- let s:assertions[1] += 1
47
-
48
- if a:0 == 1
49
- let [expr, message] = [a:1, "Assertion failure"]
50
- elseif a:0 == 2
51
- let [expr, message] = a:000
52
- else
53
- throw 'Invalid number of arguments'
54
- endif
55
-
56
- if !expr
57
- throw message
58
- endif
59
- let s:assertions[0] += 1
60
- return 1
61
- endfunction
62
-
63
- function! s:check_types(...)
64
- let [Exp, Got] = a:000[0:1]
65
- if type(Exp) !=# type(Got)
66
- throw get(a:000, 2, printf("type mismatch: %s (%s) should be equal to %s (%s)",
67
- \ string(Got), get(s:type_names, type(Got), type(Got)),
68
- \ string(Exp), get(s:type_names, type(Exp), type(Exp))))
69
- endif
70
- endfunction
71
-
72
- function! vader#assert#equal(...)
73
- let [Exp, Got] = a:000[0:1]
74
- let s:assertions[1] += 1
75
-
76
- call s:check_types(Exp, Got)
77
- if Exp !=# Got
78
- let type = type(Exp)
79
- let msg = (type == type({}) || type == type([]))
80
- \ ? printf("Unequal %ss\n %%s should be equal to \n %%s", get(s:type_names, type))
81
- \ : "%s should be equal to %s"
82
- throw get(a:000, 2, printf(msg, string(Got), string(Exp)))
83
- endif
84
- let s:assertions[0] += 1
85
- return 1
86
- endfunction
87
-
88
- function! vader#assert#not_equal(...)
89
- let [Exp, Got] = a:000[0:1]
90
- let s:assertions[1] += 1
91
-
92
- call s:check_types(Exp, Got)
93
- if Exp ==# Got
94
- throw get(a:000, 2, printf("%s should not be equal to %s", string(Got), string(Exp)))
95
- endif
96
- let s:assertions[0] += 1
97
- return 1
98
- endfunction
99
-
100
- function! vader#assert#throws(exp)
101
- let s:assertions[1] += 1
102
-
103
- let ok = 0
104
- try
105
- execute a:exp
106
- catch
107
- let g:vader_exception = v:exception
108
- let g:vader_throwpoint = v:throwpoint
109
- let ok = 1
110
- endtry
111
-
112
- let s:assertions[0] += ok
113
- if ok | return 1
114
- else | throw 'Exception expected but not raised: '.a:exp
115
- endif
116
- endfunction
@@ -1,43 +0,0 @@
1
- function! vader#helper#syntax_at(...)
2
- if a:0 < 2
3
- let l:pos = getpos('.')
4
- let l:cur_lnum = pos[1]
5
- let l:cur_col = pos[2]
6
- if a:0 == 0
7
- let l:lnum = l:cur_lnum
8
- let l:col = l:cur_col
9
- else
10
- let l:lnum = l:cur_lnum
11
- let l:col = a:1
12
- endif
13
- else
14
- let l:lnum = a:1
15
- let l:col = a:2
16
- endif
17
- return synIDattr(synID(l:lnum, l:col, 1), 'name')
18
- endfunction
19
-
20
- function! vader#helper#syntax_of(pattern, ...)
21
- if a:0 < 1
22
- let l:nth = 1
23
- else
24
- let l:nth = a:1
25
- endif
26
-
27
- let l:pos_init = getpos('.')
28
- call cursor(1, 1)
29
- let found = search(a:pattern, 'cW')
30
- while found != 0 && nth > 1
31
- let found = search(a:pattern, 'W')
32
- let nth -= 1
33
- endwhile
34
-
35
- if found
36
- let l:pos = getpos('.')
37
- let l:output = vader#helper#syntax_at(l:pos[1], l:pos[2])
38
- else
39
- let l:output = ''
40
- endif
41
- call setpos('.', l:pos_init)
42
- return l:output
43
- endfunction
@@ -1,179 +0,0 @@
1
- " Copyright (c) 2013 Junegunn Choi
2
- "
3
- " MIT License
4
- "
5
- " Permission is hereby granted, free of charge, to any person obtaining
6
- " a copy of this software and associated documentation files (the
7
- " "Software"), to deal in the Software without restriction, including
8
- " without limitation the rights to use, copy, modify, merge, publish,
9
- " distribute, sublicense, and/or sell copies of the Software, and to
10
- " permit persons to whom the Software is furnished to do so, subject to
11
- " the following conditions:
12
- "
13
- " The above copyright notice and this permission notice shall be
14
- " included in all copies or substantial portions of the Software.
15
- "
16
- " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- " NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- function! vader#parser#parse(fn, line1, line2)
25
- return s:parse_vader(s:read_vader(a:fn, a:line1, a:line2), a:line1)
26
- endfunction
27
-
28
- function! s:flush_buffer(cases, case, fn, lnum, raw, label, newlabel, buffer, final)
29
- let is_validation = index(['then', 'expect'], a:newlabel) >= 0
30
- let fpos = a:fn.':'.a:lnum
31
-
32
- if empty(a:label)
33
- if is_validation
34
- echoerr 'Expect/Then should not appear before Do/Execute ('.fpos.')'
35
- endif
36
- else
37
- let rev = reverse(copy(a:buffer))
38
- while len(rev) > 0 && empty(rev[0])
39
- call remove(rev, 0)
40
- endwhile
41
-
42
- let data = map(reverse(rev), (a:case.raw ? 'v:val' : 'strpart(v:val, 2)'))
43
- let a:case[a:label] = data
44
- if !empty(a:buffer)
45
- call remove(a:buffer, 0, -1)
46
- endif
47
-
48
- let fulfilled = has_key(a:case, 'do') || has_key(a:case, 'execute')
49
- if is_validation
50
- if !fulfilled
51
- echoerr 'Expect/Then should not appear before Do/Execute ('.fpos.')'
52
- endif
53
- if has_key(a:case, a:newlabel)
54
- echoerr 'Expect/Then should appear only once for each Do/Execute ('.fpos.')'
55
- endif
56
- endif
57
-
58
- if a:final ||
59
- \ a:newlabel == 'given' ||
60
- \ index(['before', 'after', 'do', 'execute'], a:newlabel) >= 0 && fulfilled
61
- call add(a:cases, deepcopy(a:case))
62
- let new = { 'comment': {}, 'lnum': a:lnum, 'pending': 0 }
63
- if !empty(get(a:case, 'type', ''))
64
- let new.type = a:case.type " To reuse Given block with type
65
- endif
66
- call extend(filter(a:case, '0'), new)
67
- endif
68
- endif
69
- let a:case.raw = a:raw
70
- endfunction
71
-
72
- function! s:read_vader(fn, line1, line2)
73
- let remains = readfile(a:fn)[a:line1 - 1 : a:line2 - 1]
74
- let lnum = a:line1
75
- let lines = []
76
- let reserved = 0
77
- let depth = 0 " Not a strict depth
78
- let max_depth = 10
79
-
80
- while len(remains) > 0
81
- let line = remove(remains, 0)
82
- let m = matchlist(line, '^Include\(\s*(.*)\s*\)\?:\s*\(.\{-}\)\s*$')
83
- if !empty(m)
84
- let file = findfile(m[2], fnamemodify(a:fn, ':h'))
85
- if empty(file)
86
- echoerr "Cannot find ".m[2]
87
- endif
88
- if reserved > 0
89
- let depth += 1
90
- if depth >= max_depth
91
- echoerr 'Recursive inclusion limit exceeded'
92
- endif
93
- let reserved -= 1
94
- endif
95
- let included = readfile(file)
96
- let reserved += len(included)
97
- call extend(remains, included, 0)
98
- continue
99
- end
100
-
101
- call add(lines, [a:fn, lnum, line])
102
- if reserved > 0
103
- let reserved -= 1
104
- end
105
- if reserved == 0
106
- let depth = 0
107
- let lnum += 1
108
- endif
109
- endwhile
110
-
111
- return lines
112
- endfunction
113
-
114
- function! s:parse_vader(lines, line1)
115
- let label = ''
116
- let newlabel = ''
117
- let buffer = []
118
- let cases = []
119
- let case = { 'lnum': a:line1, 'comment': {}, 'pending': 0, 'raw': 0 }
120
-
121
- for [fn, lnum, line] in a:lines
122
- " Comment / separators
123
- if !case.raw && line =~ '^[#"=~*^-]'
124
- continue
125
- endif
126
-
127
- let matched = 0
128
- for l in ['Before', 'After', 'Given', 'Execute', 'Expect', 'Do', 'Then']
129
- let m = matchlist(line, '^'.l.'\%(\s\+\([^:;(]\+\)\)\?\s*\%((\(.*\))\)\?\s*\([:;]\)\s*$')
130
- if !empty(m)
131
- let newlabel = tolower(l)
132
- call s:flush_buffer(cases, case, fn, lnum, m[3] == ';', label, newlabel, buffer, 0)
133
-
134
- let label = newlabel
135
- let arg = m[1]
136
- let comment = m[2]
137
- if !empty(arg)
138
- if l == 'Given' | let case.type = arg
139
- elseif l == 'Execute' | let case.lang_if = arg
140
- end
141
- elseif l == 'Given'
142
- let case.type = ''
143
- endif
144
- if !empty(comment)
145
- let case.comment[tolower(l)] = comment
146
- if index(['do', 'execute'], label) >= 0 &&
147
- \ comment =~# '\<TODO\>\|\<FIXME\>'
148
- let case.pending = 1
149
- endif
150
- endif
151
- let matched = 1
152
- break
153
- endif
154
- endfor
155
- if matched | continue | endif
156
-
157
- " Continuation
158
- if !empty(line) && !case.raw && line !~ '^ '
159
- throw 'Syntax error (line does not start with two spaces): ' . line
160
- endif
161
- if !empty(label)
162
- call add(buffer, line)
163
- endif
164
- endfor
165
- call s:flush_buffer(cases, case, fn, lnum, case.raw, label, '', buffer, 1)
166
-
167
- let ret = []
168
- let prev = {}
169
- for case in cases
170
- if has_key(case, "do") || has_key(case, "execute")
171
- call add(ret, extend(prev, case))
172
- let prev = {}
173
- else
174
- let prev = case
175
- endif
176
- endfor
177
- return ret
178
- endfunction
179
-
@@ -1,73 +0,0 @@
1
- " Copyright (c) 2014 Junegunn Choi
2
- "
3
- " MIT License
4
- "
5
- " Permission is hereby granted, free of charge, to any person obtaining
6
- " a copy of this software and associated documentation files (the
7
- " "Software"), to deal in the Software without restriction, including
8
- " without limitation the rights to use, copy, modify, merge, publish,
9
- " distribute, sublicense, and/or sell copies of the Software, and to
10
- " permit persons to whom the Software is furnished to do so, subject to
11
- " the following conditions:
12
- "
13
- " The above copyright notice and this permission notice shall be
14
- " included in all copies or substantial portions of the Software.
15
- "
16
- " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- " NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- let s:ifs = ['lua', 'perl', 'ruby', 'python']
25
-
26
- function! vader#syntax#reset()
27
- let b:vader_types = {}
28
- endfunction
29
-
30
- function! vader#syntax#include(l1, l2)
31
- let lines = filter(getline(a:l1, a:l2), '!empty(v:val) && v:val[0] != " "')
32
- for line in lines
33
- let match = matchlist(line, '^\(Given\|Expect\|Execute\)\s\+\([^:; (]\+\)')
34
- if len(match) >= 3
35
- silent! call s:load(match[2])
36
- endif
37
- endfor
38
- endfunction
39
-
40
- function! vader#syntax#_head()
41
- return '\(\(^\(Given\|Expect\|Do\|Execute\|Then\|Before\|After\)\(\s\+[^:;(]\+\)\?\s*\((.*)\)\?\s*[:;]\s*$\)\|\(^Include\(\s*(.*)\)\?\s*:\)\)\@='
42
- endfunction
43
-
44
- function! s:load(type)
45
- let b:vader_types = get(b:, 'vader_types', {})
46
- if has_key(b:vader_types, a:type)
47
- return
48
- endif
49
-
50
- if empty(globpath(&rtp, "syntax/".a:type.".vim", 1))
51
- return
52
- endif
53
-
54
- let b:vader_types[a:type] = 1
55
-
56
- unlet! b:current_syntax
57
- execute printf('syn include @%sSnippet syntax/%s.vim', a:type, a:type)
58
- execute printf('syn region vader_%s start=/^\s\{2,}/ end=/^\S\@=/ contains=@%sSnippet contained', a:type, a:type)
59
- execute printf('syn region vader_raw_%s start=/\(;\s*$\)\@<=/ end=/%s/ contains=@%sSnippet contained', a:type, vader#syntax#_head(), a:type)
60
-
61
- call s:define_syntax_region('Given', a:type)
62
- call s:define_syntax_region('Expect', a:type)
63
- if index(s:ifs, a:type) >= 0
64
- call s:define_syntax_region('Execute', a:type)
65
- endif
66
- let b:current_syntax = 'vader'
67
- endfunction
68
-
69
- function! s:define_syntax_region(block, lang)
70
- execute printf('syn region vader%s start=/^%s\s\+%s\s*\((.*)\)\?\s*:\s*$/ end=/\(^[^ ^#~=*-]\)\@=/ contains=vader%sType,vaderMessage,@vaderIgnored,vader_%s nextgroup=@vaderTopLevel skipempty keepend', a:block, a:block, a:lang, a:block, a:lang)
71
- execute printf('syn region vader%sRaw start=/^%s\s\+%s\s*\((.*)\)\?\s*;\s*$/ end=/%s/ contains=vader%sType,vaderMessage,@vaderIgnored,vader_raw_%s nextgroup=@vaderTopLevel skipempty keepend', a:block, a:block, a:lang, vader#syntax#_head(), a:block, a:lang)
72
- endfunction
73
-
@@ -1,205 +0,0 @@
1
- " Copyright (c) 2013 Junegunn Choi
2
- "
3
- " MIT License
4
- "
5
- " Permission is hereby granted, free of charge, to any person obtaining
6
- " a copy of this software and associated documentation files (the
7
- " "Software"), to deal in the Software without restriction, including
8
- " without limitation the rights to use, copy, modify, merge, publish,
9
- " distribute, sublicense, and/or sell copies of the Software, and to
10
- " permit persons to whom the Software is furnished to do so, subject to
11
- " the following conditions:
12
- "
13
- " The above copyright notice and this permission notice shall be
14
- " included in all copies or substantial portions of the Software.
15
- "
16
- " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- " EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- " NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- let s:quickfix_bfr = 0
25
- let s:console_bfr = 0
26
- let s:console_tab = 0
27
- let s:workbench_tab = 0
28
- let s:workbench_bfr = 0
29
-
30
- function! s:switch_to_console()
31
- execute 'normal! '.s:console_tab.'gt'
32
- call append(line('$') - 1, s:console_buffered)
33
- let s:console_buffered = []
34
- endfunction
35
-
36
- function! s:switch_to_workbench()
37
- execute 'normal! '.s:workbench_tab.'gt'
38
- execute 'b!' s:workbench_bfr
39
- endfunction
40
-
41
- function! vader#window#open()
42
- execute 'silent! bd' s:console_bfr
43
- execute 'silent! bd' s:workbench_bfr
44
- if bufexists(s:quickfix_bfr)
45
- execute "silent! bd ".s:quickfix_bfr
46
- endif
47
-
48
- let s:prev_winid = exists('*win_getid') ? win_getid() : 0
49
- tabnew
50
- setlocal buftype=nofile noswapfile nospell
51
- setf vader-result
52
- silent f \[Vader\]
53
- let s:console_tab = tabpagenr()
54
- let s:console_bfr = bufnr('')
55
- let s:console_buffered = []
56
- let b:vader_data = {}
57
- nnoremap <silent> <buffer> <CR> :call <SID>action(line('.'))<CR>
58
-
59
- tabnew
60
- setlocal buftype=nofile
61
- setlocal noswapfile
62
- silent f \[Vader-workbench\]
63
- let s:workbench_tab = tabpagenr()
64
- let s:workbench_bfr = bufnr('')
65
- endfunction
66
-
67
- function! vader#window#execute(lines, lang_if)
68
- let temp = tempname()
69
- try
70
- if empty(a:lang_if)
71
- let lines = a:lines
72
- else
73
- let lines = copy(a:lines)
74
- call insert(lines, a:lang_if . ' << __VADER__LANG__IF__')
75
- call add(lines, '__VADER__LANG__IF__')
76
- endif
77
- call writefile(lines, temp)
78
- execute 'source '.temp
79
- finally
80
- call delete(temp)
81
- endtry
82
- endfunction
83
-
84
- function! vader#window#replay(lines)
85
- call setreg('x', substitute(join(a:lines, ''), '\\<[^>]\+>', '\=eval("\"".submatch(0)."\"")', 'g'), 'c')
86
- normal! @x
87
- endfunction
88
-
89
- function! vader#window#result()
90
- return getline(1, line('$'))
91
- endfunction
92
-
93
- function! vader#window#append(message, indent, ...)
94
- let message = repeat(' ', a:indent) . a:message
95
- if get(a:, 1, 1)
96
- let message = substitute(message, '\s*$', '', '')
97
- endif
98
- if !exists('s:console_buffered')
99
- echom 'Vader:' message
100
- return 0
101
- endif
102
- call add(s:console_buffered, message)
103
- return len(s:console_buffered)
104
- endfunction
105
-
106
- function! vader#window#prepare(lines, type)
107
- call s:switch_to_workbench()
108
- execute 'setlocal modifiable filetype='.a:type
109
-
110
- silent %d _
111
- for line in a:lines
112
- call append(line('$') - 1, line)
113
- endfor
114
- silent d _
115
- execute "normal! \<c-\>\<c-n>gg0"
116
-
117
- let &undolevels = &undolevels " Break undo block
118
- endfunction
119
-
120
- function! vader#window#cleanup()
121
- execute 'silent! bd' s:workbench_bfr
122
- call s:switch_to_console()
123
- setlocal nomodifiable
124
- nnoremap <silent> <buffer> q :call <SID>quit()<CR><CR>
125
- normal! Gzb
126
- endfunction
127
-
128
- function! vader#window#copen()
129
- copen
130
- let s:quickfix_bfr = bufnr('')
131
- 1wincmd w
132
- normal! Gzb
133
- 2wincmd w
134
- nnoremap <silent> <buffer> q :call <SID>quit()<CR><CR>
135
- nnoremap <silent> <buffer> <CR> :call <SID>move()<CR><CR>
136
- endfunction
137
-
138
- function! vader#window#set_data(l1, l2, data)
139
- try
140
- let var = getbufvar(s:console_bfr, 'vader_data', {})
141
- for l in range(a:l1, a:l2)
142
- let var[l] = a:data
143
- endfor
144
- call setbufvar(s:console_bfr, 'vader_data', var)
145
- catch
146
- endtry
147
- endfunction
148
-
149
- function! s:scratch(type, data, title)
150
- setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap modifiable
151
- silent! execute 'setf '.a:type
152
- call append(0, a:data)
153
- nnoremap <silent> <buffer> q :tabclose<cr>
154
- autocmd TabLeave <buffer> tabclose
155
-
156
- execute 'silent f '.escape(a:title, '[]')
157
- normal! G"_ddgg
158
- diffthis
159
- setlocal nomodifiable
160
- endfunction
161
-
162
- function! s:action(line)
163
- if has_key(b:vader_data, a:line)
164
- let data = b:vader_data[a:line]
165
- if has_key(data, 'expect')
166
- tabnew
167
- call s:scratch(data.type, data.expect, '[Vader-expected]')
168
-
169
- vertical botright new
170
- call s:scratch(data.type, data.got, '[Vader-got]')
171
-
172
- redraw
173
- echo "Press 'q' to close"
174
- endif
175
- else
176
- execute "normal! \<CR>"
177
- endif
178
- endfunction
179
-
180
- function! s:move()
181
- let lno = matchstr(getline('.'), '(#[0-9]\+)')[2:-2]
182
- let wq = winnr()
183
- let wc = bufwinnr(s:console_bfr)
184
- if wc >= 0
185
- execute wc . 'wincmd w'
186
- let scrolloff = &scrolloff
187
- set scrolloff=0
188
- execute lno
189
- normal! zt
190
- redraw
191
- let &scrolloff = scrolloff
192
- execute wq . 'wincmd w'
193
- endif
194
- endfunction
195
-
196
- function! s:quit()
197
- if s:prev_winid
198
- let [s:t, s:w] = win_id2tabwin(s:prev_winid)
199
- if s:t
200
- execute printf('tabnext %d | %dwincmd w | %dtabclose', s:t, s:w, s:console_tab)
201
- return
202
- endif
203
- endif
204
- tabclose
205
- endfunction