summaryrefslogtreecommitdiff
path: root/test/lsp/test_read_lsp_diagnostics.vader
blob: be50fbe82d114df4a635887fde384c834f08be32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Before:
  function Range(start_line, start_char, end_line, end_char) abort
    return {
    \ 'start': {'line': a:start_line, 'character': a:start_char},
    \ 'end': {'line': a:end_line, 'character': a:end_char},
    \}
  endfunction

After:
  delfunction Range

Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 3,
  \     'col': 11,
  \     'end_lnum': 5,
  \     'end_col': 16,
  \     'code': 'some-error',
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'severity': 1,
  \     'range': Range(2, 10, 4, 15),
  \     'code': 'some-error',
  \     'message': 'Something went wrong!',
  \   },
  \ ]}})

Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
  AssertEqual [
  \   {
  \     'type': 'W',
  \     'text': 'Something went wrong!',
  \     'lnum': 2,
  \     'col': 4,
  \     'end_lnum': 2,
  \     'end_col': 4,
  \     'code': 'some-warning',
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'severity': 2,
  \     'range': Range(1, 3, 1, 3),
  \     'code': 'some-warning',
  \     'message': 'Something went wrong!',
  \   },
  \ ]}})

Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing severity as errors):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 3,
  \     'col': 11,
  \     'end_lnum': 5,
  \     'end_col': 16,
  \     'code': 'some-error',
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'range': Range(2, 10, 4, 15),
  \     'code': 'some-error',
  \     'message': 'Something went wrong!',
  \   },
  \ ]}})

Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 3,
  \     'col': 11,
  \     'end_lnum': 5,
  \     'end_col': 16,
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'range': Range(2, 10, 4, 15),
  \     'message': 'Something went wrong!',
  \   },
  \ ]}})

Execute(ale#lsp#response#ReadDiagnostics() should consider -1 to be a meaningless code):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 3,
  \     'col': 11,
  \     'end_lnum': 5,
  \     'end_col': 16,
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'range': Range(2, 10, 4, 15),
  \     'message': 'Something went wrong!',
  \     'code': -1,
  \   },
  \ ]}})


Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 1,
  \     'col': 3,
  \     'end_lnum': 1,
  \     'end_col': 3,
  \   },
  \   {
  \     'type': 'W',
  \     'text': 'A warning',
  \     'lnum': 2,
  \     'col': 5,
  \     'end_lnum': 2,
  \     'end_col': 5,
  \   },
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'range': Range(0, 2, 0, 2),
  \     'message': 'Something went wrong!',
  \   },
  \   {
  \     'severity': 2,
  \     'range': Range(1, 4, 1, 4),
  \     'message': 'A warning',
  \   },
  \ ]}})

Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for detail):
  AssertEqual [
  \   {
  \     'type': 'E',
  \     'text': 'Something went wrong!',
  \     'lnum': 1,
  \     'col': 3,
  \     'end_lnum': 1,
  \     'end_col': 3,
  \     'detail': "Something went wrong!\n/tmp/someotherfile.txt:43:80:\n\tmight be this"
  \   }
  \ ],
  \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
  \   {
  \     'range': Range(0, 2, 0, 2),
  \     'message': 'Something went wrong!',
  \     'relatedInformation': [{
  \         'message': 'might be this',
  \         'location': {
  \             'uri': 'file:///tmp/someotherfile.txt',
  \             'range': {
  \                 'start': { 'line': 42, 'character': 79 },
  \                 'end': { 'line': 142, 'character': 179},
  \             }
  \         }
  \     }]
  \   }
  \ ]}})

Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses):
  AssertEqual
  \ [
  \   {
  \     'type': 'E',
  \     'nr': 2365,
  \     'code': '2365',
  \     'text': 'Operator ''''+'''' cannot be applied to types ''''3'''' and ''''{}''''.',
  \     'lnum': 1,
  \     'col': 11,
  \     'end_lnum': 1,
  \     'end_col': 17,
  \   },
  \ ],
  \ 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}]}})

Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle warnings from tsserver):
  AssertEqual
  \ [
  \   {
  \     'lnum': 27,
  \     'col': 3,
  \     'nr': 2515,
  \     'code': '2515',
  \     'end_lnum': 27,
  \     'type': 'W',
  \     'end_col': 14,
  \     'text': 'Calls to ''console.log'' are not allowed. (no-console)',
  \   }
  \ ],
  \ 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"}]}})

Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle suggestions from tsserver):
  AssertEqual
  \ [
  \   {
  \     'lnum': 27,
  \     'col': 3,
  \     'nr': 2515,
  \     'code': '2515',
  \     'end_lnum': 27,
  \     'type': 'I',
  \     'end_col': 14,
  \     'text': 'Some info',
  \   }
  \ ],
  \ 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"}]}})