Exemplo n.º 1
0
        public async Task OnLoadedAsync()
        {
            try {
                using (Log.CriticalOperation($"{nameof(OnLoadedAsync)}")) {
                    // ReSharper disable once PossibleNullReferenceException
                    await StartAsync?.InvokeAsync(this, EventArgs.Empty);

                    _hasStartedOnce = true;
                    Interlocked.Exchange(ref _state, 1);

                    if (_solutionEventListener == null)
                    {
                        var componentModel = ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
                        Assumes.Present(componentModel);

                        _solutionEventListener         = componentModel.GetService <ISolutionEventsListener>();
                        _solutionEventListener.Closed += SolutionOrFolder_Closed;
                        _solutionEventListener.Opened += SolutionOrFolder_Opened;
                        Log.Verbose($"set {nameof(_solutionEventListener)}");
                    }
                }
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(OnLoadedAsync));
            }
        }
 public async Task OnLoadedAsync()
 {
     if (StartAsync != null)
     {
         await StartAsync.InvokeAsync(this, EventArgs.Empty);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Signals that the extension has been loaded.
        /// The caller expects that <see cref="ActivateAsync(CancellationToken)"/> can be called
        /// immediately following the completion of this method.
        /// </summary>
        public async Task OnLoadedAsync()
        {
            // initialize things on UI thread
            await InitializeOnUIAsync().ConfigureAwait(false);

            // let platform know that they can start us
            await StartAsync.InvokeAsync(this, EventArgs.Empty).ConfigureAwait(false);

            async Task InitializeOnUIAsync()
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();

                // this doesn't attempt to solve our JTF and some services being not free-thread issue here, but
                // try to fix this particular deadlock issue only. we already have long discussion on
                // how we need to deal with JTF, Roslyn service requirements and VS services reality conflicting
                // each others. architectural fix should come from the result of that discussion.

                // Ensure the options persisters are loaded since we have to fetch options from the shell
                _lazyOptions.Select(o => o.Value);

                // experimentation service unfortunately uses JTF to jump to UI thread in certain cases
                // which can cause deadlock if 2 parties try to enable OOP from BG and then FG before
                // experimentation service tries to jump to UI thread.
                var experimentationService = _services.GetService <IExperimentationService>();
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Signals that the extension has been loaded.  The server can be started immediately, or wait for user action to start.
        /// To start the server, invoke the <see cref="StartAsync"/> event;
        /// </summary>
        public Task OnLoadedAsync()
        {
            var token = _asyncListener.BeginAsyncOperation("OnLoadedAsync");

            // set up event stream so that we start LSP server once Roslyn is loaded
            _eventListener.WorkspaceStarted.ContinueWith(async _ =>
            {
                // initialize things on UI thread
                await InitializeOnUIAsync().ConfigureAwait(false);

                // this might get called before solution is fully loaded and before file is opened.
                // we delay our OOP start until then, but user might do vsstart before that. so we make sure we start OOP if
                // it is not running yet. multiple start is no-op
                ((RemoteHostClientServiceFactory.RemoteHostClientService)_workspace.Services.GetService <IRemoteHostClientService>()).Enable();

                // wait until remote host is available before let platform know that they can activate our LSP
                var client = await _workspace.TryGetRemoteHostClientAsync(CancellationToken.None).ConfigureAwait(false);
                if (client == null)
                {
                    // there is no OOP. either user turned it off, or process got killed.
                    // don't ask platform to start LSP
                    return;
                }

                // let platform know that they can start us
                await StartAsync.InvokeAsync(this, EventArgs.Empty).ConfigureAwait(false);
            }, TaskScheduler.Default).CompletesAsyncOperation(token);

            return(Task.CompletedTask);

            async Task InitializeOnUIAsync()
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();

                // this doesn't attempt to solve our JTF and some services being not free-thread issue here, but
                // try to fix this particular deadlock issue only. we already have long discussion on
                // how we need to deal with JTF, Roslyn service requirements and VS services reality conflicting
                // each others. architectural fix should come from the result of that discussion.

                // Ensure the options persisters are loaded since we have to fetch options from the shell
                _lazyOptions.Select(o => o.Value);

                // experimentation service unfortunately uses JTF to jump to UI thread in certain cases
                // which can cause deadlock if 2 parties try to enable OOP from BG and then FG before
                // experimentation service tries to jump to UI thread.
                var experimentationService = _workspace.Services.GetService <IExperimentationService>();
            }
        }
        public async Task OnLoadedAsync()
        {
            var workingdirectoryresult = Util.GetWorkingDirectory();
            var sbt = await workingdirectoryresult.Fold(SBTProcess.StartSBT, () => throw new Exception("Visual Studio is not in folder mode"), () => throw new Exception("solution folder was null"));

            if (sbt == null)
            {
                throw new Exception("SBT failed to start");
            }
            StopAsync += (object sender, EventArgs args) =>
            {
                sbt.Kill();
                return(Task.CompletedTask);
            };
            await StartAsync?.InvokeAsync(this, EventArgs.Empty);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Signals that the extension has been loaded.
        /// The caller expects that <see cref="ActivateAsync(CancellationToken)"/> can be called
        /// immediately following the completion of this method.
        /// </summary>
        public async Task OnLoadedAsync()
        {
            // initialize things on UI thread
            await InitializeOnUIAsync().ConfigureAwait(false);

            // this might get called before solution is fully loaded and before file is opened.
            // we delay our OOP start until then, but user might do vsstart before that. so we make sure we start OOP if
            // it is not running yet. multiple start is no-op
            ((RemoteHostClientServiceFactory.RemoteHostClientService)_workspace.Services.GetService <IRemoteHostClientService>()).Enable();

            // wait until remote host is available before let platform know that they can activate our LSP
            var client = await RemoteHostClient.TryGetClientAsync(_workspace, CancellationToken.None).ConfigureAwait(false);

            if (client == null)
            {
                // There is no OOP. either user turned it off, or process got killed.
                // We should have already gotten a gold bar + nfw already if the OOP is missing.
                // so just log telemetry here so we can connect the two with session explorer.
                Logger.Log(FunctionId.LanguageServer_OnLoadedFailed, KeyValueLogMessage.NoProperty);
                // don't ask platform to start LSP.
                // we shouldn't throw as the LSP client does not expect exceptions here.
                return;
            }

            // let platform know that they can start us
            await StartAsync.InvokeAsync(this, EventArgs.Empty).ConfigureAwait(false);

            async Task InitializeOnUIAsync()
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();

                // this doesn't attempt to solve our JTF and some services being not free-thread issue here, but
                // try to fix this particular deadlock issue only. we already have long discussion on
                // how we need to deal with JTF, Roslyn service requirements and VS services reality conflicting
                // each others. architectural fix should come from the result of that discussion.

                // Ensure the options persisters are loaded since we have to fetch options from the shell
                _lazyOptions.Select(o => o.Value);

                // experimentation service unfortunately uses JTF to jump to UI thread in certain cases
                // which can cause deadlock if 2 parties try to enable OOP from BG and then FG before
                // experimentation service tries to jump to UI thread.
                var experimentationService = _workspace.Services.GetService <IExperimentationService>();
            }
        }
Exemplo n.º 8
0
        public async Task OnLoadedAsync()
        {
            await JoinableTaskContext.Factory.SwitchToMainThreadAsync();

            // Force the package to load, since this is a MEF component,
            // there is no guarantee it has been loaded.
            Site.GetPythonToolsService();

            // Client context cannot be created here since the is no workspace yet
            // and hence we don't know if this is workspace or a loose files case.
            _server = new LanguageServer(Site, JoinableTaskContext, this.OnSendToServer);
            InitializationOptions = null;
            var customTarget = new PythonLanguageClientCustomTarget(Site, JoinableTaskContext);

            CustomMessageTarget = customTarget;
            customTarget.WatchedFilesRegistered          += WatchedFilesRegistered;
            customTarget.WorkspaceFolderChangeRegistered += OnWorkspaceFolderWatched;
            customTarget.AnalysisComplete += OnAnalysisComplete;
            await StartAsync.InvokeAsync(this, EventArgs.Empty);
        }
Exemplo n.º 9
0
        private async Task StartStopRestartAsync(bool isReload)
        {
            try {
                if (isReload)
                {
                    isReloading = true;
                }
                OnStopping();
                await StopAsync?.InvokeAsync(this, EventArgs.Empty);

                OnStopped();
                await StartAsync?.InvokeAsync(this, EventArgs.Empty);

                var componentModel = ServiceProvider.GetService(typeof(SComponentModel)) as IComponentModel;
                Assumes.Present(componentModel);

                var agentService = componentModel.GetService <ICodeStreamAgentService>();
                await agentService.ReinitializeAsync();

                Interlocked.Exchange(ref _state, 1);
                Log.Debug($"SetState={_state}");
            }
            catch (NullReferenceException ex) {
                Log.LocalWarning(ex?.Message);
            }
            catch (Exception ex) {
                Log.Error(ex, nameof(RestartAsync));
            }
            finally {
                if (isReload)
                {
                    isReloading = false;
                }
            }
            await Task.CompletedTask;
        }
 /// <summary>
 /// Signals that the extension has been loaded.  The server can be started immediately, or wait for user action to start.
 /// To start the server, invoke the <see cref="StartAsync"/> event;
 /// </summary>
 public async Task OnLoadedAsync()
 {
     await StartAsync.InvokeAsync(this, EventArgs.Empty).ConfigureAwait(false);
 }
 public Task OnLoadedAsync()
 {
     return(StartAsync.InvokeAsync(this, EventArgs.Empty));
 }
Exemplo n.º 12
0
 public ThunkStart(StartAsync start)
 {
     SetField.NotNull(out this.start, nameof(start), start);
 }
Exemplo n.º 13
0
        internal Rest <DialogTask, object> ToRest(StartAsync start)
        {
            var thunk = new ThunkStart(start);

            return(thunk.Rest);
        }
Exemplo n.º 14
0
        internal Rest <object> ToRest(StartAsync start)
        {
            var thunk = new ThunkStart(this, start);

            return(thunk.Rest);
        }
Exemplo n.º 15
0
 public ThunkStart(DialogContext context, StartAsync start)
 {
     SetField.NotNull(out this.context, nameof(context), context);
     SetField.NotNull(out this.start, nameof(start), start);
 }
Exemplo n.º 16
0
 public async Task OnLoadedAsync()
 {
     await StartAsync?.InvokeAsync(this, EventArgs.Empty);
 }
Exemplo n.º 17
0
 async Task ILanguageClient.OnLoadedAsync()
 {
     await StartAsync.InvokeAsync(this, EventArgs.Empty);
 }
 public async System.Threading.Tasks.Task OnLoadedAsync()
 {
     await StartAsync.InvokeAsync(this, EventArgs.Empty).ConfigureAwait(false);
 }
Exemplo n.º 19
0
 public async System.Threading.Tasks.Task OnLoadedAsync()
 {
     await StartAsync?.InvokeAsync(this, EventArgs.Empty);
 }