Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove tracked lines when file type changes to unsupported content ty… #458

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 22 additions & 21 deletions .github/workflows/push_pull.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ jobs:

# above are common steps for push and pull

# pull only
- name: upload vsix
if: github.event_name == 'pull_request' && !github.event.pull_request.draft
uses: actions/upload-artifact@v2
with:
name: FineCodeCoverage ( zipped vsix)
path: ${{env.VSIX}}
# pull only - todo update to v4
# - name: upload vsix
# if: github.event_name == 'pull_request' && !github.event.pull_request.draft
# uses: actions/upload-artifact@v2
# with:
# name: FineCodeCoverage ( zipped vsix)
# path: ${{env.VSIX}}

- name: upload vsix 2022
if: github.event_name == 'pull_request' && !github.event.pull_request.draft
uses: actions/upload-artifact@v2
with:
name: FineCodeCoverage2022 ( zipped vsix)
path: ${{env.VSIX2022}}
# - name: upload vsix 2022
# if: github.event_name == 'pull_request' && !github.event.pull_request.draft
# uses: actions/upload-artifact@v2
# with:
# name: FineCodeCoverage2022 ( zipped vsix)
# path: ${{env.VSIX2022}}

# push only
- name: create release
Expand Down Expand Up @@ -134,11 +134,12 @@ jobs:
manifestPath: ${{github.workspace}}\vs-market-place-manifest-2022.json
vsixPath: ${{env.VSIX2022}}

- name: comment - released and added to marketplace
if: github.event_name == 'push'
uses: tonyhallett/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
comment: released ${{steps.next-version.outputs.version_tag}} and available on marketplace
addTo: pullandissues
# todo - actions/upload-artifact@v4 now outputs the artifact-url
# - name: comment - released and added to marketplace
# if: github.event_name == 'push'
# uses: tonyhallett/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# comment: released ${{steps.next-version.outputs.version_tag}} and available on marketplace
# addTo: pullandissues
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMoq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.DynamicCoverage;
using FineCodeCoverage.Editor.DynamicCoverage.TrackedLinesImpl.Construction;
using FineCodeCoverage.Engine;
using FineCodeCoverage.Engine.Model;
using FineCodeCoverage.Impl;
Expand Down Expand Up @@ -290,6 +291,7 @@ public void Should_Have_Null_TrackedLines_If_No_Initial_Coverage()
null,
null,
new Mock<IAppOptionsProvider>().Object,
new CoverageContentTypes(new ICoverageContentType[] { }),
null
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.DynamicCoverage.TrackedLinesImpl.Construction;
using FineCodeCoverage.Engine;
using FineCodeCoverage.Engine.Model;
using FineCodeCoverage.Impl;
Expand All @@ -11,6 +12,11 @@

