コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        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);
            }
        }