From ea9a74ee3ce48c97e92457242b43d827fe190a65 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 2 Feb 2018 13:11:01 -0800 Subject: [PATCH] Change RazorTextViewConnectionListener to not depend on a primary workspace. - Updated the `DefaultRazorDocumentManager` to also not be a workspace service. It didn't end up having any workspace specific logic so it made sense to have the lifetime of the IDE. #2010 --- .../DefaultRazorDocumentManager.cs | 4 ++ .../DefaultRazorDocumentManagerFactory.cs | 56 ------------------- .../RazorTextViewConnectionListener.cs | 18 +----- 3 files changed, 5 insertions(+), 73 deletions(-) delete mode 100644 src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs index 13f1c15e6d..6be7e06fa9 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Composition; using System.Diagnostics; using Microsoft.CodeAnalysis.Razor; using Microsoft.VisualStudio.Text; @@ -10,12 +11,15 @@ using Microsoft.VisualStudio.Text.Editor; namespace Microsoft.VisualStudio.Editor.Razor { + [System.Composition.Shared] + [Export(typeof(RazorDocumentManager))] internal class DefaultRazorDocumentManager : RazorDocumentManager { private readonly ForegroundDispatcher _foregroundDispatcher; private readonly RazorEditorFactoryService _editorFactoryService; private readonly TextBufferProjectService _projectService; + [ImportingConstructor] public DefaultRazorDocumentManager( ForegroundDispatcher dispatcher, RazorEditorFactoryService editorFactoryService, diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs deleted file mode 100644 index 7da3850d07..0000000000 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs +++ /dev/null @@ -1,56 +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 System; -using System.Composition; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Razor; - -namespace Microsoft.VisualStudio.Editor.Razor -{ - [Shared] - [ExportLanguageServiceFactory(typeof(RazorDocumentManager), RazorLanguage.Name, ServiceLayer.Default)] - internal class DefaultRazorDocumentManagerFactory : ILanguageServiceFactory - { - private readonly ForegroundDispatcher _foregroundDispatcher; - private readonly RazorEditorFactoryService _editorFactoryService; - private readonly TextBufferProjectService _projectService; - - [ImportingConstructor] - public DefaultRazorDocumentManagerFactory( - ForegroundDispatcher foregroundDispatcher, - RazorEditorFactoryService editorFactoryService, - TextBufferProjectService projectService) - { - if (foregroundDispatcher == null) - { - throw new ArgumentNullException(nameof(foregroundDispatcher)); - } - - if (editorFactoryService == null) - { - throw new ArgumentNullException(nameof(editorFactoryService)); - } - - if (projectService == null) - { - throw new ArgumentNullException(nameof(projectService)); - } - - _foregroundDispatcher = foregroundDispatcher; - _editorFactoryService = editorFactoryService; - _projectService = projectService; - } - - public ILanguageService CreateLanguageService(HostLanguageServices languageServices) - { - if (languageServices == null) - { - throw new ArgumentNullException(nameof(languageServices)); - } - - return new DefaultRazorDocumentManager(_foregroundDispatcher, _editorFactoryService, _projectService); - } - } -} diff --git a/src/Microsoft.VisualStudio.Editor.Razor/RazorTextViewConnectionListener.cs b/src/Microsoft.VisualStudio.Editor.Razor/RazorTextViewConnectionListener.cs index 040bbb5adc..53a4464b45 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/RazorTextViewConnectionListener.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/RazorTextViewConnectionListener.cs @@ -20,23 +20,7 @@ namespace Microsoft.VisualStudio.Editor.Razor private readonly RazorDocumentManager _documentManager; [ImportingConstructor] - public RazorTextViewConnectionListener(ForegroundDispatcher foregroundDispatcher, VisualStudioWorkspaceAccessor workspaceAccessor) - { - if (workspaceAccessor == null) - { - throw new ArgumentNullException(nameof(workspaceAccessor)); - } - - _foregroundDispatcher = foregroundDispatcher; - - var languageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name); - _documentManager = languageServices.GetRequiredService(); - } - - // This is only for testing. We want to avoid using the actual Roslyn GetService methods in unit tests. - internal RazorTextViewConnectionListener( - ForegroundDispatcher foregroundDispatcher, - RazorDocumentManager documentManager) + public RazorTextViewConnectionListener(ForegroundDispatcher foregroundDispatcher, RazorDocumentManager documentManager) { if (foregroundDispatcher == null) {