Make DefaultVisualStudioDocumentTrackerFactory VS agnostic.
- Moved `DefaultVisualStudioDocumentTrackerFactory` from language services Razor to editor Razor. #1789
This commit is contained in:
parent
37eed518f8
commit
65cdddf5d9
|
|
@ -2,19 +2,15 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
using Microsoft.CodeAnalysis.Razor.Editor;
|
||||
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
|
||||
using Microsoft.VisualStudio.Editor.Razor;
|
||||
using Microsoft.VisualStudio.Text;
|
||||
|
||||
namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
|
||||
namespace Microsoft.VisualStudio.Editor.Razor
|
||||
{
|
||||
[System.Composition.Shared]
|
||||
[Export(typeof(VisualStudioDocumentTrackerFactory))]
|
||||
internal class DefaultVisualStudioDocumentTrackerFactory : VisualStudioDocumentTrackerFactory
|
||||
{
|
||||
private readonly TextBufferProjectService _projectService;
|
||||
|
|
@ -25,13 +21,30 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
|
|||
private readonly ProjectSnapshotManager _projectManager;
|
||||
private readonly EditorSettingsManagerInternal _editorSettingsManager;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DefaultVisualStudioDocumentTrackerFactory(
|
||||
ForegroundDispatcher foregroundDispatcher,
|
||||
ProjectSnapshotManager projectManager,
|
||||
EditorSettingsManagerInternal editorSettingsManager,
|
||||
TextBufferProjectService projectService,
|
||||
ITextDocumentFactoryService textDocumentFactory,
|
||||
VisualStudioWorkspaceAccessor workspaceAccessor,
|
||||
ImportDocumentManager importDocumentManager)
|
||||
ImportDocumentManager importDocumentManager,
|
||||
Workspace workspace)
|
||||
{
|
||||
if (foregroundDispatcher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(foregroundDispatcher));
|
||||
}
|
||||
|
||||
if (projectManager == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectManager));
|
||||
}
|
||||
|
||||
if (editorSettingsManager == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(editorSettingsManager));
|
||||
}
|
||||
|
||||
if (projectService == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectService));
|
||||
|
|
@ -42,20 +55,23 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
|
|||
throw new ArgumentNullException(nameof(textDocumentFactory));
|
||||
}
|
||||
|
||||
if (workspaceAccessor == null)
|
||||
if (importDocumentManager == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workspaceAccessor));
|
||||
throw new ArgumentNullException(nameof(importDocumentManager));
|
||||
}
|
||||
|
||||
if (workspace == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workspace));
|
||||
}
|
||||
|
||||
_foregroundDispatcher = foregroundDispatcher;
|
||||
_projectManager = projectManager;
|
||||
_editorSettingsManager = editorSettingsManager;
|
||||
_projectService = projectService;
|
||||
_textDocumentFactory = textDocumentFactory;
|
||||
_workspace = workspaceAccessor.Workspace;
|
||||
_importDocumentManager = importDocumentManager;
|
||||
|
||||
_foregroundDispatcher = _workspace.Services.GetRequiredService<ForegroundDispatcher>();
|
||||
var razorLanguageServices = _workspace.Services.GetLanguageServices(RazorLanguage.Name);
|
||||
_projectManager = razorLanguageServices.GetRequiredService<ProjectSnapshotManager>();
|
||||
_editorSettingsManager = razorLanguageServices.GetRequiredService<EditorSettingsManagerInternal>();
|
||||
_workspace = workspace;
|
||||
}
|
||||
|
||||
public override VisualStudioDocumentTracker Create(ITextBuffer textBuffer)
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// 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;
|
||||
using Microsoft.CodeAnalysis.Razor.Editor;
|
||||
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
|
||||
using Microsoft.VisualStudio.Text;
|
||||
|
||||
namespace Microsoft.VisualStudio.Editor.Razor
|
||||
{
|
||||
[Shared]
|
||||
[ExportLanguageServiceFactory(typeof(VisualStudioDocumentTrackerFactory), RazorLanguage.Name, ServiceLayer.Default)]
|
||||
internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory
|
||||
{
|
||||
private readonly TextBufferProjectService _projectService;
|
||||
private readonly ITextDocumentFactoryService _textDocumentFactory;
|
||||
private readonly ImportDocumentManager _importDocumentManager;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DefaultVisualStudioDocumentTrackerFactoryFactory(
|
||||
TextBufferProjectService projectService,
|
||||
ITextDocumentFactoryService textDocumentFactory,
|
||||
ImportDocumentManager importDocumentManager)
|
||||
{
|
||||
if (projectService == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(projectService));
|
||||
}
|
||||
|
||||
if (textDocumentFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(textDocumentFactory));
|
||||
}
|
||||
|
||||
if (importDocumentManager == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(importDocumentManager));
|
||||
}
|
||||
|
||||
_projectService = projectService;
|
||||
_textDocumentFactory = textDocumentFactory;
|
||||
_importDocumentManager = importDocumentManager;
|
||||
}
|
||||
|
||||
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
|
||||
{
|
||||
if (languageServices == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(languageServices));
|
||||
}
|
||||
|
||||
var dispatcher = languageServices.WorkspaceServices.GetRequiredService<ForegroundDispatcher>();
|
||||
var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>();
|
||||
var editorSettingsManager = languageServices.GetRequiredService<EditorSettingsManagerInternal>();
|
||||
|
||||
return new DefaultVisualStudioDocumentTrackerFactory(
|
||||
dispatcher,
|
||||
projectManager,
|
||||
editorSettingsManager,
|
||||
_projectService,
|
||||
_textDocumentFactory,
|
||||
_importDocumentManager,
|
||||
languageServices.WorkspaceServices.Workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
// 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.VisualStudio.Text;
|
||||
|
||||
namespace Microsoft.VisualStudio.Editor.Razor
|
||||
{
|
||||
internal abstract class VisualStudioDocumentTrackerFactory
|
||||
internal abstract class VisualStudioDocumentTrackerFactory : ILanguageService
|
||||
{
|
||||
public abstract VisualStudioDocumentTracker Create(ITextBuffer textBuffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,23 +21,15 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
|
|||
private readonly BraceSmartIndenterFactory _braceSmartIndenterFactory;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DefaultRazorEditorFactoryService(
|
||||
VisualStudioDocumentTrackerFactory documentTrackerFactory,
|
||||
VisualStudioWorkspaceAccessor workspaceAccessor)
|
||||
public DefaultRazorEditorFactoryService(VisualStudioWorkspaceAccessor workspaceAccessor)
|
||||
{
|
||||
if (documentTrackerFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(documentTrackerFactory));
|
||||
}
|
||||
|
||||
if (workspaceAccessor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workspaceAccessor));
|
||||
}
|
||||
|
||||
_documentTrackerFactory = documentTrackerFactory;
|
||||
|
||||
var razorLanguageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name);
|
||||
_documentTrackerFactory = razorLanguageServices.GetRequiredService<VisualStudioDocumentTrackerFactory>();
|
||||
_parserFactory = razorLanguageServices.GetRequiredService<VisualStudioRazorParserFactory>();
|
||||
_braceSmartIndenterFactory = razorLanguageServices.GetRequiredService<BraceSmartIndenterFactory>();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue