Example #1
0
        public override void Dispose()
        {
            if (Interlocked.Exchange(ref isSubscribed, NOT_SUBSCRIBED) == SUBSCRIBED && ColorizerTagger != null)
            {
                ColorizerTagger.TagsChanged -= OnColorizingTaggerTagsChanged;
                ColorizerTagger              = null;
            }

            base.Dispose();
        }
        private static Task AfterTaggingActionAsync(PXColorizerTaggerBase tagger, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(cancellationToken));
            }

            // We should be on UI thread here but the tagger.RaiseTagsChangedAsync switches to UI thread from non UI threads internally if needed
            return(Shell.ThreadHelper.JoinableTaskFactory.RunAsync(tagger.RaiseTagsChangedAsync).Task);
        }
Example #3
0
        private void SubscribeToColorizingTaggerEvents(PXColorizerTaggerBase colorizerTagger)
        {
            if (colorizerTagger.TaggerType == TaggerType.RegEx)
            {
                return;
            }

            if (Interlocked.Exchange(ref isSubscribed, SUBSCRIBED) == NOT_SUBSCRIBED)
            {
                ColorizerTagger              = colorizerTagger;
                ColorizerTagger.TagsChanged += OnColorizingTaggerTagsChanged;
            }
        }
        public static BackgroundTagging StartBackgroundTagging(PXColorizerTaggerBase tagger)
        {
            tagger.ThrowOnNull(nameof(tagger));

            BackgroundTagging backgroundTagging = new BackgroundTagging();

            backgroundTagging.TaggingTask = tagger.GetTagsAsyncImplementation(tagger.Snapshot, backgroundTagging.CancellationToken);
            backgroundTagging.TaggingTask?.ConfigureAwait(false);
            backgroundTagging.TaggingTask.ContinueWith(task => tagger.RaiseTagsChanged(),
                                                       backgroundTagging.CancellationToken,
                                                       TaskContinuationOptions.OnlyOnRanToCompletion,
                                                       TaskScheduler.Default)
            .ConfigureAwait(false);

            return(backgroundTagging);
        }
        public static BackgroundTagging StartBackgroundTagging(PXColorizerTaggerBase tagger)
        {
            tagger.ThrowOnNull(nameof(tagger));

            BackgroundTagging backgroundTagging = new BackgroundTagging();
            var taggingTask = tagger.GetTagsAsyncImplementationAsync(tagger.Snapshot, backgroundTagging.CancellationToken);

            if (taggingTask == null)
            {
                return(backgroundTagging);
            }

            // Use VS task scheduler from the VS synchronization context to schedule task continuation immediately to main thread
            // No need for synchronziation because FromCurrentSynchronizationContext creates schedulers which wrap around the same synchronization context
            // Therefore all schedulers should be identical and nothing wrong will happen if multiple threads create will create a scheduler
            _vsTaskScheduler = _vsTaskScheduler ?? TaskScheduler.FromCurrentSynchronizationContext();
            backgroundTagging.TaggingTask = taggingTask.ContinueWith(task => AfterTaggingActionAsync(tagger, backgroundTagging.CancellationToken),  //continuation should be on the UI thread
                                                                     backgroundTagging.CancellationToken,
                                                                     TaskContinuationOptions.OnlyOnRanToCompletion,
                                                                     _vsTaskScheduler);
            return(backgroundTagging);
        }
Example #6
0
 private static bool TryGetColorizingTaggerFromBuffer(ITextBuffer textBuffer, out PXColorizerTaggerBase colorizingTagger)
 {
     return(textBuffer.Properties.TryGetProperty(typeof(PXColorizerTaggerBase), out colorizingTagger));
 }