diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs index ac6eb886bd..834092ae72 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManagerFactory.cs @@ -14,25 +14,16 @@ namespace Microsoft.VisualStudio.Editor.Razor internal class DefaultRazorDocumentManagerFactory : ILanguageServiceFactory { private readonly RazorEditorFactoryService _editorFactoryService; - private readonly TextBufferProjectService _projectService; [ImportingConstructor] - public DefaultRazorDocumentManagerFactory( - RazorEditorFactoryService editorFactoryService, - TextBufferProjectService projectService) + public DefaultRazorDocumentManagerFactory(RazorEditorFactoryService editorFactoryService) { if (editorFactoryService == null) { throw new ArgumentNullException(nameof(editorFactoryService)); } - if (projectService == null) - { - throw new ArgumentNullException(nameof(projectService)); - } - _editorFactoryService = editorFactoryService; - _projectService = projectService; } public ILanguageService CreateLanguageService(HostLanguageServices languageServices) @@ -43,7 +34,9 @@ namespace Microsoft.VisualStudio.Editor.Razor } var dispatcher = languageServices.WorkspaceServices.GetRequiredService(); - return new DefaultRazorDocumentManager(dispatcher, _editorFactoryService, _projectService); + var projectService = languageServices.GetRequiredService(); + + return new DefaultRazorDocumentManager(dispatcher, _editorFactoryService, projectService); } } } diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs index 4fd4f1f583..a43d02eb98 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioDocumentTrackerFactoryFactory.cs @@ -16,25 +16,16 @@ namespace Microsoft.VisualStudio.Editor.Razor [ExportLanguageServiceFactory(typeof(VisualStudioDocumentTrackerFactory), RazorLanguage.Name, ServiceLayer.Default)] internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory { - private readonly TextBufferProjectService _projectService; private readonly ITextDocumentFactoryService _textDocumentFactory; [ImportingConstructor] - public DefaultVisualStudioDocumentTrackerFactoryFactory( - TextBufferProjectService projectService, - ITextDocumentFactoryService textDocumentFactory) + public DefaultVisualStudioDocumentTrackerFactoryFactory(ITextDocumentFactoryService textDocumentFactory) { - if (projectService == null) - { - throw new ArgumentNullException(nameof(projectService)); - } - if (textDocumentFactory == null) { throw new ArgumentNullException(nameof(textDocumentFactory)); } - _projectService = projectService; _textDocumentFactory = textDocumentFactory; } @@ -48,13 +39,14 @@ namespace Microsoft.VisualStudio.Editor.Razor var dispatcher = languageServices.WorkspaceServices.GetRequiredService(); var projectManager = languageServices.GetRequiredService(); var editorSettingsManager = languageServices.GetRequiredService(); + var projectService = languageServices.GetRequiredService(); var importDocumentManager = languageServices.GetRequiredService(); return new DefaultVisualStudioDocumentTrackerFactory( dispatcher, projectManager, editorSettingsManager, - _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 30ba31714c..7a4649caf8 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/TextBufferProjectService.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 TextBufferProjectService + internal abstract class TextBufferProjectService : ILanguageService { 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 e0fe9a9540..7f251c5c94 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs +++ b/src/Microsoft.VisualStudio.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.ComponentModel.Composition; using System.Diagnostics; -using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; @@ -15,7 +13,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor /// /// Infrastructure methods to find project information from an . /// - [Export(typeof(TextBufferProjectService))] internal class DefaultTextBufferProjectService : TextBufferProjectService { private const string DotNetCoreCapability = "(CSharp|VB)&CPS"; @@ -23,15 +20,13 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor private readonly RunningDocumentTable _documentTable; private readonly ITextDocumentFactoryService _documentFactory; - [ImportingConstructor] public DefaultTextBufferProjectService( - [Import(typeof(SVsServiceProvider))] IServiceProvider services, - ITextDocumentFactoryService documentFactory, - [Import(typeof(VisualStudioWorkspace))] Workspace workspace) + RunningDocumentTable documentTable, + ITextDocumentFactoryService documentFactory) { - if (services == null) + if (documentTable == null) { - throw new ArgumentNullException(nameof(services)); + throw new ArgumentNullException(nameof(documentTable)); } if (documentFactory == null) @@ -40,7 +35,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor } _documentFactory = documentFactory; - _documentTable = new RunningDocumentTable(services); + _documentTable = documentTable; } 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 new file mode 100644 index 0000000000..0dd558e7bb --- /dev/null +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectServiceFactory.cs @@ -0,0 +1,51 @@ +// 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 bc5f0d569b..42c6633919 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/VsSolutionUpdatesProjectSnapshotChangeTrigger.cs @@ -8,6 +8,7 @@ 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 { @@ -22,6 +23,27 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor [ImportingConstructor] public VsSolutionUpdatesProjectSnapshotChangeTrigger( [Import(typeof(SVsServiceProvider))] IServiceProvider services, + VisualStudioWorkspaceAccessor workspaceAccessor) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + if (workspaceAccessor == null) + { + throw new ArgumentNullException(nameof(workspaceAccessor)); + } + + _services = services; + + var languageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name); + _projectService = languageServices.GetRequiredService(); + } + + // Internal for testing + internal VsSolutionUpdatesProjectSnapshotChangeTrigger( + IServiceProvider services, TextBufferProjectService projectService) { _services = services; @@ -72,6 +94,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor return VSConstants.S_OK; } + // This gets called when the project has finished building. public int UpdateProjectCfg_Done(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, int fSuccess, int fCancel) { var projectName = _projectService.GetProjectName(pHierProj);