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
|
internal class DefaultRazorDocumentManagerFactory : ILanguageServiceFactory
|
||||||
{
|
{
|
||||||
private readonly RazorEditorFactoryService _editorFactoryService;
|
private readonly RazorEditorFactoryService _editorFactoryService;
|
||||||
private readonly TextBufferProjectService _projectService;
|
|
||||||
|
|
||||||
[ImportingConstructor]
|
[ImportingConstructor]
|
||||||
public DefaultRazorDocumentManagerFactory(
|
public DefaultRazorDocumentManagerFactory(RazorEditorFactoryService editorFactoryService)
|
||||||
RazorEditorFactoryService editorFactoryService,
|
|
||||||
TextBufferProjectService projectService)
|
|
||||||
{
|
{
|
||||||
if (editorFactoryService == null)
|
if (editorFactoryService == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(editorFactoryService));
|
throw new ArgumentNullException(nameof(editorFactoryService));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectService == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(projectService));
|
|
||||||
}
|
|
||||||
|
|
||||||
_editorFactoryService = editorFactoryService;
|
_editorFactoryService = editorFactoryService;
|
||||||
_projectService = projectService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
|
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
|
||||||
|
|
@ -43,7 +34,9 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
}
|
}
|
||||||
|
|
||||||
var dispatcher = languageServices.WorkspaceServices.GetRequiredService<ForegroundDispatcher>();
|
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)]
|
[ExportLanguageServiceFactory(typeof(VisualStudioDocumentTrackerFactory), RazorLanguage.Name, ServiceLayer.Default)]
|
||||||
internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory
|
internal class DefaultVisualStudioDocumentTrackerFactoryFactory : ILanguageServiceFactory
|
||||||
{
|
{
|
||||||
private readonly TextBufferProjectService _projectService;
|
|
||||||
private readonly ITextDocumentFactoryService _textDocumentFactory;
|
private readonly ITextDocumentFactoryService _textDocumentFactory;
|
||||||
|
|
||||||
[ImportingConstructor]
|
[ImportingConstructor]
|
||||||
public DefaultVisualStudioDocumentTrackerFactoryFactory(
|
public DefaultVisualStudioDocumentTrackerFactoryFactory(ITextDocumentFactoryService textDocumentFactory)
|
||||||
TextBufferProjectService projectService,
|
|
||||||
ITextDocumentFactoryService textDocumentFactory)
|
|
||||||
{
|
{
|
||||||
if (projectService == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(projectService));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textDocumentFactory == null)
|
if (textDocumentFactory == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(textDocumentFactory));
|
throw new ArgumentNullException(nameof(textDocumentFactory));
|
||||||
}
|
}
|
||||||
|
|
||||||
_projectService = projectService;
|
|
||||||
_textDocumentFactory = textDocumentFactory;
|
_textDocumentFactory = textDocumentFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,13 +39,14 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
||||||
var dispatcher = languageServices.WorkspaceServices.GetRequiredService<ForegroundDispatcher>();
|
var dispatcher = languageServices.WorkspaceServices.GetRequiredService<ForegroundDispatcher>();
|
||||||
var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>();
|
var projectManager = languageServices.GetRequiredService<ProjectSnapshotManager>();
|
||||||
var editorSettingsManager = languageServices.GetRequiredService<EditorSettingsManagerInternal>();
|
var editorSettingsManager = languageServices.GetRequiredService<EditorSettingsManagerInternal>();
|
||||||
|
var projectService = languageServices.GetRequiredService<TextBufferProjectService>();
|
||||||
var importDocumentManager = languageServices.GetRequiredService<ImportDocumentManager>();
|
var importDocumentManager = languageServices.GetRequiredService<ImportDocumentManager>();
|
||||||
|
|
||||||
return new DefaultVisualStudioDocumentTrackerFactory(
|
return new DefaultVisualStudioDocumentTrackerFactory(
|
||||||
dispatcher,
|
dispatcher,
|
||||||
projectManager,
|
projectManager,
|
||||||
editorSettingsManager,
|
editorSettingsManager,
|
||||||
_projectService,
|
projectService,
|
||||||
_textDocumentFactory,
|
_textDocumentFactory,
|
||||||
importDocumentManager,
|
importDocumentManager,
|
||||||
languageServices.WorkspaceServices.Workspace);
|
languageServices.WorkspaceServices.Workspace);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
// 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
|
internal abstract class TextBufferProjectService : ILanguageService
|
||||||
{
|
{
|
||||||
public abstract object GetHostProject(ITextBuffer textBuffer);
|
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.
|
// 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.CodeAnalysis;
|
|
||||||
using Microsoft.VisualStudio.Editor.Razor;
|
using Microsoft.VisualStudio.Editor.Razor;
|
||||||
using Microsoft.VisualStudio.Shell;
|
using Microsoft.VisualStudio.Shell;
|
||||||
using Microsoft.VisualStudio.Shell.Interop;
|
using Microsoft.VisualStudio.Shell.Interop;
|
||||||
|
|
@ -15,7 +13,6 @@ 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>
|
||||||
[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";
|
||||||
|
|
@ -23,15 +20,13 @@ 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(
|
||||||
[Import(typeof(SVsServiceProvider))] IServiceProvider services,
|
RunningDocumentTable documentTable,
|
||||||
ITextDocumentFactoryService documentFactory,
|
ITextDocumentFactoryService documentFactory)
|
||||||
[Import(typeof(VisualStudioWorkspace))] Workspace workspace)
|
|
||||||
{
|
{
|
||||||
if (services == null)
|
if (documentTable == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(services));
|
throw new ArgumentNullException(nameof(documentTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (documentFactory == null)
|
if (documentFactory == null)
|
||||||
|
|
@ -40,7 +35,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor
|
||||||
}
|
}
|
||||||
|
|
||||||
_documentFactory = documentFactory;
|
_documentFactory = documentFactory;
|
||||||
_documentTable = new RunningDocumentTable(services);
|
_documentTable = documentTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object GetHostProject(ITextBuffer textBuffer)
|
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.Shell.Interop;
|
||||||
using Microsoft.VisualStudio.Editor.Razor;
|
using Microsoft.VisualStudio.Editor.Razor;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.CodeAnalysis.Razor;
|
||||||
|
|
||||||
namespace Microsoft.VisualStudio.LanguageServices.Razor
|
namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
{
|
{
|
||||||
|
|
@ -22,6 +23,27 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
[ImportingConstructor]
|
[ImportingConstructor]
|
||||||
public VsSolutionUpdatesProjectSnapshotChangeTrigger(
|
public VsSolutionUpdatesProjectSnapshotChangeTrigger(
|
||||||
[Import(typeof(SVsServiceProvider))] IServiceProvider services,
|
[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)
|
TextBufferProjectService projectService)
|
||||||
{
|
{
|
||||||
_services = services;
|
_services = services;
|
||||||
|
|
@ -72,6 +94,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
return VSConstants.S_OK;
|
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)
|
public int UpdateProjectCfg_Done(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, int fSuccess, int fCancel)
|
||||||
{
|
{
|
||||||
var projectName = _projectService.GetProjectName(pHierProj);
|
var projectName = _projectService.GetProjectName(pHierProj);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue