Moved TextBufferProjectService from Mef to ILanguageService
This commit is contained in:
parent
6b8223b544
commit
f208b27bd7
|
|
@ -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<ForegroundDispatcher>();
|
||||
return new DefaultRazorDocumentManager(dispatcher, _editorFactoryService, _projectService);
|
||||
var projectService = languageServices.GetRequiredService<TextBufferProjectService>();
|
||||
|
||||
return new DefaultRazorDocumentManager(dispatcher, _editorFactoryService, projectService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ForegroundDispatcher>();
|
||||
var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>();
|
||||
var editorSettingsManager = languageServices.GetRequiredService<EditorSettingsManagerInternal>();
|
||||
var projectService = languageServices.GetRequiredService<TextBufferProjectService>();
|
||||
var importDocumentManager = languageServices.GetRequiredService<ImportDocumentManager>();
|
||||
|
||||
return new DefaultVisualStudioDocumentTrackerFactory(
|
||||
dispatcher,
|
||||
projectManager,
|
||||
editorSettingsManager,
|
||||
_projectService,
|
||||
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 TextBufferProjectService
|
||||
internal abstract class TextBufferProjectService : ILanguageService
|
||||
{
|
||||
public abstract object GetHostProject(ITextBuffer textBuffer);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Infrastructure methods to find project information from an <see cref="ITextBuffer"/>.
|
||||
/// </summary>
|
||||
[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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<TextBufferProjectService>();
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue