Наша сборка Qt VS Tools
giy
2022-09-02 ca47896204482bf4a6979e3838bf7f09f61cebeb
QtVsTools.Package/QML/Classification/QmlAsyncClassifier.cs
@@ -33,7 +33,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using Microsoft.VisualStudio.Text;
@@ -52,7 +51,7 @@
    /// </summary>
    class SharedTagList : Concurrent
    {
        SortedList<int, TrackingTag> data = new SortedList<int, TrackingTag>();
        readonly SortedList<int, TrackingTag> data = new SortedList<int, TrackingTag>();
        object owner;
        public bool Ready { get; private set; }
@@ -97,7 +96,7 @@
        class TrackingTagComparer : Comparer<TrackingTag>
        {
            ITextSnapshot snapshot;
            readonly ITextSnapshot snapshot;
            public TrackingTagComparer(ITextSnapshot snapshot)
            {
                this.snapshot = snapshot;
@@ -232,17 +231,16 @@
        /// <returns>Instance of T corresponding to the given TrackingTag</returns>
        protected abstract T GetClassification(TrackingTag tag);
        protected ITextView TextView { get; private set; }
        protected ITextBuffer Buffer { get; private set; }
        private ITextView TextView { get; }
        private ITextBuffer Buffer { get; }
        readonly object criticalSection = new object();
        string classificationType;
        readonly string classificationType;
        ParserKey currentParserKey;
        TagListKey currentTagListKey;
        SharedTagList currentTagList;
        Dispatcher dispatcher;
        DispatcherTimer timer;
        readonly Dispatcher dispatcher;
        readonly DispatcherTimer timer;
        bool flag = false;
        protected QmlAsyncClassifier(
@@ -267,7 +265,7 @@
            currentTagList = null;
            this.classificationType = classificationType;
            AsyncParse(buffer.CurrentSnapshot);
            Parse(buffer.CurrentSnapshot);
        }
        private void TextView_Closed(object sender, EventArgs e)
@@ -286,16 +284,16 @@
        private void Buffer_Changed(object sender, TextContentChangedEventArgs e)
        {
            timer.Stop();
            AsyncParse(e.After);
            Parse(e.After);
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            AsyncParse(Buffer.CurrentSnapshot);
            Parse(Buffer.CurrentSnapshot);
        }
        private async void AsyncParse(ITextSnapshot snapshot)
        private void Parse(ITextSnapshot snapshot)
        {
            lock (criticalSection) {
                if (flag)
@@ -311,7 +309,7 @@
            ParserKey oldParserKey = null;
            TagListKey oldTagListKey = null;
            await Task.Run(() =>
            _ = Task.Run(() =>
            {
                var parser = ParserStore.Instance.Get(this, newParserKey);
@@ -344,7 +342,7 @@
                flag = false;
            }
            await Task.Run(() =>
            _ = Task.Run(() =>
            {
                if (oldParserKey != null)
                    ParserStore.Instance.Release(this, oldParserKey);
@@ -511,7 +509,7 @@
                public TValue Value { get; set; }
                public HashSet<object> ClientObjects { get; set; }
            }
            Dictionary<TKey, ValueRef> data = new Dictionary<TKey, ValueRef>();
            readonly Dictionary<TKey, ValueRef> data = new Dictionary<TKey, ValueRef>();
            static readonly object staticCriticalSection = new object();
            readonly object criticalSection = new object();
@@ -524,8 +522,7 @@
            public TValue Get(object client, TKey key)
            {
                lock (criticalSection) {
                    ValueRef valueRef;
                    if (!data.TryGetValue(key, out valueRef)) {
                    if (!data.TryGetValue(key, out ValueRef valueRef)) {
                        valueRef = new ValueRef
                        {
                            Value = GetDefaultValue(key),
@@ -543,8 +540,7 @@
            {
                IDisposable disposable = null;
                lock (criticalSection) {
                    ValueRef valueRef;
                    if (data.TryGetValue(key, out valueRef)) {
                    if (data.TryGetValue(key, out ValueRef valueRef)) {
                        valueRef.ClientObjects.Remove(client);
                        if (valueRef.ClientObjects.Count == 0) {
                            data.Remove(key);
@@ -573,8 +569,8 @@
        class TagListKey
        {
            public string Classification { get; private set; }
            public ITextSnapshot Snapshot { get; private set; }
            private string Classification { get; }
            private ITextSnapshot Snapshot { get; }
            public TagListKey(string classification, ITextSnapshot snapshot)
            {
                Classification = classification;
@@ -614,7 +610,7 @@
        class ParserKey
        {
            public ITextSnapshot Snapshot { get; private set; }
            public ITextSnapshot Snapshot { get; }
            public ParserKey(ITextSnapshot snapshot)
            {
                Snapshot = snapshot;