]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_hover.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / test / test_hover.vader
1 Before:
2   call ale#test#SetDirectory('/testplugin/test')
3   call ale#test#SetFilename('dummy.txt')
4
5   let g:Callback = 0
6   let g:message_list = []
7   let g:item_list = []
8   let g:show_message_arg_list = []
9
10   let g:ale_floating_preview = 0
11   let g:ale_hover_to_floating_preview = 0
12   let g:ale_detail_to_floating_preview = 0
13
14   runtime autoload/ale/linter.vim
15   runtime autoload/ale/lsp.vim
16   runtime autoload/ale/lsp_linter.vim
17   runtime autoload/ale/util.vim
18   runtime autoload/ale/floating_preview.vim
19   runtime autoload/ale/hover.vim
20
21   let g:floated_lines = []
22   let g:floating_preview_show_called = 0
23
24   " Stub out so we can track the call
25   function! ale#floating_preview#Show(lines, ...) abort
26     let g:floating_preview_show_called = 1
27     let g:floated_lines = a:lines
28     return win_getid()
29   endfunction
30
31   function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
32     let g:Callback = a:callback
33
34     return {
35     \ 'command': 'foobar',
36     \ 'connection_id': 347,
37     \ 'project_root': '/foo/bar',
38     \}
39   endfunction
40
41   function! ale#lsp#Send(conn_id, message, root) abort
42     call add(g:message_list, a:message)
43
44     return 42
45   endfunction
46
47   function! ale#util#ShowMessage(string, ...) abort
48       call add(g:show_message_arg_list, [a:string] + a:000)
49   endfunction
50
51   function! HandleValidLSPResult(result) abort
52     " The cursor is beyond the length of the line.
53     " We will clamp the cursor position with the line length.
54     call setpos('.', [bufnr(''), 1, 5, 0])
55
56     call ale#hover#SetMap({3: {
57     \ 'buffer': bufnr(''),
58     \ 'line': 1,
59     \ 'column': 5,
60     \}})
61     call ale#hover#HandleLSPResponse(
62     \ 1,
63     \ {
64     \   'id': 3,
65     \   'result': a:result,
66     \ }
67     \)
68   endfunction
69
70
71 After:
72   call ale#hover#SetMap({})
73   call ale#test#RestoreDirectory()
74   call ale#linter#Reset()
75
76   unlet! g:Callback
77   unlet! g:message_list
78   unlet! b:ale_linters
79   unlet! g:show_message_arg_list
80
81   delfunction HandleValidLSPResult
82
83   runtime autoload/ale/lsp_linter.vim
84   runtime autoload/ale/lsp.vim
85   runtime autoload/ale/util.vim
86   runtime autoload/ale/floating_preview.vim
87
88 Given python(Some Python file):
89   foo
90   somelongerline
91   bazxyzxyzxyz
92
93 Execute(Other messages for the tsserver handler should be ignored):
94   call ale#hover#HandleTSServerResponse(1, {'command': 'foo'})
95
96 Execute(Failed hover responses should be handled correctly):
97   call ale#hover#SetMap({3: {}})
98   call ale#hover#HandleTSServerResponse(
99   \ 1,
100   \ {'command': 'quickinfo', 'request_seq': 3}
101   \)
102   AssertEqual {}, ale#hover#GetMap()
103
104 Given typescript(Some typescript file):
105   foo
106   somelongerline
107   bazxyzxyzxyz
108
109 Execute(tsserver quickinfo responses will null missing bodies should be handled):
110   call ale#hover#SetMap({3: {}})
111   call ale#hover#HandleTSServerResponse(
112   \ 1,
113   \ {
114   \   'command': 'quickinfo',
115   \   'request_seq': 3,
116   \   'success': v:true,
117   \ }
118   \)
119
120   AssertEqual {}, ale#hover#GetMap()
121
122 Execute(tsserver quickinfo displayString values should be displayed):
123   call ale#hover#SetMap({3: {'buffer': bufnr('')}})
124   call ale#hover#HandleTSServerResponse(
125   \ 1,
126   \ {
127   \   'command': 'quickinfo',
128   \   'request_seq': 3,
129   \   'success': v:true,
130   \   'body': {'displayString': 'foo bar'},
131   \ }
132   \)
133
134   AssertEqual [['foo bar']], g:show_message_arg_list
135   AssertEqual {}, ale#hover#GetMap()
136
137 Execute(LSP hover responses with just a string should be handled):
138   call HandleValidLSPResult({'contents': 'foobar'})
139
140   AssertEqual [['foobar', {'commands': []}]], g:show_message_arg_list
141   AssertEqual {}, ale#hover#GetMap()
142
143 Execute(LSP hover null responses should be handled):
144   call HandleValidLSPResult(v:null)
145
146   AssertEqual [], g:show_message_arg_list
147   AssertEqual {}, ale#hover#GetMap()
148
149 Execute(LSP hover responses with markup content should be handled):
150   call HandleValidLSPResult({'contents': {'kind': 'markdown', 'value': 'markup'}})
151
152   AssertEqual [['markup', {'commands': []}]], g:show_message_arg_list
153   AssertEqual {}, ale#hover#GetMap()
154
155 Execute(LSP hover responses with markup content missing values should be handled):
156   call HandleValidLSPResult({'contents': {'kind': 'markdown'}})
157
158   AssertEqual [], g:show_message_arg_list
159   AssertEqual {}, ale#hover#GetMap()
160
161 Execute(LSP hover response with lists of strings should be handled):
162   call HandleValidLSPResult({'contents': [
163   \  "foo\n",
164   \  "bar\n",
165   \]})
166
167   AssertEqual [["foo\n\nbar", {'commands': []}]], g:show_message_arg_list
168   AssertEqual {}, ale#hover#GetMap()
169
170 Execute(LSP hover response with lists of strings and marked strings should be handled):
171   call HandleValidLSPResult({'contents': [
172   \  {'language': 'python', 'value': 'foo'},
173   \  "bar\n",
174   \]})
175
176   AssertEqual [
177   \ [
178   \   "foo\n\nbar",
179   \   {
180   \     'commands': [
181   \       'unlet! b:current_syntax',
182   \       'syntax include @ALE_hover_python syntax/python.vim',
183   \       'syntax region ALE_hover_1 start=/\%1l/ end=/\%2l/ contains=@ALE_hover_python',
184   \     ],
185   \   },
186   \ ],
187   \], g:show_message_arg_list
188   AssertEqual {}, ale#hover#GetMap()
189
190 Execute(LSP hover with ale_floating_preview should float):
191   let g:ale_floating_preview = 1
192
193   call HandleValidLSPResult({'contents': "the message\ncontinuing"})
194
195   AssertEqual 1, g:floating_preview_show_called
196   AssertEqual ["the message", "continuing"], g:floated_lines
197
198 Execute(LSP hover ale_hover_to_floating_preview should float):
199   let g:ale_hover_to_floating_preview = 1
200
201   call HandleValidLSPResult({'contents': "the message\ncontinuing"})
202
203   AssertEqual 1, g:floating_preview_show_called
204   AssertEqual ["the message", "continuing"], g:floated_lines
205
206
207 Execute(LSP hover by default should not float):
208   call HandleValidLSPResult({'contents': "the message\ncontinuing"})
209
210   AssertEqual 0, g:floating_preview_show_called
211
212 Execute(tsserver responses for documentation requests should be handled):
213   call ale#hover#SetMap({3: {'show_documentation': 1, 'buffer': bufnr('')}})
214
215   call ale#hover#HandleTSServerResponse(
216   \ 1,
217   \ {
218   \   'command': 'quickinfo',
219   \   'request_seq': 3,
220   \   'success': v:true,
221   \   'body': {
222   \     'documentation': 'foo is a very good method',
223   \     'displayString': 'foo bar',
224   \   },
225   \ }
226   \)
227
228   " The preview window should show the text.
229   AssertEqual ['foo is a very good method'], ale#test#GetPreviewWindowText()
230   silent! pclose
231
232 Execute(hover with show_documentation should be in the preview window, not floating):
233   let g:ale_hover_to_floating_preview = 1
234   let g:ale_floating_preview = 1
235
236   call ale#hover#SetMap({3: {'show_documentation': 1, 'buffer': bufnr('')}})
237
238   call ale#hover#HandleTSServerResponse(
239   \ 1,
240   \ {
241   \   'command': 'quickinfo',
242   \   'request_seq': 3,
243   \   'success': v:true,
244   \   'body': {
245   \     'documentation': 'foo is a very good method',
246   \     'displayString': 'foo bar ',
247   \   },
248   \ }
249   \)
250
251   let expected = ["Every statement should end with a semicolon", "second line"]
252
253   AssertEqual 0, g:floating_preview_show_called
254
255 Execute(TSServer hover without show_documentation and ale_floating_preview should float):
256   let g:ale_floating_preview = 1
257
258   call ale#hover#SetMap({3: {'buffer': bufnr('')}})
259
260   call ale#hover#HandleTSServerResponse(
261   \ 1,
262   \ {
263   \   'command': 'quickinfo',
264   \   'request_seq': 3,
265   \   'success': v:true,
266   \   'body': {
267   \     'displayString': "the message\ncontinuing",
268   \   },
269   \ }
270   \)
271
272   AssertEqual 1, g:floating_preview_show_called
273   AssertEqual ["the message", "continuing"], g:floated_lines