| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Threading;
|
| | | using System.Threading.Tasks;
|
| | | using System.Windows.Threading;
|
| | | using Microsoft.VisualStudio.Text;
|
| | |
| | | /// </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; }
|
| | |
| | |
|
| | | class TrackingTagComparer : Comparer<TrackingTag>
|
| | | {
|
| | | ITextSnapshot snapshot;
|
| | | readonly ITextSnapshot snapshot;
|
| | | public TrackingTagComparer(ITextSnapshot snapshot)
|
| | | {
|
| | | this.snapshot = snapshot;
|
| | |
| | | /// <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(
|
| | |
| | | currentTagList = null;
|
| | | this.classificationType = classificationType;
|
| | |
|
| | | AsyncParse(buffer.CurrentSnapshot);
|
| | | Parse(buffer.CurrentSnapshot);
|
| | | }
|
| | |
|
| | | private void TextView_Closed(object sender, EventArgs e)
|
| | |
| | | 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)
|
| | |
| | | ParserKey oldParserKey = null;
|
| | | TagListKey oldTagListKey = null;
|
| | |
|
| | | await Task.Run(() =>
|
| | | _ = Task.Run(() =>
|
| | | {
|
| | | var parser = ParserStore.Instance.Get(this, newParserKey);
|
| | |
|
| | |
| | | flag = false;
|
| | | }
|
| | |
|
| | | await Task.Run(() =>
|
| | | _ = Task.Run(() =>
|
| | | {
|
| | | if (oldParserKey != null)
|
| | | ParserStore.Instance.Release(this, oldParserKey);
|
| | |
| | | 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();
|
| | |
| | | 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),
|
| | |
| | | {
|
| | | 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);
|
| | |
| | |
|
| | | 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;
|
| | |
| | |
|
| | | class ParserKey
|
| | | {
|
| | | public ITextSnapshot Snapshot { get; private set; }
|
| | | public ITextSnapshot Snapshot { get; }
|
| | | public ParserKey(ITextSnapshot snapshot)
|
| | | {
|
| | | Snapshot = snapshot;
|