Ejemplo n.º 1
0
        public static async Task <bool> WaitForSingleButtonInfoBarAsync(InfoBar infoBar)
        {
            if (infoBar.ActionItems.Count != 1)
            {
                throw new ArgumentException($"{nameof(infoBar)} has more than one button element");
            }

            var completionSource = new TaskCompletionSource <bool>();

            var button = (InfoBarButton)infoBar.ActionItems.GetItem(0);

            button.OnClick += (source, e) =>
            {
                completionSource.SetResult(true);
                e.InfoBarUIElement.Close();
            };

            infoBar.OnClosed += () =>
            {
                completionSource.TrySetResult(false);
            };

            await VsUtilities.ShowInfoBar(infoBar);

            return(await completionSource.Task);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Displays an info bar with one button and waits until the user closes it or clicks the button.
        /// </summary>
        /// <param name="infoBar">The infobar to display.</param>
        /// <param name="serviceProvider">The async service provider.</param>
        /// <returns>A task that completes when the info bar has been closed or the button selected.
        /// The task completes with true if the button was pressed or false if the info bar was closed.</returns>
        public static async Task <bool> WaitForSingleButtonInfoBarAsync(VsUtilities.InfoBar infoBar, IAsyncServiceProvider serviceProvider)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (infoBar.ActionItems.Count != 1)
            {
                throw new ArgumentException($"{nameof(infoBar)} has more than one button element");
            }

            var completionSource = new TaskCompletionSource <bool>();

            var button = (VsUtilities.InfoBarButton)infoBar.ActionItems.GetItem(0);

            button.OnClick += (source, e) =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                completionSource.SetResult(true);
                e.InfoBarUIElement.Close();
            };

            infoBar.OnClosed += () =>
            {
                completionSource.TrySetResult(false);
            };

            await VsUtilities.ShowInfoBarAsync(infoBar, serviceProvider);

            return(await completionSource.Task);
        }
        /// <inheritdoc/>
        public async Task OnLoadedAsync()
        {
            var rustup = new Rustup(this.optionsModel.RustupPath);

            if (!await rustup.IsInstalledAsync())
            {
                var infoBar = new VsUtilities.InfoBar("could not start the rls: rustup is not installed or not on the path");
                await VsUtilities.ShowInfoBarAsync(infoBar, this.serviceProvider);

                return;
            }

            var toolchain = this.optionsModel.Toolchain;

            if (!await rustup.HasToolchainAsync(toolchain))
            {
                var infoBar = new VsUtilities.InfoBar($"configured toolchain {toolchain} is not installed", new VsUtilities.InfoBarButton("Install"));
                if (await Utilities.WaitForSingleButtonInfoBarAsync(infoBar, this.serviceProvider))
                {
                    var task = rustup.InstallToolchainAsync(toolchain);
                    await VsUtilities.CreateTaskAsync($"Installing {toolchain}", this.serviceProvider, task);

                    if (await task != 0)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            // Check for necessary rls components
            if (!await rustup.HasComponentAsync("rls", toolchain) ||
                !await rustup.HasComponentAsync("rust-analysis", toolchain) ||
                !await rustup.HasComponentAsync("rust-src", toolchain))
            {
                if (!await this.InstallComponentsAsync(rustup, toolchain, "rls-preview", "rust-analysis", "rust-src"))
                {
                    var infoBar = new VsUtilities.InfoBar("could not install one of the required rls components");
                    await VsUtilities.ShowInfoBarAsync(infoBar, this.serviceProvider);

                    return;
                }
            }

            if (this.StartAsync != null)
            {
                await this.StartAsync.InvokeAsync(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 4
0
        public async System.Threading.Tasks.Task OnLoadedAsync()
        {
            var toolchain = OptionsModel.Toolchain;

            if (!await Rustup.HasToolchain(toolchain))
            {
                var infoBar = new VsUtilities.InfoBar($"configured toolchain {toolchain} is not installed", new VsUtilities.InfoBarButton("Install"));
                if (await Utilities.WaitForSingleButtonInfoBarAsync(infoBar))
                {
                    var task = Rustup.InstallToolchain(toolchain).ContinueWith(t => t.Result == 0);
                    await VsUtilities.CreateTask($"Installing {toolchain}", task);

                    if (!await task)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            if (!await Rustup.HasComponent("rls-preview", toolchain))
            {
                if (!await InstallComponent("rls-preview", toolchain))
                {
                    return;
                }
            }

            if (!await Rustup.HasComponent("rust-analysis", toolchain))
            {
                if (!await InstallComponent("rust-analysis", toolchain))
                {
                    return;
                }
            }

            if (!await Rustup.HasComponent("rust-src", toolchain))
            {
                if (!await InstallComponent("rust-src", toolchain))
                {
                    return;
                }
            }

            if (StartAsync != null)
            {
                await StartAsync.InvokeAsync(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 5
0
        private async Task <bool> InstallComponent(string component, string toolchain)
        {
            var infoBar = new VsUtilities.InfoBar($"component '{component}' is not installed", new VsUtilities.InfoBarButton("Install"));

            if (await Utilities.WaitForSingleButtonInfoBarAsync(infoBar))
            {
                var task = Rustup.InstallComponent(component, toolchain).ContinueWith(t => t.Result == 0);
                await VsUtilities.CreateTask($"Installing {component}", task);

                return(await task);
            }
            else
            {
                return(false);
            }
        }
        private async Task <bool> InstallComponentsAsync(Rustup rustup, string toolchain, params string[] components)
        {
            VsUtilities.InfoBar infoBar;
            if (components.Length == 1)
            {
                infoBar = new VsUtilities.InfoBar($"component '{components[0]}' is not installed", new VsUtilities.InfoBarButton("Install"));
            }
            else
            {
                infoBar = new VsUtilities.InfoBar("required components are not installed", new VsUtilities.InfoBarButton("Install"));
            }

            if (await Utilities.WaitForSingleButtonInfoBarAsync(infoBar, this.serviceProvider))
            {
                var task = rustup.InstallComponentsAsync(toolchain, components);
                await VsUtilities.CreateTaskAsync($"Installing components", this.serviceProvider, task);

                return(await task == 0);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Shows a basic infobar notification.
 /// </summary>
 /// <param name="notification">The text of the notification.</param>
 /// <param name="serviceProvider">VS async service provider.</param>
 /// <returns>A task that completes once the infobar is displayed.</returns>
 public static async Task ShowNotoficationAsync(string notification, IAsyncServiceProvider serviceProvider)
 {
     var infoBar = new VsUtilities.InfoBar(notification);
     await VsUtilities.ShowInfoBarAsync(infoBar, serviceProvider);
 }