Commit 8f6c987
authored
Fix auto-imports (#491)
This change adds support for auto-imports.
The virtual code now contains an empty import of the JSX runtime. This
import was chosen, because it must exist anyway. This is immediately
followed by an empty code mapping, meaning TypeScript always has a place
to insert auto-imports.
Since JSX components can be injected, they are sometimes prefixed with
`_components.` in the virtual code. To support auto-import completions,
an additional mapping is now made to an expression containing merely the
identifier. As a result, the editor now shows auto-import completions,
unless `MDXProvidedComponents` is defined. I don’t know why the
existence of `MDXProvidedComponents` matters, but this probably matches
the expectation of users anyway.
The auto-imports will not be followed by a blank line. This can lead to
a syntax error in case no other imports exist yet. This is not ideal,
but easy and straight-forward to resolve manually.
Closes #4521 parent 4bb0a87 commit 8f6c987
4 files changed
Lines changed: 392 additions & 62 deletions
File tree
- .changeset
- packages
- language-server/test
- language-service
- lib
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
294 | 295 | | |
295 | 296 | | |
296 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
297 | 313 | | |
298 | 314 | | |
299 | 315 | | |
| |||
302 | 318 | | |
303 | 319 | | |
304 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
305 | 328 | | |
306 | 329 | | |
307 | 330 | | |
| |||
311 | 334 | | |
312 | 335 | | |
313 | 336 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
317 | 342 | | |
318 | 343 | | |
319 | 344 | | |
| |||
343 | 368 | | |
344 | 369 | | |
345 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
346 | 385 | | |
347 | 386 | | |
348 | 387 | | |
| |||
364 | 403 | | |
365 | 404 | | |
366 | 405 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | 406 | | |
375 | 407 | | |
376 | 408 | | |
| |||
482 | 514 | | |
483 | 515 | | |
484 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
485 | 528 | | |
486 | 529 | | |
487 | 530 | | |
| |||
624 | 667 | | |
625 | 668 | | |
626 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
627 | 680 | | |
628 | 681 | | |
629 | 682 | | |
| |||
741 | 794 | | |
742 | 795 | | |
743 | 796 | | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
| 797 | + | |
748 | 798 | | |
749 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
750 | 803 | | |
751 | 804 | | |
752 | 805 | | |
| |||
755 | 808 | | |
756 | 809 | | |
757 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
758 | 815 | | |
759 | 816 | | |
760 | 817 | | |
| |||
0 commit comments