From 6cf78ceb1bbdfd0a8d573925f09fd540f5f146c1 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 14 Nov 2017 16:17:19 -0800 Subject: [PATCH] Move TagHelperCompletionService to VS.Editor.Razor and export it. - Moved service poco types: `AttributeCompletionContext`, `AttributeCompletionResult`, `ElementCompletionContext` and `ElementCompletionResult`. - Exported DefaultTagHelperCompletionService. #1762 --- ...DefaultTagHelperCompletionServiceFactory.cs | 18 ------------------ .../AttributeCompletionContext.cs | 2 +- .../AttributeCompletionResult.cs | 2 +- .../DefaultTagHelperCompletionService.cs | 16 ++++++++++++++-- .../ElementCompletionContext.cs | 2 +- .../ElementCompletionResult.cs | 2 +- .../TagHelperCompletionService.cs | 6 ++---- .../DefaultTagHelperCompletionServiceTest.cs | 3 ++- 8 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionServiceFactory.cs rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/AttributeCompletionContext.cs (98%) rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/AttributeCompletionResult.cs (97%) rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/DefaultTagHelperCompletionService.cs (94%) rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/ElementCompletionContext.cs (97%) rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/ElementCompletionResult.cs (96%) rename src/{Microsoft.CodeAnalysis.Razor.Workspaces => Microsoft.VisualStudio.Editor.Razor}/TagHelperCompletionService.cs (74%) rename test/{Microsoft.CodeAnalysis.Razor.Workspaces.Test => Microsoft.VisualStudio.Editor.Razor.Test}/DefaultTagHelperCompletionServiceTest.cs (99%) diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionServiceFactory.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionServiceFactory.cs deleted file mode 100644 index aaa4f7dc2b..0000000000 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionServiceFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; - -namespace Microsoft.CodeAnalysis.Razor -{ - [ExportLanguageServiceFactory(typeof(TagHelperCompletionService), RazorLanguage.Name, ServiceLayer.Default)] - internal class DefaultTagHelperCompletionServiceFactory : ILanguageServiceFactory - { - public ILanguageService CreateLanguageService(HostLanguageServices languageServices) - { - var tagHelperFactsService = languageServices.GetRequiredService(); - return new DefaultTagHelperCompletionService(tagHelperFactsService); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionContext.cs b/src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionContext.cs similarity index 98% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionContext.cs rename to src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionContext.cs index bad51cc347..08b4ffe032 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionContext.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionContext.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.Language; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { public class AttributeCompletionContext { diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionResult.cs b/src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionResult.cs similarity index 97% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionResult.cs rename to src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionResult.cs index 1142b9ce6c..c6a11d67ed 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/AttributeCompletionResult.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/AttributeCompletionResult.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { public abstract class AttributeCompletionResult { diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionService.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultTagHelperCompletionService.cs similarity index 94% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionService.cs rename to src/Microsoft.VisualStudio.Editor.Razor/DefaultTagHelperCompletionService.cs index 65a99fa85b..0bb688e1b3 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultTagHelperCompletionService.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultTagHelperCompletionService.cs @@ -3,18 +3,30 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { + [System.Composition.Shared] + [Export(typeof(TagHelperCompletionService))] internal class DefaultTagHelperCompletionService : TagHelperCompletionService { private readonly TagHelperFactsServiceInternal _tagHelperFactsService; private static readonly HashSet _emptyHashSet = new HashSet(); - public DefaultTagHelperCompletionService(TagHelperFactsServiceInternal tagHelperFactsService) + [ImportingConstructor] + public DefaultTagHelperCompletionService(VisualStudioWorkspaceAccessor workspaceAccessor) + { + var razorLanguageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name); + _tagHelperFactsService = razorLanguageServices.GetRequiredService(); + } + + // Internal for testing + internal DefaultTagHelperCompletionService(TagHelperFactsServiceInternal tagHelperFactsService) { _tagHelperFactsService = tagHelperFactsService; } diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionContext.cs b/src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionContext.cs similarity index 97% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionContext.cs rename to src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionContext.cs index 614d5ac7f9..6d2c3965f5 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionContext.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionContext.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.Language; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { public sealed class ElementCompletionContext { diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionResult.cs b/src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionResult.cs similarity index 96% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionResult.cs rename to src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionResult.cs index 9bd1121380..3f5a9ad2d7 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ElementCompletionResult.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/ElementCompletionResult.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { public abstract class ElementCompletionResult { diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperCompletionService.cs b/src/Microsoft.VisualStudio.Editor.Razor/TagHelperCompletionService.cs similarity index 74% rename from src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperCompletionService.cs rename to src/Microsoft.VisualStudio.Editor.Razor/TagHelperCompletionService.cs index 0e75536f40..61eb751796 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperCompletionService.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/TagHelperCompletionService.cs @@ -1,11 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.CodeAnalysis.Host; - -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { - public abstract class TagHelperCompletionService : ILanguageService + public abstract class TagHelperCompletionService { public abstract AttributeCompletionResult GetAttributeCompletions(AttributeCompletionContext completionContext); diff --git a/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/DefaultTagHelperCompletionServiceTest.cs b/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultTagHelperCompletionServiceTest.cs similarity index 99% rename from test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/DefaultTagHelperCompletionServiceTest.cs rename to test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultTagHelperCompletionServiceTest.cs index c37f51a79e..1422e44815 100644 --- a/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/DefaultTagHelperCompletionServiceTest.cs +++ b/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultTagHelperCompletionServiceTest.cs @@ -4,9 +4,10 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor; using Xunit; -namespace Microsoft.CodeAnalysis.Razor +namespace Microsoft.VisualStudio.Editor.Razor { public class DefaultTagHelperCompletionServiceTest {