示例#1
0
 private void TextView_Closed(object sender, EventArgs e)
 {
     if (currentParserKey != null)
     {
         ParserStore.Instance.Release(this, currentParserKey);
         currentParserKey = null;
     }
     if (currentTagListKey != null)
     {
         TagListStore.Instance.Release(this, currentTagListKey);
         currentTagListKey = null;
     }
     currentTagList = null;
 }
示例#2
0
        protected QmlAsyncClassifier(
            string classificationType,
            ITextView textView,
            ITextBuffer buffer)
        {
            TextView         = textView;
            textView.Closed += TextView_Closed;
            Buffer           = buffer;
            buffer.Changed  += Buffer_Changed;

            dispatcher = Dispatcher.CurrentDispatcher;
            timer      = new DispatcherTimer(DispatcherPriority.ApplicationIdle, dispatcher)
            {
                Interval = TimeSpan.FromMilliseconds(250)
            };
            timer.Tick += Timer_Tick;

            currentParserKey        = null;
            currentTagListKey       = null;
            currentTagList          = null;
            this.classificationType = classificationType;

            AsyncParse(buffer.CurrentSnapshot);
        }
示例#3
0
        private async void AsyncParse(ITextSnapshot snapshot)
        {
            lock (criticalSection) {
                if (flag)
                {
                    return;
                }
                flag = true;
            }

            var newParserKey  = new ParserKey(snapshot);
            var newTagListKey = new TagListKey(classificationType, snapshot);

            if (newParserKey == currentParserKey || newTagListKey == currentTagListKey)
            {
                return;
            }

            ParserKey  oldParserKey  = null;
            TagListKey oldTagListKey = null;

            await Task.Run(() =>
            {
                var parser = ParserStore.Instance.Get(this, newParserKey);

                var tagList = TagListStore.Instance.Get(this, newTagListKey);
                var refresh = ClassificationRefresh.FullText;
                try {
                    var accessType = tagList.RequestWriteAccess(this);
                    refresh        = ProcessText(snapshot, parser, tagList,
                                                 accessType == SharedTagList.AccessType.ReadWrite);
                } finally {
                    tagList.WriteComplete(this);
                }

                oldParserKey      = currentParserKey;
                currentParserKey  = newParserKey;
                oldTagListKey     = currentTagListKey;
                currentTagListKey = newTagListKey;
                currentTagList    = tagList;

                RefreshClassification(snapshot, refresh, tagList);

                var currentVersion = Buffer.CurrentSnapshot.Version;
                if (snapshot.Version.VersionNumber == currentVersion.VersionNumber)
                {
                    timer.Stop();
                }
                else
                {
                    timer.Start();
                }
            });

            lock (criticalSection) {
                flag = false;
            }

            await Task.Run(() =>
            {
                if (oldParserKey != null)
                {
                    ParserStore.Instance.Release(this, oldParserKey);
                }
                if (oldTagListKey != null)
                {
                    TagListStore.Instance.Release(this, oldTagListKey);
                }
            });
        }