Change TextBufferProjectService to not be per-workspace.

- Updated impacted code to now expect this from MEF.

#1997
This commit is contained in:
N. Taylor Mullen 2018-01-31 16:21:40 -08:00
parent e3932aa1ec
commit 5e454a36fa
9 changed files with 47 additions and 144 deletions

View File

@ -15,9 +15,13 @@ namespace Microsoft.VisualStudio.Editor.Razor
{ {
private readonly ForegroundDispatcher _foregroundDispatcher; private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly RazorEditorFactoryService _editorFactoryService; private readonly RazorEditorFactoryService _editorFactoryService;
private readonly TextBufferProjectService _projectService;
[ImportingConstructor] [ImportingConstructor]
public DefaultRazorDocumentManagerFactory(ForegroundDispatcher foregroundDispatcher, RazorEditorFactoryService editorFactoryService) public DefaultRazorDocumentManagerFactory(
ForegroundDispatcher foregroundDispatcher,
RazorEditorFactoryService editorFactoryService,
TextBufferProjectService projectService)
{ {
if (foregroundDispatcher == null) if (foregroundDispatcher == null)
{ {
@ -29,8 +33,14 @@ namespace Microsoft.VisualStudio.Editor.Razor
throw new ArgumentNullException(nameof(editorFactoryService)); throw new ArgumentNullException(nameof(editorFactoryService));
} }
if (projectService == null)
{
throw new ArgumentNullException(nameof(projectService));
}
_foregroundDispatcher = foregroundDispatcher; _foregroundDispatcher = foregroundDispatcher;
_editorFactoryService = editorFactoryService; _editorFactoryService = editorFactoryService;
_projectService = projectService;
} }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
@ -40,9 +50,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
throw new ArgumentNullException(nameof(languageServices)); throw new ArgumentNullException(nameof(languageServices));
} }
var projectService = languageServices.GetRequiredService<TextBufferProjectService>(); return new DefaultRazorDocumentManager(_foregroundDispatcher, _editorFactoryService, _projectService);
return new DefaultRazorDocumentManager(_foregroundDispatcher, _editorFactoryService, projectService);
} }
} }
} }

View File

