diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs index 593bd8fb35..7da3850d07 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs @@ -15,9 +15,13 @@ namespace Microsoft.VisualStudio.Editor.Razor { private readonly ForegroundDispatcher _foregroundDispatcher; private readonly RazorEditorFactoryService _editorFactoryService; + private readonly TextBufferProjectService _projectService; [ImportingConstructor] - public DefaultRazorDocumentManagerFactory(ForegroundDispatcher foregroundDispatcher, RazorEditorFactoryService editorFactoryService) + public DefaultRazorDocumentManagerFactory( + ForegroundDispatcher foregroundDispatcher, + RazorEditorFactoryService editorFactoryService, + TextBufferProjectService projectService) { if (foregroundDispatcher == null) { @@ -29,8 +33,14 @@ namespace Microsoft.VisualStudio.Editor.Razor throw new ArgumentNullException(nameof(editorFactoryService)); } + if (projectService == null) + { + throw new ArgumentNullException(nameof(projectService)); + } + _foregroundDispatcher = foregroundDispatcher; _editorFactoryService = editorFactoryService; + _projectService = projectService; } public ILanguageService CreateLanguageService(HostLanguageServices languageServices) @@ -40,9 +50,7 @@ namespace Microsoft.VisualStudio.Editor.Razor throw new ArgumentNullException(nameof(languageServices)); } - var projectService = languageServices.GetRequiredService(); - - return new DefaultRazorDocumentManager(_foregroundDispatcher, _editorFactoryService, projectService); + return new DefaultRazorDocumentManager(_foregroundDispatcher, _editorFactoryService, _projectService); } } } diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs index f8ebf6503d..a2af5b8d17 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs @@ -17,22 +17,32 @@ namespace Microsoft.VisualStudio.Editor.Razor internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory { private readonly ForegroundDispatcher _foregroundDispatcher; + private readonly TextBufferProjectService _projectService; private readonly ITextDocumentFactoryService _textDocumentFactory; [ImportingConstructor] - public DefaultVisualStudioDocumentTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher, ITextDocumentFactoryService textDocumentFactory) + public DefaultVisualStudioDocumentTrackerFactoryFactory( + ForegroundDispatcher foregroundDispatcher, + TextBufferProjectService projectService, + ITextDocumentFactoryService textDocumentFactory) { if (foregroundDispatcher == null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } + if (projectService == null) + { + throw new ArgumentNullException(nameof(projectService)); + } + if (textDocumentFactory == null) { throw new ArgumentNullException(nameof(textDocumentFactory)); } _foregroundDispatcher = foregroundDispatcher; + _projectService = projectService; _textDocumentFactory = textDocumentFactory; } @@ -45,14 +55,13 @@ namespace Microsoft.VisualStudio.Editor.Razor var projectManager = languageServices.GetRequiredService(); var workspaceEditorSettings = languageServices.GetRequiredService(); - var projectService = languageServices.GetRequiredService(); var importDocumentManager = languageServices.GetRequiredService(); return new DefaultVisualStudioDocumentTrackerFactory( _foregroundDispatcher, projectManager, workspaceEditorSettings, - projectService, + _projectService, _textDocumentFactory, importDocumentManager, languageServices.WorkspaceServices.Workspace); diff --git a/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.cs b/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.cs index 7a4649caf8..30ba31714c 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.cs @@ -1,12 +1,11 @@ // 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 TextBufferProjectService : ILanguageService + internal abstract class TextBufferProjectService { public abstract object GetHostProject(ITextBuffer textBuffer); diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs index 7f251c5c94..aeafcec345 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs @@ -2,6 +2,7 @@ // 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.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Shell; @@ -13,6 +14,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor /// /// Infrastructure methods to find project information from an . /// + [System.Composition.Shared] + [Export(typeof(TextBufferProjectService))] internal class DefaultTextBufferProjectService : TextBufferProjectService { private const string DotNetCoreCapability = "(CSharp|VB)&CPS"; @@ -20,13 +23,14 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor private readonly RunningDocumentTable _documentTable; private readonly ITextDocumentFactoryService _documentFactory; + [ImportingConstructor] public DefaultTextBufferProjectService( - RunningDocumentTable documentTable, + [Import(typeof(SVsServiceProvider))] IServiceProvider services, ITextDocumentFactoryService documentFactory) { - if (documentTable == null) + if (services == null) { - throw new ArgumentNullException(nameof(documentTable)); + throw new ArgumentNullException(nameof(services)); } if (documentFactory == null) @@ -35,7 +39,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor } _documentFactory = documentFactory; - _documentTable = documentTable; + _documentTable = new RunningDocumentTable(services); } public override object GetHostProject(ITextBuffer textBuffer) diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs deleted file mode 100644 index 0dd558e7bb..0000000000 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs +++ /dev/null @@ -1,51 +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; -using Microsoft.VisualStudio.Editor.Razor; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Text; - -namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor -{ - [Shared] - [ExportLanguageServiceFactory(typeof(TextBufferProjectService), RazorLanguage.Name)] - internal class DefaultTextBufferProjectServiceFactory : ILanguageServiceFactory - { - private readonly RunningDocumentTable _documentTable; - private readonly ITextDocumentFactoryService _documentFactory; - - [ImportingConstructor] - public DefaultTextBufferProjectServiceFactory( - SVsServiceProvider services, - ITextDocumentFactoryService documentFactory) - { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - - if (documentFactory == null) - { - throw new ArgumentNullException(nameof(documentFactory)); - } - - _documentTable = new RunningDocumentTable(services); - _documentFactory = documentFactory; - } - - public ILanguageService CreateLanguageService(HostLanguageServices languageServices) - { - if (languageServices == null) - { - throw new ArgumentNullException(nameof(languageServices)); - } - - return new DefaultTextBufferProjectService(_documentTable, _documentFactory); - } - } -} diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs index 42c6633919..91297d852b 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs @@ -3,12 +3,11 @@ using System; using System.ComponentModel.Composition; +using System.Runtime.InteropServices; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.Editor.Razor; -using System.Runtime.InteropServices; -using Microsoft.CodeAnalysis.Razor; namespace Microsoft.VisualStudio.LanguageServices.Razor { @@ -23,29 +22,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor [ImportingConstructor] public VsSolutionUpdatesProjectSnapshotChangeTrigger( [Import(typeof(SVsServiceProvider))] IServiceProvider services, - VisualStudioWorkspaceAccessor workspaceAccessor) + TextBufferProjectService projectService) { if (services == null) { throw new ArgumentNullException(nameof(services)); } - if (workspaceAccessor == null) + if (projectService == null) { - throw new ArgumentNullException(nameof(workspaceAccessor)); + throw new ArgumentNullException(nameof(projectService)); } - _services = services; - - var languageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name); - _projectService = languageServices.GetRequiredService(); - } - - // Internal for testing - internal VsSolutionUpdatesProjectSnapshotChangeTrigger( - IServiceProvider services, - TextBufferProjectService projectService) - { _services = services; _projectService = projectService; } diff --git a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs b/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs index dddeed3e74..64696bf571 100644 --- a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs +++ b/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; -using System.Linq; -using Microsoft.CodeAnalysis.Razor; +using System.ComponentModel.Composition; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Text; using MonoDevelop.Ide; @@ -15,27 +13,21 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor.Editor /// /// Infrastructure methods to find project information from an . /// + [System.Composition.Shared] + [Export(typeof(TextBufferProjectService))] internal class DefaultTextBufferProjectService : TextBufferProjectService { private readonly ITextDocumentFactoryService _documentFactory; - private readonly ErrorReporter _errorReporter; - public DefaultTextBufferProjectService( - ITextDocumentFactoryService documentFactory, - ErrorReporter errorReporter) + [ImportingConstructor] + public DefaultTextBufferProjectService(ITextDocumentFactoryService documentFactory) { if (documentFactory == null) { throw new ArgumentNullException(nameof(documentFactory)); } - if (errorReporter == null) - { - throw new ArgumentNullException(nameof(errorReporter)); - } - _documentFactory = documentFactory; - _errorReporter = errorReporter; } public override object GetHostProject(ITextBuffer textBuffer) diff --git a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs b/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs deleted file mode 100644 index 0613662208..0000000000 --- a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs +++ /dev/null @@ -1,44 +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; -using Microsoft.VisualStudio.Editor.Razor; -using Microsoft.VisualStudio.Text; -using MonoDevelop.Ide.TypeSystem; - -namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor.Editor -{ - [Shared] - [ExportLanguageServiceFactory(typeof(TextBufferProjectService), RazorLanguage.Name, ServiceLayer.Default)] - internal class DefaultTextBufferProjectServiceFactory : ILanguageServiceFactory - { - private readonly ITextDocumentFactoryService _documentFactory; - - [ImportingConstructor] - public DefaultTextBufferProjectServiceFactory(ITextDocumentFactoryService documentFactory) - { - if (documentFactory == null) - { - throw new ArgumentNullException(nameof(documentFactory)); - } - - _documentFactory = documentFactory; - } - - public ILanguageService CreateLanguageService(HostLanguageServices languageServices) - { - if (languageServices == null) - { - throw new ArgumentNullException(nameof(languageServices)); - } - - var errorReporter = languageServices.WorkspaceServices.GetRequiredService(); - - return new DefaultTextBufferProjectService(_documentFactory, errorReporter); - } - } -} diff --git a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/ProjectBuildChangeTrigger.cs b/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/ProjectBuildChangeTrigger.cs index 3d36a2dae6..e874735740 100644 --- a/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/ProjectBuildChangeTrigger.cs +++ b/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/ProjectBuildChangeTrigger.cs @@ -19,22 +19,20 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor private ProjectSnapshotManagerBase _projectManager; [ImportingConstructor] - public ProjectBuildChangeTrigger(ForegroundDispatcher foregroundDispatcher, VisualStudioWorkspaceAccessor workspaceAccessor) + public ProjectBuildChangeTrigger(ForegroundDispatcher foregroundDispatcher, TextBufferProjectService projectService) { if (foregroundDispatcher == null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } - if (workspaceAccessor == null) + if (projectService == null) { - throw new ArgumentNullException(nameof(workspaceAccessor)); + throw new ArgumentNullException(nameof(projectService)); } _foregroundDispatcher = foregroundDispatcher; - - var languageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name); - _projectService = languageServices.GetRequiredService(); + _projectService = projectService; } // Internal for testing