diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTrackerFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactory.cs similarity index 70% rename from src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTrackerFactory.cs rename to src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactory.cs index 9bd9570a9a..e4b6dd4f24 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTrackerFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactory.cs @@ -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(); - var razorLanguageServices = _workspace.Services.GetLanguageServices(RazorLanguage.Name); - _projectManager = razorLanguageServices.GetRequiredService(); - _editorSettingsManager = razorLanguageServices.GetRequiredService(); + _workspace = workspace; } public override VisualStudioDocumentTracker Create(ITextBuffer textBuffer) diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs new file mode 100644 index 0000000000..0a97cf211a --- /dev/null +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs @@ -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(); + var projectManager = languageServices.GetRequiredService(); + var editorSettingsManager = languageServices.GetRequiredService(); + + return new DefaultVisualStudioDocumentTrackerFactory( + dispatcher, + projectManager, + editorSettingsManager, + _projectService, + _textDocumentFactory, + _importDocumentManager, + languageServices.WorkspaceServices.Workspace); + } + } +} diff --git a/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTrackerFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTrackerFactory.cs index 1576ac9074..c17565dd72 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTrackerFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTrackerFactory.cs @@ -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); } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultRazorEditorFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultRazorEditorFactoryService.cs index dfb2b51d93..71cc07f20d 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultRazorEditorFactoryService.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultRazorEditorFactoryService.cs @@ -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(); _parserFactory = razorLanguageServices.GetRequiredService(); _braceSmartIndenterFactory = razorLanguageServices.GetRequiredService(); }