@ -17,22 +17,32 @@ namespace Microsoft.VisualStudio.Editor.Razor
internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory
{ {
private readonly ForegroundDispatcher _foregroundDispatcher; private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly TextBufferProjectService _projectService;
private readonly ITextDocumentFactoryService _textDocumentFactory; private readonly ITextDocumentFactoryService _textDocumentFactory;
[ImportingConstructor] [ImportingConstructor]
public DefaultVisualStudioDocumentTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher, ITextDocumentFactoryService textDocumentFactory) public DefaultVisualStudioDocumentTrackerFactoryFactory(
ForegroundDispatcher foregroundDispatcher,
TextBufferProjectService projectService,
ITextDocumentFactoryService textDocumentFactory)
{ {
if (foregroundDispatcher == null) if (foregroundDispatcher == null)
{ {
throw new ArgumentNullException(nameof(foregroundDispatcher)); throw new ArgumentNullException(nameof(foregroundDispatcher));
} }
if (projectService == null)
{
throw new ArgumentNullException(nameof(projectService));
}
if (textDocumentFactory == null) if (textDocumentFactory == null)
{ {
throw new ArgumentNullException(nameof(textDocumentFactory)); throw new ArgumentNullException(nameof(textDocumentFactory));
} }
_foregroundDispatcher = foregroundDispatcher; _foregroundDispatcher = foregroundDispatcher;
_projectService = projectService;
_textDocumentFactory = textDocumentFactory; _textDocumentFactory = textDocumentFactory;
} }
@ -45,14 +55,13 @@ namespace Microsoft.VisualStudio.Editor.Razor
var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>(); var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>();
var workspaceEditorSettings = languageServices.GetRequiredService<WorkspaceEditorSettings>(); var workspaceEditorSettings = languageServices.GetRequiredService<WorkspaceEditorSettings>();
var projectService = languageServices.GetRequiredService<TextBufferProjectService>();
var importDocumentManager = languageServices.GetRequiredService<ImportDocumentManager>(); var importDocumentManager = languageServices.GetRequiredService<ImportDocumentManager>();
return new DefaultVisualStudioDocumentTrackerFactory( return new DefaultVisualStudioDocumentTrackerFactory(
_foregroundDispatcher, _foregroundDispatcher,
projectManager, projectManager,
workspaceEditorSettings, workspaceEditorSettings,
projectService, _projectService,
_textDocumentFactory, _textDocumentFactory,
importDocumentManager, importDocumentManager,
languageServices.WorkspaceServices.Workspace); languageServices.WorkspaceServices.Workspace);

View File

@ -1,12 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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; using Microsoft.VisualStudio.Text;
namespace Microsoft.VisualStudio.Editor.Razor namespace Microsoft.VisualStudio.Editor.Razor
{ {
internal abstract class TextBufferProjectService : ILanguageService internal abstract class TextBufferProjectService
{ {
public abstract object GetHostProject(ITextBuffer textBuffer); public abstract object GetHostProject(ITextBuffer textBuffer);

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.ComponentModel.Composition;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell;
@ -13,6 +14,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
/// <summary> /// <summary>
/// Infrastructure methods to find project information from an <see cref="ITextBuffer"/>. /// Infrastructure methods to find project information from an <see cref="ITextBuffer"/>.
/// </summary> /// </summary>
[System.Composition.Shared]
[Export(typeof(TextBufferProjectService))]
internal class DefaultTextBufferProjectService : TextBufferProjectService internal class DefaultTextBufferProjectService : TextBufferProjectService
{ {
private const string DotNetCoreCapability = "(CSharp|VB)&CPS"; private const string DotNetCoreCapability = "(CSharp|VB)&CPS";
@ -20,13 +23,14 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
private readonly RunningDocumentTable _documentTable; private readonly RunningDocumentTable _documentTable;
private readonly ITextDocumentFactoryService _documentFactory; private readonly ITextDocumentFactoryService _documentFactory;
[ImportingConstructor]
public DefaultTextBufferProjectService( public DefaultTextBufferProjectService(
RunningDocumentTable documentTable, [Import(typeof(SVsServiceProvider))] IServiceProvider services,
ITextDocumentFactoryService documentFactory) ITextDocumentFactoryService documentFactory)
{ {
if (documentTable == null) if (services == null)
{ {
throw new ArgumentNullException(nameof(documentTable)); throw new ArgumentNullException(nameof(services));
} }
if (documentFactory == null) if (documentFactory == null)
@ -35,7 +39,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
} }
_documentFactory = documentFactory; _documentFactory = documentFactory;
_documentTable = documentTable; _documentTable = new RunningDocumentTable(services);
} }
public override object GetHostProject(ITextBuffer textBuffer) public override object GetHostProject(ITextBuffer textBuffer)

View File

@ -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);
}
}
}

View File

@ -3,12 +3,11 @@
using System; using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Editor.Razor;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Razor;
namespace Microsoft.VisualStudio.LanguageServices.Razor namespace Microsoft.VisualStudio.LanguageServices.Razor
{ {
@ -23,29 +22,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
[ImportingConstructor] [ImportingConstructor]
public VsSolutionUpdatesProjectSnapshotChangeTrigger( public VsSolutionUpdatesProjectSnapshotChangeTrigger(
[Import(typeof(SVsServiceProvider))] IServiceProvider services, [Import(typeof(SVsServiceProvider))] IServiceProvider services,
VisualStudioWorkspaceAccessor workspaceAccessor) TextBufferProjectService projectService)
{ {
if (services == null) if (services == null)
{ {
throw new ArgumentNullException(nameof(services)); 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<TextBufferProjectService>();
}
// Internal for testing
internal VsSolutionUpdatesProjectSnapshotChangeTrigger(
IServiceProvider services,
TextBufferProjectService projectService)
{
_services = services; _services = services;
_projectService = projectService; _projectService = projectService;
} }

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Diagnostics; using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text;
using MonoDevelop.Ide; using MonoDevelop.Ide;
@ -15,27 +13,21 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor.Editor
/// <summary> /// <summary>
/// Infrastructure methods to find project information from an <see cref="ITextBuffer"/>. /// Infrastructure methods to find project information from an <see cref="ITextBuffer"/>.
/// </summary> /// </summary>
[System.Composition.Shared]
[Export(typeof(TextBufferProjectService))]
internal class DefaultTextBufferProjectService : TextBufferProjectService internal class DefaultTextBufferProjectService : TextBufferProjectService
{ {
private readonly ITextDocumentFactoryService _documentFactory; private readonly ITextDocumentFactoryService _documentFactory;
private readonly ErrorReporter _errorReporter;
public DefaultTextBufferProjectService( [ImportingConstructor]
ITextDocumentFactoryService documentFactory, public DefaultTextBufferProjectService(ITextDocumentFactoryService documentFactory)
ErrorReporter errorReporter)
{ {
if (documentFactory == null) if (documentFactory == null)
{ {
throw new ArgumentNullException(nameof(documentFactory)); throw new ArgumentNullException(nameof(documentFactory));
} }
if (errorReporter == null)
{
throw new ArgumentNullException(nameof(errorReporter));
}
_documentFactory = documentFactory; _documentFactory = documentFactory;
_errorReporter = errorReporter;
} }
public override object GetHostProject(ITextBuffer textBuffer) public override object GetHostProject(ITextBuffer textBuffer)

View File

@ -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<ErrorReporter>();
return new DefaultTextBufferProjectService(_documentFactory, errorReporter);
}
}
}

View File

@ -19,22 +19,20 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
private ProjectSnapshotManagerBase _projectManager; private ProjectSnapshotManagerBase _projectManager;
[ImportingConstructor] [ImportingConstructor]
public ProjectBuildChangeTrigger(ForegroundDispatcher foregroundDispatcher, VisualStudioWorkspaceAccessor workspaceAccessor) public ProjectBuildChangeTrigger(ForegroundDispatcher foregroundDispatcher, TextBufferProjectService projectService)
{ {
if (foregroundDispatcher == null) if (foregroundDispatcher == null)
{ {
throw new ArgumentNullException(nameof(foregroundDispatcher)); throw new ArgumentNullException(nameof(foregroundDispatcher));
} }
if (workspaceAccessor == null) if (projectService == null)
{ {
throw new ArgumentNullException(nameof(workspaceAccessor)); throw new ArgumentNullException(nameof(projectService));
} }
_foregroundDispatcher = foregroundDispatcher; _foregroundDispatcher = foregroundDispatcher;
_projectService = projectService;
var languageServices = workspaceAccessor.Workspace.Services.GetLanguageServices(RazorLanguage.Name);
_projectService = languageServices.GetRequiredService<TextBufferProjectService>();
} }
// Internal for testing // Internal for testing