Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;

using Acuminator.Utilities.Common;
using Acuminator.Vsix.Logger;

using Shell = Microsoft.VisualStudio.Shell;

Expand Down Expand Up @@ -80,8 +81,32 @@ public void Dispose()
return;

_isDisposed = true;
CancelTagging();
_cancellationTokenSource.Dispose();

Comment thread
SENya1990 marked this conversation as resolved.
try
{
_cancellationTokenSource.Cancel();
}
catch (OperationCanceledException)
{
}
catch (AggregateException aggregateException)
{
var flattened = aggregateException.Flatten();
var exceptionsToLog = flattened.InnerExceptions.Where(ex => ex is not OperationCanceledException);

foreach (var exception in exceptionsToLog)
{
AcuminatorVSPackage.Instance?.AcuminatorLogger?.LogException(exception, logOnlyFromAcuminatorAssemblies: false, LogMode.Warning);
}
}
catch (Exception ex)
{
AcuminatorVSPackage.Instance?.AcuminatorLogger?.LogException(ex, logOnlyFromAcuminatorAssemblies: false, LogMode.Warning);
}
finally
{
_cancellationTokenSource.Dispose();
}
}

private static Task AfterTaggingActionAsync(Task taggingTask, PXRoslynColorizerTagger tagger, CancellationToken cancellationToken)
Expand Down
16 changes: 13 additions & 3 deletions src/Acuminator/Acuminator.Vsix/Coloriser/Base/PXTaggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

namespace Acuminator.Vsix.Coloriser
{
public abstract class PXTaggerBase : IDisposable
public abstract class PXTaggerBase
{
private readonly TextDocumentDisposedNotification _disposedNotification;

#pragma warning disable CS0067
public event EventHandler<SnapshotSpanEventArgs>? TagsChanged;
#pragma warning restore CS0067
Expand All @@ -32,7 +34,8 @@ public abstract class PXTaggerBase : IDisposable

protected bool CacheCheckingEnabled { get; }

protected PXTaggerBase(ITextBuffer buffer, bool subscribeToSettingsChanges, bool useCacheChecking)
protected PXTaggerBase(ITextBuffer buffer, ITextDocumentFactoryService textDocumentFactory,
bool subscribeToSettingsChanges, bool useCacheChecking)
{
Buffer = buffer.CheckIfNull();
SubscribedToSettingsChanges = subscribeToSettingsChanges;
Expand All @@ -47,6 +50,9 @@ protected PXTaggerBase(ITextBuffer buffer, bool subscribeToSettingsChanges, bool
genOptionsPage.ColoringSettingChanged += ColoringSettingChangedHandler;
}
}

_disposedNotification = new TextDocumentDisposedNotification(textDocumentFactory, Buffer);
_disposedNotification.CurrentTextDocumentDisposed += CleanupOnTextDocumentDisposed;
}

protected virtual void ColoringSettingChangedHandler(object sender, SettingChangedEventArgs e)
Expand Down Expand Up @@ -94,8 +100,12 @@ protected internal virtual void ResetCacheAndFlags(ITextSnapshot? newSnapshotToC
Snapshot = newSnapshotToCache;
}

public virtual void Dispose()
protected virtual void CleanupOnTextDocumentDisposed(object sender, EventArgs e)
{
Type taggerType = GetType();
Buffer.Properties.RemoveProperty(taggerType);
_disposedNotification.CurrentTextDocumentDisposed -= CleanupOnTextDocumentDisposed;

if (!SubscribedToSettingsChanges)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ internal class PXOutliningTagger : PXTaggerBase, ITagger<IOutliningRegionTag>
[MemberNotNullWhen(returnValue: true, nameof(ColorizerTagger))]
public override bool HasReferenceToAcumaticaPlatform => ColorizerTagger?.HasReferenceToAcumaticaPlatform ?? false;

public PXOutliningTagger(ITextBuffer buffer, bool subscribeToSettingsChanges, bool useCacheChecking) :
base(buffer, subscribeToSettingsChanges, useCacheChecking)
public PXOutliningTagger(ITextBuffer buffer, ITextDocumentFactoryService textDocumentFactory, bool subscribeToSettingsChanges,
bool useCacheChecking) :
base(buffer, textDocumentFactory, subscribeToSettingsChanges, useCacheChecking)
{
}

Expand Down Expand Up @@ -69,15 +70,15 @@ private void OnColorizingTaggerTagsChanged(object sender, SnapshotSpanEventArgs
RaiseTagsChanged();
}

public override void Dispose()
protected override void CleanupOnTextDocumentDisposed(object sender, EventArgs e)
{
base.CleanupOnTextDocumentDisposed(sender, e);

if (Interlocked.Exchange(ref _isSubscribed, NOT_SUBSCRIBED) == SUBSCRIBED && ColorizerTagger != null)
{
ColorizerTagger.TagsChanged -= OnColorizingTaggerTagsChanged;
ColorizerTagger = null;
}

base.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;

Comment thread
SENya1990 marked this conversation as resolved.
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace Acuminator.Vsix.Coloriser
namespace Acuminator.Vsix.Coloriser;

[ContentType("CSharp")]
[TagType(typeof(IOutliningRegionTag))]
[TextViewRole(PredefinedTextViewRoles.Document)]
[Export(typeof(ITaggerProvider))]
public class PXOutliningTaggerProvider : ITaggerProvider
{
[ContentType("CSharp")]
[TagType(typeof(IOutliningRegionTag))]
[TextViewRole(PredefinedTextViewRoles.Document)]
[Export(typeof(ITaggerProvider))]
public class PXOutliningTaggerProvider : ITaggerProvider
private readonly ITextDocumentFactoryService _textDocumentFactory;

[ImportingConstructor]
public PXOutliningTaggerProvider(ITextDocumentFactoryService textDocumentFactory)
{
public ITagger<T>? CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
if (buffer == null || !ThreadHelper.CheckAccess())
return null;
_textDocumentFactory = textDocumentFactory;
}

public ITagger<T>? CreateTagger<T>(ITextBuffer buffer) where T : ITag
{
if (buffer == null || !ThreadHelper.CheckAccess())
return null;

PXOutliningTagger outliningTagger = buffer.Properties.GetOrCreateSingletonProperty(() =>
{
return new PXOutliningTagger(buffer, subscribeToSettingsChanges: true, useCacheChecking: true);
});
PXOutliningTagger outliningTagger = buffer.Properties.GetOrCreateSingletonProperty(typeof(PXOutliningTagger), () =>
{
return new PXOutliningTagger(buffer, _textDocumentFactory, subscribeToSettingsChanges: true, useCacheChecking: true);
});
Comment thread
SENya1990 marked this conversation as resolved.

return outliningTagger as ITagger<T>;
}
return outliningTagger as ITagger<T>;
}
}
Loading