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:
parent
b760102148
commit
ea9a74ee3c
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.Composition;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.CodeAnalysis.Razor;
|
using Microsoft.CodeAnalysis.Razor;
|
||||||
using Microsoft.VisualStudio.Text;
|
using Microsoft.VisualStudio.Text;
|
||||||
|
|
@ -10,12 +11,15 @@ using Microsoft.VisualStudio.Text.Editor;
|
||||||
|
|
||||||
namespace Microsoft.VisualStudio.Editor.Razor
|
namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
{
|
{
|
||||||
|
[System.Composition.Shared]
|
||||||
|
[Export(typeof(RazorDocumentManager))]
|
||||||
internal class DefaultRazorDocumentManager : RazorDocumentManager
|
internal class DefaultRazorDocumentManager : RazorDocumentManager
|
||||||
{
|
{
|
||||||
private readonly ForegroundDispatcher _foregroundDispatcher;
|
private readonly ForegroundDispatcher _foregroundDispatcher;
|
||||||
private readonly RazorEditorFactoryService _editorFactoryService;
|
private readonly RazorEditorFactoryService _editorFactoryService;
|
||||||
private readonly TextBufferProjectService _projectService;
|
private readonly TextBufferProjectService _projectService;
|
||||||
|
|
||||||
|
[ImportingConstructor]
|
||||||
public DefaultRazorDocumentManager(
|
public DefaultRazorDocumentManager(
|
||||||
ForegroundDispatcher dispatcher,
|
ForegroundDispatcher dispatcher,
|
||||||
RazorEditorFactoryService editorFactoryService,
|
RazorEditorFactoryService editorFactoryService,
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -20,23 +20,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
private readonly RazorDocumentManager _documentManager;
|
private readonly RazorDocumentManager _documentManager;
|
||||||
|
|
||||||
[ImportingConstructor]
|
[ImportingConstructor]
|
||||||
public RazorTextViewConnectionListener(ForegroundDispatcher foregroundDispatcher, VisualStudioWorkspaceAccessor workspaceAccessor)
|
public RazorTextViewConnectionListener(ForegroundDispatcher foregroundDispatcher, RazorDocumentManager documentManager)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (foregroundDispatcher == null)
|
if (foregroundDispatcher == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue