diff --git a/.github/workflows/push_pull.yaml b/.github/workflows/push_pull.yaml index 32df82bb..df3558fe 100644 --- a/.github/workflows/push_pull.yaml +++ b/.github/workflows/push_pull.yaml @@ -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 @@ -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/addCommentToPullAndIssuesFromPushAction@v1.0.0 - 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/addCommentToPullAndIssuesFromPushAction@v1.0.0 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # comment: released ${{steps.next-version.outputs.version_tag}} and available on marketplace + # addTo: pullandissues diff --git a/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs b/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs index 51498c58..9908aee9 100644 --- a/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs +++ b/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs @@ -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; @@ -290,6 +291,7 @@ public void Should_Have_Null_TrackedLines_If_No_Initial_Coverage() null, null, new Mock().Object, + new CoverageContentTypes(new ICoverageContentType[] { }), null ); diff --git a/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverage.cs b/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverage.cs index 09f41c56..d234cc84 100644 --- a/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverage.cs +++ b/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverage.cs @@ -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; @@ -11,6 +12,11 @@ namespace FineCodeCoverage.Editor.DynamicCoverage { + internal interface ICoverageContentTypes + { + bool IsApplicable(string contentTypeName); + } + internal class BufferLineCoverage : IBufferLineCoverage, IListener, IListener { @@ -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 lastChanged; private DateTime lastTestExecutionStarting; + private bool applicableContentType = true; public ITrackedLines TrackedLines { get; set; } @@ -40,6 +48,7 @@ public BufferLineCoverage( ITrackedLinesFactory trackedLinesFactory, IDynamicCoverageStore dynamicCoverageStore, IAppOptionsProvider appOptionsProvider, + ICoverageContentTypes coverageContentTypes, ILogger logger ) { @@ -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) { @@ -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); @@ -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) @@ -116,7 +147,7 @@ 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()) { @@ -124,15 +155,15 @@ private void CreateTrackedLinesIfRequired(bool initial) } 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) { @@ -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 @@ -266,6 +297,8 @@ public IEnumerable GetLines(int startLineNumber, int endLineNumber public void Handle(NewCoverageLinesMessage message) { + if (!this.applicableContentType) return; + this.fileLineCoverage = message.CoverageLines; bool hadTrackedLines = this.TrackedLines != null; diff --git a/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverageFactory.cs b/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverageFactory.cs index 1876ca2a..854c8aba 100644 --- a/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverageFactory.cs +++ b/SharedProject/Editor/DynamicCoverage/Management/BufferLineCoverageFactory.cs @@ -1,22 +1,37 @@ 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 @@ -24,6 +39,7 @@ ILogger logger { this.appOptionsProvider = appOptionsProvider; this.logger = logger; + this.coverageContentTypes = new CoverageContentTypes(coverageContentTypes); this.dynamicCoverageStore = dynamicCoverageStore; } @@ -39,7 +55,9 @@ ITrackedLinesFactory trackedLinesFactory trackedLinesFactory, this.dynamicCoverageStore, this.appOptionsProvider, + this.coverageContentTypes, this.logger + ); } }