(
server: LspServerDefinition,
mode: InstallActionMode = "install",
options: { promptConfirm?: boolean } = {},
)
| 717 | type InstallActionMode = "install" | "update" | "reinstall"; |
| 718 | |
| 719 | export async function installServer( |
| 720 | server: LspServerDefinition, |
| 721 | mode: InstallActionMode = "install", |
| 722 | options: { promptConfirm?: boolean } = {}, |
| 723 | ): Promise<boolean> { |
| 724 | const bundle = getServerBundle(server.id); |
| 725 | if (bundle?.installServer) { |
| 726 | return bundle.installServer(server.id, server, mode, options); |
| 727 | } |
| 728 | |
| 729 | const { promptConfirm = false } = options; |
| 730 | const cacheKey = getInstallCacheKey(server); |
| 731 | const displayLabel = getInstallLabel(server); |
| 732 | const isUpdate = mode === "update"; |
| 733 | const actionLabel = isUpdate ? "Update" : "Install"; |
| 734 | const command = |
| 735 | mode === "install" |
| 736 | ? getInstallCommand(server, "install") |
| 737 | : getUpdateCommand(server); |
| 738 | |
| 739 | if (!command) { |
| 740 | throw new Error( |
| 741 | `${displayLabel} has no ${actionLabel.toLowerCase()} command.`, |
| 742 | ); |
| 743 | } |
| 744 | |
| 745 | if (promptConfirm) { |
| 746 | let resolveThis: (val: boolean) => void; |
| 747 | let rejectThis: (err: Error) => void; |
| 748 | notificationManager.pushNotification({ |
| 749 | icon: "zap", |
| 750 | title: displayLabel, |
| 751 | message: strings["lsp-install-notification"].replace( |
| 752 | "{server}", |
| 753 | displayLabel, |
| 754 | ), |
| 755 | type: "warning", |
| 756 | action: async (notification) => { |
| 757 | notificationManager.closeNotification(notification); |
| 758 | try { |
| 759 | resolveThis(await installServer(server, mode)); |
| 760 | } catch (error) { |
| 761 | rejectThis(error as Error); |
| 762 | } |
| 763 | }, |
| 764 | onDismiss: () => { |
| 765 | resolveThis(false); |
| 766 | if (cacheKey) { |
| 767 | checkedCommands.set(cacheKey, STATUS_DECLINED); |
| 768 | } |
| 769 | }, |
| 770 | }); |
| 771 | |
| 772 | return new Promise((resolve, reject) => { |
| 773 | resolveThis = resolve; |
| 774 | rejectThis = reject; |
| 775 | }); |
| 776 | } |
no test coverage detected