Esempio n. 1
0
        private static void DoObserveWorkDone(ILanguageProtocolProxy proxy, IWorkDoneProgressParams @params, IWorkDoneProgressObserver observer)
        {
            var token      = @params.WorkDoneToken ??= new ProgressToken(Guid.NewGuid().ToString());
            var observable = proxy.GetRequiredService <IClientWorkDoneManager>().Monitor(token);

            observable.Subscribe(
                v => {
                switch (v)
                {
                case WorkDoneProgressBegin begin:
                    observer.OnBegin(begin);
                    break;

                case WorkDoneProgressReport report:
                    observer.OnReport(report);
                    break;

                case WorkDoneProgressEnd end:
                    observer.OnEnd(end);
                    break;
                }
            },
                observer.OnError,
                observer.OnCompleted
                );
        }
Esempio n. 2
0
 private static ProgressToken SetWorkDoneToken(IWorkDoneProgressParams @params)
 {
     if (@params.WorkDoneToken is not null)
     {
         return(@params.WorkDoneToken);
     }
     WorkDoneTokenProperty.SetValue(@params, new ProgressToken(Guid.NewGuid().ToString()));
     return(@params.WorkDoneToken !);
 }
Esempio n. 3
0
        public static async Task SetWorkspaceRoots(IEnumerable <string> workspaceFolders,
                                                   ProgressManager progressManager, IWorkDoneProgressParams workDoneProgressParams)
        {
            WorkspaceFolders.OnNext(workspaceFolders.ToImmutableList());

            var completionSource     = new TaskCompletionSource <bool>();
            var initialParseProgress = progressManager.WorkDone(workDoneProgressParams, new WorkDoneProgressBegin()
            {
                Title      = "Begin parsing workspace",
                Percentage = 0
            });

            var partProgresses = GlobalParseCache.BeginAddOrUpdatePaths(WorkspaceFolders.Value, finishedHandler:
                                                                        ea =>
            {
                initialParseProgress.OnNext(new WorkDoneProgressReport()
                {
                    Message    = "Done parsing workspace",
                    Percentage = 100
                });
                initialParseProgress.OnCompleted();
                completionSource.SetResult(true);
            });

            int partIndex = 1;

            foreach (var statisticsHandle in partProgresses)
            {
                initialParseProgress.OnNext(new WorkDoneProgressReport()
                {
                    Percentage = partIndex / partProgresses.Count,
                    Message    = "Parse " + statisticsHandle.basePath
                });
                statisticsHandle.WaitForCompletion();
                partIndex++;

                initialParseProgress.OnNext(new WorkDoneProgressReport()
                {
                    Percentage = partIndex / partProgresses.Count,
                    Message    = "Finished parsing " + statisticsHandle.basePath
                });
            }

            await completionSource.Task;
        }
        /// <summary>
        /// Creates a <see cref="IWorkDoneObserver" /> that will send all of its progress information to the same source.
        /// </summary>
        public IWorkDoneObserver For(
            IWorkDoneProgressParams request,
            WorkDoneProgressBegin begin, Func <Exception, WorkDoneProgressEnd> onError = null,
            Func <WorkDoneProgressEnd> onComplete = null
            )
        {
            if (!IsSupported || request.WorkDoneToken == null)
            {
                return(NoopWorkDoneObserver.Instance);
            }

            if (_activeObservers.TryGetValue(request.WorkDoneToken, out var item))
            {
                return(item);
            }

            onError ??= error => new WorkDoneProgressEnd {
                Message = error.ToString()
            };

            onComplete ??= () => new WorkDoneProgressEnd();
            var cts      = new CancellationTokenSource();
            var observer = new WorkDoneObserver(
                request.WorkDoneToken,
                _router,
                _serializer,
                begin,
                onError,
                onComplete,
                cts.Token
                );

            _activeObservers.TryAdd(observer.WorkDoneToken, observer);
            _activeObserverTokens.TryAdd(observer.WorkDoneToken, cts);

            return(observer);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a <see cref="ProgressObserver" /> that will send all of its progress information to the same source.
        /// </summary>
        public ProgressObserver <WorkDoneProgressReport> WorkDone(IWorkDoneProgressParams request,
                                                                  WorkDoneProgressBegin begin, Func <Exception, WorkDoneProgressEnd> onError = null,
                                                                  Func <WorkDoneProgressEnd> onComplete = null, CancellationToken?cancellationToken = null)
        {
            if (!_supported || request.WorkDoneToken == null)
            {
                return(ProgressObserver <WorkDoneProgressReport> .Noop);
            }

            if (_activeObservers.TryGetValue(request.WorkDoneToken, out var item))
            {
                return((ProgressObserver <WorkDoneProgressReport>)item);
            }

            onError ??= error => new WorkDoneProgressEnd()
            {
                Message = error.ToString()
            };

            onComplete ??= () => new WorkDoneProgressEnd();

            var observer = ProgressObserver.CreateWorkDoneProgress(request.WorkDoneToken, _router, _serializer, begin,
                                                                   onError, onComplete, cancellationToken ?? CancellationToken.None);

            _activeObservers.TryAdd(observer.ProgressToken, observer);

            observer.CancellationToken.Register(() =>
            {
                if (_activeObservers.TryRemove(request.WorkDoneToken, out _))
                {
                    observer.OnCompleted();
                }
            });

            return(observer);
        }
Esempio n. 6
0
        private static void DoObserveWorkDone(ILanguageProtocolProxy proxy, IWorkDoneProgressParams @params, IObserver <WorkDoneProgress> observer)
        {
            var token = @params.WorkDoneToken ??= new ProgressToken(Guid.NewGuid().ToString());

            proxy.GetRequiredService <IClientWorkDoneManager>().Monitor(token).Subscribe(observer);
        }
Esempio n. 7
0
        private static void DoObserveWorkDone(ILanguageProtocolProxy proxy, IWorkDoneProgressParams @params, IObserver <WorkDoneProgress> observer)
        {
            var token = SetWorkDoneToken(@params);

            proxy.GetRequiredService <IClientWorkDoneManager>().Monitor(token).Subscribe(observer);
        }
Esempio n. 8
0
 public static void SendWorkDoneProgressCancel(this IWindowLanguageClient mediator, IWorkDoneProgressParams @params) =>
 mediator.SendNotification(
     WindowNames.WorkDoneProgressCancel, new WorkDoneProgressCancelParams {
     Token = @params.WorkDoneToken
 }
     );
        private static void DoObserveWorkDone(IClientProxy proxy, IWorkDoneProgressParams @params, IObserver <WorkDoneProgress> observer)
        {
            var token = @params.WorkDoneToken ??= new ProgressToken(Guid.NewGuid().ToString());

            proxy.WorkDoneManager.Monitor(token).Subscribe(observer);
        }