test_tsserver_completion_parsing.vader
1 Before: 2 Save g:ale_completion_tsserver_remove_warnings 3 4 let g:ale_completion_tsserver_remove_warnings = 0 5 6 After: 7 Restore 8 9 unlet! b:ale_tsserver_completion_names 10 11 Execute(TypeScript completions responses should be parsed correctly): 12 AssertEqual [], 13 \ ale#completion#ParseTSServerCompletions({ 14 \ 'body': [], 15 \}) 16 AssertEqual 17 \ [ 18 \ { 19 \ 'word': 'foo', 20 \ 'source': '/path/to/foo.ts', 21 \ }, 22 \ { 23 \ 'word': 'bar', 24 \ 'source': '', 25 \ }, 26 \ { 27 \ 'word': 'baz', 28 \ 'source': '', 29 \ } 30 \ ], 31 \ ale#completion#ParseTSServerCompletions({ 32 \ 'body': [ 33 \ {'name': 'foo', 'source': '/path/to/foo.ts'}, 34 \ {'name': 'bar'}, 35 \ {'name': 'baz'}, 36 \ ], 37 \}) 38 39 Execute(TypeScript completions responses should include warnings): 40 AssertEqual 41 \ [ 42 \ { 43 \ 'word': 'foo', 44 \ 'source': '/path/to/foo.ts', 45 \ }, 46 \ { 47 \ 'word': 'bar', 48 \ 'source': '', 49 \ }, 50 \ { 51 \ 'word': 'baz', 52 \ 'source': '', 53 \ } 54 \ ], 55 \ ale#completion#ParseTSServerCompletions({ 56 \ 'body': [ 57 \ {'name': 'foo', 'source': '/path/to/foo.ts'}, 58 \ {'name': 'bar', 'kind': 'warning'}, 59 \ {'name': 'baz'}, 60 \ ], 61 \}) 62 63 Execute(TypeScript completions responses should not include warnings if excluded): 64 let g:ale_completion_tsserver_remove_warnings = 1 65 AssertEqual 66 \ [ 67 \ { 68 \ 'word': 'foo', 69 \ 'source': '/path/to/foo.ts', 70 \ }, 71 \ { 72 \ 'word': 'baz', 73 \ 'source': '', 74 \ } 75 \ ], 76 \ ale#completion#ParseTSServerCompletions({ 77 \ 'body': [ 78 \ {'name': 'foo', 'source': '/path/to/foo.ts'}, 79 \ {'name': 'bar', 'kind': 'warning'}, 80 \ {'name': 'baz'}, 81 \ ], 82 \}) 83 84 Execute(TypeScript completion details responses should be parsed correctly): 85 AssertEqual 86 \ [ 87 \ { 88 \ 'word': 'abc', 89 \ 'menu': '(property) Foo.abc: number', 90 \ 'info': '', 91 \ 'kind': 'v', 92 \ 'icase': 1, 93 \ 'user_data': json_encode({'_ale_completion_item': 1}), 94 \ 'dup': g:ale_completion_autoimport, 95 \ }, 96 \ { 97 \ 'word': 'def', 98 \ 'menu': '(property) Foo.def: number', 99 \ 'info': 'foo bar baz', 100 \ 'kind': 'v', 101 \ 'icase': 1, 102 \ 'user_data': json_encode({'_ale_completion_item': 1}), 103 \ 'dup': g:ale_completion_autoimport, 104 \ }, 105 \ { 106 \ 'word': 'ghi', 107 \ 'menu': '(class) Foo', 108 \ 'info': '', 109 \ 'kind': 'v', 110 \ 'icase': 1, 111 \ 'user_data': json_encode({'_ale_completion_item': 1}), 112 \ 'dup': g:ale_completion_autoimport, 113 \ }, 114 \ ], 115 \ ale#completion#ParseTSServerCompletionEntryDetails({ 116 \ 'body': [ 117 \ { 118 \ 'name': 'abc', 119 \ 'kind': 'parameterName', 120 \ 'displayParts': [ 121 \ {'text': '('}, 122 \ {'text': 'property'}, 123 \ {'text': ')'}, 124 \ {'text': ' '}, 125 \ {'text': 'Foo'}, 126 \ {'text': '.'}, 127 \ {'text': 'abc'}, 128 \ {'text': ':'}, 129 \ {'text': ' '}, 130 \ {'text': 'number'}, 131 \ ], 132 \ }, 133 \ { 134 \ 'name': 'def', 135 \ 'kind': 'parameterName', 136 \ 'displayParts': [ 137 \ {'text': '('}, 138 \ {'text': 'property'}, 139 \ {'text': ')'}, 140 \ {'text': ' '}, 141 \ {'text': 'Foo'}, 142 \ {'text': '.'}, 143 \ {'text': 'def'}, 144 \ {'text': ':'}, 145 \ {'text': ' '}, 146 \ {'text': 'number'}, 147 \ ], 148 \ 'documentation': [ 149 \ {'text': 'foo'}, 150 \ {'text': ' '}, 151 \ {'text': 'bar'}, 152 \ {'text': ' '}, 153 \ {'text': 'baz'}, 154 \ ], 155 \ }, 156 \ { 157 \ 'name': 'ghi', 158 \ 'kind': 'className', 159 \ 'displayParts': [ 160 \ {'text': '('}, 161 \ {'text': 'class'}, 162 \ {'text': ')'}, 163 \ {'text': ' '}, 164 \ {'text': 'Foo'}, 165 \ ], 166 \ }, 167 \ ], 168 \}) 169 170 Execute(Entries without details should be included in the responses): 171 let b:ale_tsserver_completion_names = [{ 172 \ 'word': 'xyz', 173 \ 'source': '/path/to/xyz.ts', 174 \ }] 175 176 AssertEqual 177 \ [ 178 \ { 179 \ 'word': 'abc', 180 \ 'menu': 'import { def } from "./Foo"; (property) Foo.abc: number', 181 \ 'info': '', 182 \ 'kind': 'v', 183 \ 'icase': 1, 184 \ 'user_data': json_encode({ 185 \ '_ale_completion_item': 1, 186 \ 'code_actions': [{ 187 \ 'description': 'import { def } from "./Foo";', 188 \ 'changes': [], 189 \ }], 190 \ }), 191 \ 'dup': g:ale_completion_autoimport, 192 \ }, 193 \ { 194 \ 'word': 'def', 195 \ 'menu': '(property) Foo.def: number', 196 \ 'info': 'foo bar baz', 197 \ 'kind': 'v', 198 \ 'icase': 1, 199 \ 'user_data': json_encode({'_ale_completion_item': 1}), 200 \ 'dup': g:ale_completion_autoimport, 201 \ }, 202 \ { 203 \ 'word': 'xyz', 204 \ 'menu': '', 205 \ 'info': '', 206 \ 'kind': 'v', 207 \ 'user_data': json_encode({'_ale_completion_item': 1}), 208 \ 'icase': 1, 209 \ }, 210 \ ], 211 \ ale#completion#ParseTSServerCompletionEntryDetails({ 212 \ 'body': [ 213 \ { 214 \ 'name': 'abc', 215 \ 'kind': 'parameterName', 216 \ 'displayParts': [ 217 \ {'text': '('}, 218 \ {'text': 'property'}, 219 \ {'text': ')'}, 220 \ {'text': ' '}, 221 \ {'text': 'Foo'}, 222 \ {'text': '.'}, 223 \ {'text': 'abc'}, 224 \ {'text': ':'}, 225 \ {'text': ' '}, 226 \ {'text': 'number'}, 227 \ ], 228 \ 'codeActions': [{ 229 \ 'description': 'import { def } from "./Foo";', 230 \ 'changes': [], 231 \ }], 232 \ }, 233 \ { 234 \ 'name': 'def', 235 \ 'kind': 'parameterName', 236 \ 'displayParts': [ 237 \ {'text': '('}, 238 \ {'text': 'property'}, 239 \ {'text': ')'}, 240 \ {'text': ' '}, 241 \ {'text': 'Foo'}, 242 \ {'text': '.'}, 243 \ {'text': 'def'}, 244 \ {'text': ':'}, 245 \ {'text': ' '}, 246 \ {'text': 'number'}, 247 \ ], 248 \ 'documentation': [ 249 \ {'text': 'foo'}, 250 \ {'text': ' '}, 251 \ {'text': 'bar'}, 252 \ {'text': ' '}, 253 \ {'text': 'baz'}, 254 \ ], 255 \ }, 256 \ ], 257 \}) 258 259 Execute(Default imports should be handled correctly): 260 AssertEqual 261 \ [ 262 \ { 263 \ 'word': 'abcd', 264 \ 'menu': 'Import default ''abcd'' from module "./foo" (alias) const abcd: 3', 265 \ 'info': '', 266 \ 'kind': 't', 267 \ 'icase': 1, 268 \ 'user_data': json_encode({ 269 \ '_ale_completion_item': 1, 270 \ 'code_actions': [{ 271 \ 'description': 'Import default ''abcd'' from module "./foo"', 272 \ 'changes': [], 273 \ }], 274 \ }), 275 \ 'dup': g:ale_completion_autoimport, 276 \ }, 277 \ ], 278 \ ale#completion#ParseTSServerCompletionEntryDetails({ 279 \ 'body': [ 280 \ { 281 \ 'name': 'default', 282 \ 'kind': 'alias', 283 \ 'displayParts': [ 284 \ {'kind': 'punctuation', 'text': '('}, 285 \ {'kind': 'text', 'text': 'alias'}, 286 \ {'kind': 'punctuation', 'text': ')'}, 287 \ {'kind': 'space', 'text': ' '}, 288 \ {'kind': 'keyword', 'text': 'const'}, 289 \ {'kind': 'space', 'text': ' '}, 290 \ {'kind': 'localName', 'text': 'abcd'}, 291 \ {'kind': 'punctuation', 'text': ':'}, 292 \ {'kind': 'space', 'text': ' '}, 293 \ {'kind': 'stringLiteral', 'text': '3'}, 294 \ {'kind': 'lineBreak', 'text': '^@'}, 295 \ {'kind': 'keyword', 'text': 'export'}, 296 \ {'kind': 'space', 'text': ' '}, 297 \ {'kind': 'keyword', 'text': 'default'}, 298 \ {'kind': 'space', 'text': ' '}, 299 \ {'kind': 'aliasName', 'text': 'abcd'} 300 \ ], 301 \ 'codeActions': [ 302 \ { 303 \ 'description': 'Import default ''abcd'' from module "./foo"', 304 \ 'changes': [], 305 \ }, 306 \ ], 307 \ }, 308 \ ], 309 \ })