|
6 | 6 | "testing" |
7 | 7 |
|
8 | 8 | "github.com/microsoft/typescript-go/internal/bundled" |
| 9 | + "github.com/microsoft/typescript-go/internal/ls/lsutil" |
9 | 10 | "github.com/microsoft/typescript-go/internal/lsp/lsproto" |
10 | 11 | "github.com/microsoft/typescript-go/internal/project" |
11 | 12 | "github.com/microsoft/typescript-go/internal/testutil/projecttestutil" |
@@ -662,4 +663,105 @@ func TestATA(t *testing.T) { |
662 | 663 | assert.NilError(t, err) |
663 | 664 | assert.Assert(t, ls != nil) |
664 | 665 | }) |
| 666 | + |
| 667 | + ataDisabledCases := []struct { |
| 668 | + name string |
| 669 | + config map[string]any |
| 670 | + }{ |
| 671 | + { |
| 672 | + name: "unified setting", |
| 673 | + config: map[string]any{ |
| 674 | + "js/ts": map[string]any{ |
| 675 | + "tsserver": map[string]any{ |
| 676 | + "automaticTypeAcquisition": map[string]any{ |
| 677 | + "enabled": false, |
| 678 | + }, |
| 679 | + }, |
| 680 | + }, |
| 681 | + }, |
| 682 | + }, |
| 683 | + { |
| 684 | + name: "deprecated setting", |
| 685 | + config: map[string]any{ |
| 686 | + "typescript": map[string]any{ |
| 687 | + "disableAutomaticTypeAcquisition": true, |
| 688 | + }, |
| 689 | + }, |
| 690 | + }, |
| 691 | + } |
| 692 | + |
| 693 | + for _, tc := range ataDisabledCases { |
| 694 | + t.Run("ATA disabled via "+tc.name, func(t *testing.T) { |
| 695 | + t.Parallel() |
| 696 | + |
| 697 | + files := map[string]any{ |
| 698 | + "/user/username/projects/project/app.js": ``, |
| 699 | + "/user/username/projects/project/package.json": `{ |
| 700 | + "name": "test", |
| 701 | + "dependencies": { |
| 702 | + "jquery": "^3.1.0" |
| 703 | + } |
| 704 | + }`, |
| 705 | + } |
| 706 | + |
| 707 | + session, utils := projecttestutil.SetupWithTypingsInstaller(files, &projecttestutil.TypingsInstallerOptions{ |
| 708 | + PackageToFile: map[string]string{ |
| 709 | + "jquery": `declare const $: { x: number }`, |
| 710 | + }, |
| 711 | + }) |
| 712 | + |
| 713 | + session.Configure(lsutil.ParseUserPreferences(tc.config)) |
| 714 | + session.DidOpenFile(context.Background(), lsproto.DocumentUri("file:///user/username/projects/project/app.js"), 1, files["/user/username/projects/project/app.js"].(string), lsproto.LanguageKindJavaScript) |
| 715 | + session.WaitForBackgroundTasks() |
| 716 | + |
| 717 | + calls := utils.NpmExecutor().NpmInstallCalls() |
| 718 | + assert.Equal(t, 0, len(calls), "Expected no npm install calls when ATA is disabled via "+tc.name) |
| 719 | + }) |
| 720 | + } |
| 721 | + |
| 722 | + t.Run("ATA re-enabled after being disabled triggers diagnostics refresh", func(t *testing.T) { |
| 723 | + t.Parallel() |
| 724 | + |
| 725 | + files := map[string]any{ |
| 726 | + "/user/username/projects/project/app.js": ``, |
| 727 | + "/user/username/projects/project/package.json": `{ |
| 728 | + "name": "test", |
| 729 | + "dependencies": { |
| 730 | + "jquery": "^3.1.0" |
| 731 | + } |
| 732 | + }`, |
| 733 | + } |
| 734 | + |
| 735 | + session, utils := projecttestutil.SetupWithTypingsInstaller(files, &projecttestutil.TypingsInstallerOptions{ |
| 736 | + PackageToFile: map[string]string{ |
| 737 | + "jquery": `declare const $: { x: number }`, |
| 738 | + }, |
| 739 | + }) |
| 740 | + |
| 741 | + // Disable ATA |
| 742 | + session.Configure(lsutil.ParseUserPreferences(map[string]any{ |
| 743 | + "js/ts": map[string]any{ |
| 744 | + "tsserver": map[string]any{ |
| 745 | + "automaticTypeAcquisition": map[string]any{ |
| 746 | + "enabled": false, |
| 747 | + }, |
| 748 | + }, |
| 749 | + }, |
| 750 | + })) |
| 751 | + |
| 752 | + session.DidOpenFile(context.Background(), lsproto.DocumentUri("file:///user/username/projects/project/app.js"), 1, files["/user/username/projects/project/app.js"].(string), lsproto.LanguageKindJavaScript) |
| 753 | + session.WaitForBackgroundTasks() |
| 754 | + |
| 755 | + calls := utils.NpmExecutor().NpmInstallCalls() |
| 756 | + assert.Equal(t, 0, len(calls), "Expected no npm install calls when ATA is disabled") |
| 757 | + |
| 758 | + baselineRefreshCount := len(utils.Client().RefreshDiagnosticsCalls()) |
| 759 | + |
| 760 | + // Re-enable ATA |
| 761 | + session.Configure(lsutil.ParseUserPreferences(map[string]any{})) |
| 762 | + session.WaitForBackgroundTasks() |
| 763 | + |
| 764 | + refreshCount := len(utils.Client().RefreshDiagnosticsCalls()) |
| 765 | + assert.Assert(t, refreshCount > baselineRefreshCount, "Expected RefreshDiagnostics call after ATA re-enabled") |
| 766 | + }) |
665 | 767 | } |
0 commit comments