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
This commit is contained in:
N. Taylor Mullen 2018-02-02 13:11:01 -08:00
parent b760102148
commit ea9a74ee3c
3 changed files with 5 additions and 73 deletions

View File

@ -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,

View File

@ -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);
}
}
}

View File

@ -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<RazorDocumentManager>();
}
// 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)
{