namespace FineCodeCoverage.Editor.DynamicCoverage
{
internal interface ICoverageContentTypes
{
bool IsApplicable(string contentTypeName);
}

internal class BufferLineCoverage :
IBufferLineCoverage, IListener<NewCoverageLinesMessage>, IListener<TestExecutionStartingMessage>
{
Expand All @@ -19,12 +25,14 @@ internal class BufferLineCoverage :
private readonly ITrackedLinesFactory trackedLinesFactory;
private readonly IDynamicCoverageStore dynamicCoverageStore;
private readonly IAppOptionsProvider appOptionsProvider;
private readonly ICoverageContentTypes coverageContentTypes;
private readonly ILogger logger;
private readonly ITextBuffer2 textBuffer;
private bool? editorCoverageModeOff;
private IFileLineCoverage fileLineCoverage;
private Nullable<DateTime> lastChanged;
private DateTime lastTestExecutionStarting;
private bool applicableContentType = true;

public ITrackedLines TrackedLines { get; set; }

Expand All @@ -40,6 +48,7 @@ public BufferLineCoverage(
ITrackedLinesFactory trackedLinesFactory,
IDynamicCoverageStore dynamicCoverageStore,
IAppOptionsProvider appOptionsProvider,
ICoverageContentTypes coverageContentTypes,
ILogger logger
)
{
Expand All @@ -50,11 +59,13 @@ ILogger logger
}

this.textBuffer = textInfo.TextBuffer;
this.textBuffer.ContentTypeChanged += this.ContentTypeChanged;
this.textInfo = textInfo;
this.eventAggregator = eventAggregator;
this.trackedLinesFactory = trackedLinesFactory;
this.dynamicCoverageStore = dynamicCoverageStore;
this.appOptionsProvider = appOptionsProvider;
this.coverageContentTypes = coverageContentTypes;
this.logger = logger;
void AppOptionsChanged(IAppOptions appOptions)
{
Expand All @@ -79,6 +90,7 @@ void textViewClosedHandler(object s, EventArgs e)
{
this.UpdateDynamicCoverageStore((s as ITextView).TextSnapshot);
this.textBuffer.Changed -= this.TextBuffer_ChangedOnBackground;
this.textBuffer.ContentTypeChanged -= this.ContentTypeChanged;
textInfo.TextView.Closed -= textViewClosedHandler;
appOptionsProvider.OptionsChanged -= AppOptionsChanged;
_ = eventAggregator.RemoveListener(this);
Expand All @@ -87,6 +99,25 @@ void textViewClosedHandler(object s, EventArgs e)
textInfo.TextView.Closed += textViewClosedHandler;
}

private void ContentTypeChanged(object sender, ContentTypeChangedEventArgs args)
{
// purpose is so do not create tracked lines for a content type that is not applicable when new coverage
this.applicableContentType = this.coverageContentTypes.IsApplicable(args.AfterContentType.TypeName);
if (this.applicableContentType)
{
// this currently does not work as Roslyn is not ready.
// could fallback to single lines but would have to look at other uses of IFileCodeSpanRangeService
// this is low priority
this.CreateTrackedLinesIfRequired(true);
}
else
{
this.TrackedLines = null;
}

this.SendCoverageChangedMessage();
}

private void UpdateDynamicCoverageStore(ITextSnapshot textSnapshot)
{
if (this.TrackedLines != null)
Expand Down Expand Up @@ -116,23 +147,23 @@ private void UpdateDynamicCoverageStore(ITextSnapshot textSnapshot)
private bool FileSystemReflectsTrackedLines(string snapshotText)
=> this.textInfo.GetFileText() == snapshotText;

private void CreateTrackedLinesIfRequired(bool initial)
private void CreateTrackedLinesIfRequired(bool fromStore)
{
if (this.EditorCoverageColouringModeOff())
{
this.TrackedLines = null;
}
else
{
this.TryCreateTrackedLines(initial);
this.TryCreateTrackedLines(fromStore);
}
}

private void TryCreateTrackedLines(bool initial)
private void TryCreateTrackedLines(bool fromStore)
{
try
{
this.CreateTrackedLines(initial);
this.CreateTrackedLines(fromStore);
}
catch (Exception e)
{
Expand Down Expand Up @@ -182,11 +213,11 @@ as When is written when the text view is closed it is always - LastWriteTime < W
: (SerializedCoverageState.Ok, serializedCoverageWhen.Serialized);
}

private void CreateTrackedLines(bool initial)
private void CreateTrackedLines(bool fromStore)
{
string filePath = this.textInfo.FilePath;
ITextSnapshot currentSnapshot = this.textBuffer.CurrentSnapshot;
if (initial)
if (fromStore)
{
SerializedCoverageWhen serializedCoverageWhen = this.dynamicCoverageStore.GetSerializedCoverage(
filePath
Expand Down Expand Up @@ -266,6 +297,8 @@ public IEnumerable<IDynamicLine> GetLines(int startLineNumber, int endLineNumber

public void Handle(NewCoverageLinesMessage message)
{
if (!this.applicableContentType) return;

this.fileLineCoverage = message.CoverageLines;

bool hadTrackedLines = this.TrackedLines != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.DynamicCoverage.TrackedLinesImpl.Construction;
using FineCodeCoverage.Engine.Model;
using FineCodeCoverage.Impl;
using FineCodeCoverage.Options;

namespace FineCodeCoverage.Editor.DynamicCoverage
{
internal class CoverageContentTypes : ICoverageContentTypes
{
private readonly ICoverageContentType[] coverageContentTypes;

public CoverageContentTypes(ICoverageContentType[] coverageContentTypes)
=> this.coverageContentTypes = coverageContentTypes;
public bool IsApplicable(string contentTypeName)
=> this.coverageContentTypes.Any(contentType => contentType.ContentTypeName == contentTypeName);
}

[ExcludeFromCodeCoverage]
[Export(typeof(IBufferLineCoverageFactory))]
internal class BufferLineCoverageFactory : IBufferLineCoverageFactory
{
private readonly ICoverageContentTypes coverageContentTypes;
private readonly IDynamicCoverageStore dynamicCoverageStore;
private readonly IAppOptionsProvider appOptionsProvider;
private readonly ILogger logger;

[ImportingConstructor]
public BufferLineCoverageFactory(
[ImportMany]
ICoverageContentType[] coverageContentTypes,
IDynamicCoverageStore dynamicCoverageStore,
IAppOptionsProvider appOptionsProvider,
ILogger logger
)
{
this.appOptionsProvider = appOptionsProvider;
this.logger = logger;
this.coverageContentTypes = new CoverageContentTypes(coverageContentTypes);
this.dynamicCoverageStore = dynamicCoverageStore;
}

Expand All @@ -39,7 +55,9 @@ ITrackedLinesFactory trackedLinesFactory
trackedLinesFactory,
this.dynamicCoverageStore,
this.appOptionsProvider,
this.coverageContentTypes,
this.logger

);
}
}
Loading