From b4deac09ce3270678d3294bdc0b7dd3292f79271 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Thu, 30 Nov 2017 09:55:20 -0800 Subject: [PATCH 1/3] Enable execution of well known batch fixer from non-VS host Well known batch fixer expects a MEF exported IDocumentTextDifferencingService, but we only have one in the EditorFeatures layer. We already have a simple default differencing service in the workspace, this change exports it at the default service layer. This change unblocks enabling FixAll testing in roslyn-analyzers repo: https://github.com/dotnet/roslyn-analyzers/issues/1420 --- .../DefaultDocumentTextDifferencingService.cs | 3 +++ .../CoreTest/WorkspaceTests/AdhocWorkspaceTests.cs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs index 1301d50193086..4c37b35d0e150 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/DefaultDocumentTextDifferencingService.cs @@ -1,12 +1,15 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Immutable; +using System.Composition; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis { + [ExportWorkspaceService(typeof(IDocumentTextDifferencingService), ServiceLayer.Default), Shared] internal class DefaultDocumentTextDifferencingService : IDocumentTextDifferencingService { public async Task> GetTextChangesAsync(Document oldDocument, Document newDocument, CancellationToken cancellationToken) diff --git a/src/Workspaces/CoreTest/WorkspaceTests/AdhocWorkspaceTests.cs b/src/Workspaces/CoreTest/WorkspaceTests/AdhocWorkspaceTests.cs index 5ac2d7a22277b..d821ec3166728 100644 --- a/src/Workspaces/CoreTest/WorkspaceTests/AdhocWorkspaceTests.cs +++ b/src/Workspaces/CoreTest/WorkspaceTests/AdhocWorkspaceTests.cs @@ -661,5 +661,16 @@ public void TestChangeDocumentInfo_TryApplyChanges() Assert.Equal(newPath, appliedDoc.FilePath); } } + + [Fact, Trait(Traits.Feature, Traits.Features.Workspace)] + public void TestDefaultDocumentTextDifferencingService() + { + using (var ws = new AdhocWorkspace()) + { + var service = ws.Services.GetService(); + Assert.NotNull(service); + Assert.Equal(service.GetType(), typeof(DefaultDocumentTextDifferencingService)); + } + } } } From c24e51ef84668dd7342f2fc63d5597aebf54276c Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Thu, 30 Nov 2017 12:02:35 -0800 Subject: [PATCH 2/3] Address PR feedback --- .../LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs index 2ca2493f08de7..077b155989cec 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs @@ -86,7 +86,7 @@ private async Task MergeLinkedDocumentGroupAsync( // Automatically merge non-conflicting diffs while collecting the conflicting diffs - var textDifferencingService = _oldSolution.Workspace.Services.GetService() ?? new DefaultDocumentTextDifferencingService(); + var textDifferencingService = _oldSolution.Workspace.Services.GetService(); var appliedChanges = await textDifferencingService.GetTextChangesAsync(_oldSolution.GetDocument(linkedDocumentGroup.First()), _newSolution.GetDocument(linkedDocumentGroup.First()), cancellationToken).ConfigureAwait(false); var unmergedChanges = new List(); From 6a850ec844611b1ab6d8a6e57b22a2f0d0e4cb06 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Thu, 30 Nov 2017 13:05:47 -0800 Subject: [PATCH 3/3] Revert "Address PR feedback" This reverts commit c24e51ef84668dd7342f2fc63d5597aebf54276c. --- .../LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs index 077b155989cec..2ca2493f08de7 100644 --- a/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs +++ b/src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs @@ -86,7 +86,7 @@ private async Task MergeLinkedDocumentGroupAsync( // Automatically merge non-conflicting diffs while collecting the conflicting diffs - var textDifferencingService = _oldSolution.Workspace.Services.GetService(); + var textDifferencingService = _oldSolution.Workspace.Services.GetService() ?? new DefaultDocumentTextDifferencingService(); var appliedChanges = await textDifferencingService.GetTextChangesAsync(_oldSolution.GetDocument(linkedDocumentGroup.First()), _newSolution.GetDocument(linkedDocumentGroup.First()), cancellationToken).ConfigureAwait(false); var unmergedChanges = new List();