]> git.madduck.net Git - etc/vim.git/blob - test/lsp/test_read_lsp_diagnostics.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / lsp / test_read_lsp_diagnostics.vader
1 Before:
2   function Range(start_line, start_char, end_line, end_char) abort
3     return {
4     \ 'start': {'line': a:start_line, 'character': a:start_char},
5     \ 'end': {'line': a:end_line, 'character': a:end_char},
6     \}
7   endfunction
8
9 After:
10   delfunction Range
11
12 Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
13   AssertEqual [
14   \   {
15   \     'type': 'E',
16   \     'text': 'Something went wrong!',
17   \     'lnum': 3,
18   \     'col': 11,
19   \     'end_lnum': 5,
20   \     'end_col': 15,
21   \     'code': 'some-error',
22   \   }
23   \ ],
24   \ ale#lsp#response#ReadDiagnostics([
25   \   {
26   \     'severity': 1,
27   \     'range': Range(2, 10, 4, 15),
28   \     'code': 'some-error',
29   \     'message': 'Something went wrong!',
30   \   },
31   \ ])
32
33 Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
34   AssertEqual [
35   \   {
36   \     'type': 'W',
37   \     'text': 'Something went wrong!',
38   \     'lnum': 2,
39   \     'col': 4,
40   \     'end_lnum': 2,
41   \     'end_col': 3,
42   \     'code': 'some-warning',
43   \   }
44   \ ],
45   \ ale#lsp#response#ReadDiagnostics([
46   \   {
47   \     'severity': 2,
48   \     'range': Range(1, 3, 1, 3),
49   \     'code': 'some-warning',
50   \     'message': 'Something went wrong!',
51   \   },
52   \ ])
53
54 Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing severity as errors):
55   AssertEqual [
56   \   {
57   \     'type': 'E',
58   \     'text': 'Something went wrong!',
59   \     'lnum': 3,
60   \     'col': 11,
61   \     'end_lnum': 5,
62   \     'end_col': 15,
63   \     'code': 'some-error',
64   \   }
65   \ ],
66   \ ale#lsp#response#ReadDiagnostics([
67   \   {
68   \     'range': Range(2, 10, 4, 15),
69   \     'code': 'some-error',
70   \     'message': 'Something went wrong!',
71   \   },
72   \ ])
73
74 Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes):
75   AssertEqual [
76   \   {
77   \     'type': 'E',
78   \     'text': 'Something went wrong!',
79   \     'lnum': 3,
80   \     'col': 11,
81   \     'end_lnum': 5,
82   \     'end_col': 15,
83   \   }
84   \ ],
85   \ ale#lsp#response#ReadDiagnostics([
86   \   {
87   \     'range': Range(2, 10, 4, 15),
88   \     'message': 'Something went wrong!',
89   \   },
90   \ ])
91
92 Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail):
93   AssertEqual [
94   \   {
95   \     'type': 'E',
96   \     'text': 'Something went wrong!',
97   \     'detail': '[tslint] Something went wrong!',
98   \     'lnum': 10,
99   \     'col': 15,
100   \     'end_lnum': 12,
101   \     'end_col': 22,
102   \   }
103   \ ],
104   \ ale#lsp#response#ReadDiagnostics([
105   \   {
106   \     'range': Range(9, 14, 11, 22),
107   \     'message': 'Something went wrong!',
108   \     'source': 'tslint',
109   \   }
110   \ ])
111
112 Execute(ale#lsp#response#ReadDiagnostics() should keep detail with line breaks but replace with spaces in text):
113   AssertEqual [
114   \   {
115   \     'type': 'E',
116   \     'text': 'cannot borrow `cap` as mutable more than once at a time  mutable borrow starts here in previous iteration of loop',
117   \     'detail': "[rustc] cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop",
118   \     'lnum': 10,
119   \     'col': 15,
120   \     'end_lnum': 12,
121   \     'end_col': 22,
122   \   }
123   \ ],
124   \ ale#lsp#response#ReadDiagnostics([
125   \   {
126   \     'range': Range(9, 14, 11, 22),
127   \     'message': "cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop",
128   \     'source': 'rustc',
129   \   }
130   \ ])
131
132 Execute(ale#lsp#response#ReadDiagnostics() should consider -1 to be a meaningless code):
133   AssertEqual [
134   \   {
135   \     'type': 'E',
136   \     'text': 'Something went wrong!',
137   \     'lnum': 3,
138   \     'col': 11,
139   \     'end_lnum': 5,
140   \     'end_col': 15,
141   \   }
142   \ ],
143   \ ale#lsp#response#ReadDiagnostics([
144   \   {
145   \     'range': Range(2, 10, 4, 15),
146   \     'message': 'Something went wrong!',
147   \     'code': -1,
148   \   },
149   \ ])
150
151 Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
152   AssertEqual [
153   \   {
154   \     'type': 'E',
155   \     'text': 'Something went wrong!',
156   \     'lnum': 1,
157   \     'col': 3,
158   \     'end_lnum': 1,
159   \     'end_col': 2,
160   \   },
161   \   {
162   \     'type': 'W',
163   \     'text': 'A warning',
164   \     'lnum': 2,
165   \     'col': 5,
166   \     'end_lnum': 2,
167   \     'end_col': 4,
168   \   },
169   \ ],
170   \ ale#lsp#response#ReadDiagnostics([
171   \   {
172   \     'range': Range(0, 2, 0, 2),
173   \     'message': 'Something went wrong!',
174   \   },
175   \   {
176   \     'severity': 2,
177   \     'range': Range(1, 4, 1, 4),
178   \     'message': 'A warning',
179   \   },
180   \ ])
181
182 Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for detail):
183   AssertEqual [
184   \   {
185   \     'type': 'E',
186   \     'text': 'Something went wrong!',
187   \     'lnum': 1,
188   \     'col': 3,
189   \     'end_lnum': 1,
190   \     'end_col': 2,
191   \     'detail': "Something went wrong!\n/tmp/someotherfile.txt:43:80:\n\tmight be this"
192   \   }
193   \ ],
194   \ ale#lsp#response#ReadDiagnostics([
195   \   {
196   \     'range': Range(0, 2, 0, 2),
197   \     'message': 'Something went wrong!',
198   \     'relatedInformation': [{
199   \         'message': 'might be this',
200   \         'location': {
201   \             'uri': 'file:///tmp/someotherfile.txt',
202   \             'range': {
203   \                 'start': { 'line': 42, 'character': 79 },
204   \                 'end': { 'line': 142, 'character': 179},
205   \             }
206   \         }
207   \     }]
208   \   }
209   \ ])
210
211 Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses):
212   AssertEqual
213   \ [
214   \   {
215   \     'type': 'E',
216   \     'nr': 2365,
217   \     'code': '2365',
218   \     'text': 'Operator ''''+'''' cannot be applied to types ''''3'''' and ''''{}''''.',
219   \     'lnum': 1,
220   \     'col': 11,
221   \     'end_lnum': 1,
222   \     'end_col': 16,
223   \   },
224   \ ],
225   \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/bar/foo.ts","diagnostics":[{"start":{"line":1,"offset":11},"end":{"line":1,"offset":17},"text":"Operator ''+'' cannot be applied to types ''3'' and ''{}''.","code":2365}]}})
226
227 Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle warnings from tsserver):
228   AssertEqual
229   \ [
230   \   {
231   \     'lnum': 27,
232   \     'col': 3,
233   \     'nr': 2515,
234   \     'code': '2515',
235   \     'end_lnum': 27,
236   \     'type': 'W',
237   \     'end_col': 13,
238   \     'text': 'Calls to ''console.log'' are not allowed. (no-console)',
239   \   }
240   \ ],
241   \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"<removed>","diagnostics":[{"start":{"line":27,"offset":3},"end":{"line":27,"offset":14},"text":"Calls to 'console.log' are not allowed. (no-console)","code":2515,"category":"warning","source":"tslint"}]}})
242
243 Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle suggestions from tsserver):
244   AssertEqual
245   \ [
246   \   {
247   \     'lnum': 27,
248   \     'col': 3,
249   \     'nr': 2515,
250   \     'code': '2515',
251   \     'end_lnum': 27,
252   \     'type': 'I',
253   \     'end_col': 13,
254   \     'text': 'Some info',
255   \   }
256   \ ],
257   \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"<removed>","diagnostics":[{"start":{"line":27,"offset":3},"end":{"line":27,"offset":14},"text":"Some info","code":2515,"category":"suggestion","source":"tslint"}]}})