Reorganize file tracker

This is precursor to a much bigger change. Pushing out some of the
changes that have broad impact early to make it easier to review the
real change.
This commit is contained in:
Ryan Nowak 2018-05-08 15:36:33 -07:00 committed by Ryan Nowak
parent 0f2b315fe4
commit 1d5245c421
30 changed files with 159 additions and 111 deletions

View File

@ -39,15 +39,15 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return State.GeneratedOutput.GetGeneratedOutputInitializationTask(Project, this);
}
public override bool TryGetGeneratedOutput(out RazorCodeDocument results)
public override bool TryGetGeneratedOutput(out RazorCodeDocument result)
{
if (State.GeneratedOutput.IsResultAvailable)
{
results = State.GeneratedOutput.GetGeneratedOutputInitializationTask(Project, this).Result;
result = State.GeneratedOutput.GetGeneratedOutputInitializationTask(Project, this).Result;
return true;
}
results = null;
result = null;
return false;
}
}

View File

@ -69,15 +69,15 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return State.TagHelpers.GetTagHelperInitializationTask(this);
}
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> results)
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> result)
{
if (State.TagHelpers.IsResultAvailable)
{
results = State.TagHelpers.GetTagHelperInitializationTask(this).Result;
result = State.TagHelpers.GetTagHelperInitializationTask(this).Result;
return true;
}
results = null;
result = null;
return false;
}
}

View File

@ -149,7 +149,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
var state = entry.State.AddHostDocument(document);
var state = entry.State.WithAddedHostDocument(document);
// Document updates can no-op.
if (!object.ReferenceEquals(state, entry.State))
@ -175,7 +175,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
_foregroundDispatcher.AssertForegroundThread();
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
var state = entry.State.RemoveHostDocument(document);
var state = entry.State.WithRemovedHostDocument(document);
// Document updates can no-op.
if (!object.ReferenceEquals(state, entry.State))

View File

@ -14,6 +14,6 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public abstract Task<RazorCodeDocument> GetGeneratedOutputAsync();
public abstract bool TryGetGeneratedOutput(out RazorCodeDocument results);
public abstract bool TryGetGeneratedOutput(out RazorCodeDocument result);
}
}

View File

@ -66,9 +66,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return EmptyTagHelpers;
}
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> results)
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> result)
{
results = EmptyTagHelpers.Result;
result = EmptyTagHelpers.Result;
return true;
}

View File

@ -27,6 +27,6 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public abstract Task<IReadOnlyList<TagHelperDescriptor>> GetTagHelpersAsync();
public abstract bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> results);
public abstract bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> result);
}
}

View File

@ -126,7 +126,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
}
}
public ProjectState AddHostDocument(HostDocument hostDocument)
public ProjectState WithAddedHostDocument(HostDocument hostDocument)
{
if (hostDocument == null)
{
@ -153,7 +153,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return state;
}
public ProjectState RemoveHostDocument(HostDocument hostDocument)
public ProjectState WithRemovedHostDocument(HostDocument hostDocument)
{
if (hostDocument == null)
{

View File

@ -86,7 +86,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor
throw new NotImplementedException();
}
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> results)
public override bool TryGetTagHelpers(out IReadOnlyList<TagHelperDescriptor> result)
{
throw new NotImplementedException();
}

View File

@ -4,10 +4,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor.Documents;
namespace Microsoft.VisualStudio.Editor.Razor
{

View File

@ -6,6 +6,7 @@ using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor.Documents;
namespace Microsoft.VisualStudio.Editor.Razor
{
@ -34,7 +35,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
}
var errorReporter = languageServices.WorkspaceServices.GetRequiredService<ErrorReporter>();
var fileChangeTrackerFactory = languageServices.GetRequiredService<FileChangeTrackerFactory>();
var fileChangeTrackerFactory = languageServices.WorkspaceServices.GetRequiredService<FileChangeTrackerFactory>();
return new DefaultImportDocumentManager(_foregroundDispatcher, errorReporter, fileChangeTrackerFactory);
}

View File

@ -0,0 +1,37 @@
// 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;
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
// A noop implementation for non-ide cases
internal class DefaultFileChangeTracker : FileChangeTracker
{
public override event EventHandler<FileChangeEventArgs> Changed;
public DefaultFileChangeTracker(string filePath)
{
if (filePath == null)
{
throw new ArgumentNullException(nameof(filePath));
}
FilePath = filePath;
GC.KeepAlive(Changed);
}
public override string FilePath { get; }
public override void StartListening()
{
// Do nothing
}
public override void StopListening()
{
// Do nothing
}
}
}

View File

@ -0,0 +1,22 @@
// 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 Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
[ExportWorkspaceService(typeof(FileChangeTrackerFactory), layer: ServiceLayer.Editor)]
internal class DefaultFileChangeTrackerFactory : FileChangeTrackerFactory
{
public override FileChangeTracker Create(string filePath)
{
if (filePath == null)
{
throw new ArgumentNullException(nameof(filePath));
}
return new DefaultFileChangeTracker(filePath);
}
}
}

View File

@ -3,7 +3,7 @@
using System;
namespace Microsoft.VisualStudio.Editor.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal sealed class FileChangeEventArgs : EventArgs
{

View File

@ -1,7 +1,7 @@
// 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.
namespace Microsoft.VisualStudio.Editor.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal enum FileChangeKind
{

View File

@ -3,7 +3,7 @@
using System;
namespace Microsoft.VisualStudio.Editor.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal abstract class FileChangeTracker
{

View File

@ -3,9 +3,9 @@
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.VisualStudio.Editor.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal abstract class FileChangeTrackerFactory : ILanguageService
internal abstract class FileChangeTrackerFactory : IWorkspaceService
{
public abstract FileChangeTracker Create(string filePath);
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Editor.Razor.Documents;
namespace Microsoft.VisualStudio.Editor.Razor
{

View File

@ -2,15 +2,13 @@
// 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.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal class DefaultFileChangeTracker : FileChangeTracker, IVsFileChangeEvents
internal class VisualStudioFileChangeTracker : FileChangeTracker, IVsFileChangeEvents
{
private const uint FileChangeFlags = (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Del | _VSFILECHANGEFLAGS.VSFILECHG_Add);
@ -21,7 +19,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
public override event EventHandler<FileChangeEventArgs> Changed;
public DefaultFileChangeTracker(
public VisualStudioFileChangeTracker(
string filePath,
ForegroundDispatcher foregroundDispatcher,
ErrorReporter errorReporter,

View File

@ -3,18 +3,17 @@
using System;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal partial class DefaultFileChangeTrackerFactory : FileChangeTrackerFactory
internal class VisualStudioFileChangeTrackerFactory : FileChangeTrackerFactory
{
private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly ErrorReporter _errorReporter;
private readonly IVsFileChangeEx _fileChangeService;
public DefaultFileChangeTrackerFactory(
public VisualStudioFileChangeTrackerFactory(
ForegroundDispatcher foregroundDispatcher,
ErrorReporter errorReporter,
IVsFileChangeEx fileChangeService)
@ -46,7 +45,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath));
}
var fileChangeTracker = new DefaultFileChangeTracker(filePath, _foregroundDispatcher, _errorReporter, _fileChangeService);
var fileChangeTracker = new VisualStudioFileChangeTracker(filePath, _foregroundDispatcher, _errorReporter, _fileChangeService);
return fileChangeTracker;
}
}

View File

@ -6,21 +6,20 @@ 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.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
[Shared]
[ExportLanguageServiceFactory(typeof(FileChangeTrackerFactory), RazorLanguage.Name, ServiceLayer.Default)]
internal class DefaultFileChangeTrackerFactoryFactory : ILanguageServiceFactory
[ExportWorkspaceServiceFactory(typeof(FileChangeTrackerFactory), ServiceLayer.Host)]
internal class VisualStudioFileChangeTrackerFactoryFactory : IWorkspaceServiceFactory
{
private readonly IVsFileChangeEx _fileChangeService;
private readonly ForegroundDispatcher _foregroundDispatcher;
[ImportingConstructor]
public DefaultFileChangeTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher, SVsServiceProvider serviceProvider)
public VisualStudioFileChangeTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher, SVsServiceProvider serviceProvider)
{
if (foregroundDispatcher == null)
{
@ -35,16 +34,15 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
_foregroundDispatcher = foregroundDispatcher;
_fileChangeService = serviceProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
}
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
{
if (languageServices == null)
if (workspaceServices == null)
{
throw new ArgumentNullException(nameof(languageServices));
throw new ArgumentNullException(nameof(workspaceServices));
}
var errorReporter = languageServices.WorkspaceServices.GetRequiredService<ErrorReporter>();
return new DefaultFileChangeTrackerFactory(_foregroundDispatcher, errorReporter, _fileChangeService);
var errorReporter = workspaceServices.GetRequiredService<ErrorReporter>();
return new VisualStudioFileChangeTrackerFactory(_foregroundDispatcher, errorReporter, _fileChangeService);
}
}
}

View File

@ -3,12 +3,11 @@
using System;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using MonoDevelop.Core;
namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal class DefaultFileChangeTracker : FileChangeTracker
internal class VisualStudioMacFileChangeTracker : FileChangeTracker
{
private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly string _normalizedFilePath;
@ -16,7 +15,7 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
public override event EventHandler<FileChangeEventArgs> Changed;
public DefaultFileChangeTracker(
public VisualStudioMacFileChangeTracker(
string filePath,
ForegroundDispatcher foregroundDispatcher)
{

View File

@ -3,15 +3,14 @@
using System;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
internal class DefaultFileChangeTrackerFactory : FileChangeTrackerFactory
internal class VisualStudioMacFileChangeTrackerFactory : FileChangeTrackerFactory
{
private readonly ForegroundDispatcher _foregroundDispatcher;
public DefaultFileChangeTrackerFactory(ForegroundDispatcher foregroundDispatcher)
public VisualStudioMacFileChangeTrackerFactory(ForegroundDispatcher foregroundDispatcher)
{
if (foregroundDispatcher == null)
{
@ -28,7 +27,7 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath));
}
var fileChangeTracker = new DefaultFileChangeTracker(filePath, _foregroundDispatcher);
var fileChangeTracker = new VisualStudioMacFileChangeTracker(filePath, _foregroundDispatcher);
return fileChangeTracker;
}
}

View File

@ -6,18 +6,17 @@ using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
[Shared]
[ExportLanguageServiceFactory(typeof(FileChangeTrackerFactory), RazorLanguage.Name, ServiceLayer.Default)]
internal class DefaultFileChangeTrackerFactoryFactory : ILanguageServiceFactory
[ExportWorkspaceService(typeof(FileChangeTrackerFactory), ServiceLayer.Host)]
internal class VisualStudioMacFileChangeTrackerFactoryFactory : IWorkspaceServiceFactory
{
private readonly ForegroundDispatcher _foregroundDispatcher;
[ImportingConstructor]
public DefaultFileChangeTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher)
public VisualStudioMacFileChangeTrackerFactoryFactory(ForegroundDispatcher foregroundDispatcher)
{
if (foregroundDispatcher == null)
{
@ -27,14 +26,14 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
_foregroundDispatcher = foregroundDispatcher;
}
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
{
if (languageServices == null)
if (workspaceServices == null)
{
throw new ArgumentNullException(nameof(languageServices));
throw new ArgumentNullException(nameof(workspaceServices));
}
return new DefaultFileChangeTrackerFactory(_foregroundDispatcher);
return new VisualStudioMacFileChangeTrackerFactory(_foregroundDispatcher);
}
}
}

View File

@ -77,9 +77,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var state = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[0])
.AddHostDocument(Documents[1])
.AddHostDocument(Documents[2]);
.WithAddedHostDocument(Documents[0])
.WithAddedHostDocument(Documents[1])
.WithAddedHostDocument(Documents[2]);
var snapshot = new DefaultProjectSnapshot(state);
// Act

View File

@ -106,7 +106,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject);
// Act
var state = original.AddHostDocument(Documents[0]);
var state = original.WithAddedHostDocument(Documents[0]);
// Assert
Assert.NotEqual(original.Version, state.Version);
@ -121,11 +121,11 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Act
var state = original.AddHostDocument(Documents[0]);
var state = original.WithAddedHostDocument(Documents[0]);
// Assert
Assert.NotEqual(original.Version, state.Version);
@ -142,15 +142,15 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
GC.KeepAlive(original.TagHelpers);
// Act
var state = original.AddHostDocument(Documents[0]);
var state = original.WithAddedHostDocument(Documents[0]);
// Assert
Assert.Same(original.ProjectEngine, state.ProjectEngine);
@ -165,11 +165,11 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Act
var state = original.AddHostDocument(new HostDocument(Documents[1].FilePath, "SomePath.cshtml"));
var state = original.WithAddedHostDocument(new HostDocument(Documents[1].FilePath, "SomePath.cshtml"));
// Assert
Assert.Same(original, state);
@ -180,11 +180,11 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Act
var state = original.RemoveHostDocument(Documents[1]);
var state = original.WithRemovedHostDocument(Documents[1]);
// Assert
Assert.NotEqual(original.Version, state.Version);
@ -199,15 +199,15 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
GC.KeepAlive(original.TagHelpers);
// Act
var state = original.RemoveHostDocument(Documents[2]);
var state = original.WithRemovedHostDocument(Documents[2]);
// Assert
Assert.Same(original.ProjectEngine, state.ProjectEngine);
@ -221,11 +221,11 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Act
var state = original.RemoveHostDocument(Documents[0]);
var state = original.WithRemovedHostDocument(Documents[0]);
// Assert
Assert.Same(original, state);
@ -236,8 +236,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
@ -262,8 +262,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
@ -281,8 +281,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
@ -307,8 +307,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, null)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);
@ -333,8 +333,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
// Arrange
var original = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
.AddHostDocument(Documents[2])
.AddHostDocument(Documents[1]);
.WithAddedHostDocument(Documents[2])
.WithAddedHostDocument(Documents[1]);
// Force init
GC.KeepAlive(original.ProjectEngine);

View File

@ -1,16 +1,14 @@
// 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.IO;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Moq;
using Xunit;
namespace Microsoft.VisualStudio.Editor.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
public class DefaultImportDocumentManagerIntegrationTest : ForegroundDispatcherTestBase
{

View File

@ -6,6 +6,7 @@ using System.IO;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.VisualStudio.Editor.Razor.Documents;
using Moq;
using Xunit;

View File

@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Editor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.VisualStudio.Editor.Razor.Documents;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;

View File

@ -3,14 +3,13 @@
using System;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using Microsoft.VisualStudio.Shell.Interop;
using Moq;
using Xunit;
namespace Microsoft.VisualStudio.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
public class DefaultFileChangeTrackerTest : ForegroundDispatcherTestBase
public class VisualStudioFileChangeTrackerTest : ForegroundDispatcherTestBase
{
private ErrorReporter ErrorReporter { get; } = new DefaultErrorReporter();
@ -24,7 +23,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
.Setup(f => f.AdviseFileChange(It.IsAny<string>(), It.IsAny<uint>(), It.IsAny<IVsFileChangeEvents>(), out cookie))
.Returns(VSConstants.S_OK)
.Verifiable();
var tracker = new DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
var tracker = new VisualStudioFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
// Act
tracker.StartListening();
@ -44,7 +43,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
.Setup(f => f.AdviseFileChange(It.IsAny<string>(), It.IsAny<uint>(), It.IsAny<IVsFileChangeEvents>(), out cookie))
.Returns(VSConstants.S_OK)
.Callback(() => callCount++);
var tracker = new DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
var tracker = new VisualStudioFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
tracker.StartListening();
// Act
@ -68,7 +67,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
.Setup(f => f.UnadviseFileChange(cookie))
.Returns(VSConstants.S_OK)
.Verifiable();
var tracker = new DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
var tracker = new VisualStudioFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
tracker.StartListening(); // Start listening for changes.
// Act
@ -87,7 +86,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
fileChangeService
.Setup(f => f.UnadviseFileChange(cookie))
.Throws(new InvalidOperationException());
var tracker = new DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
var tracker = new VisualStudioFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);
// Act & Assert
tracker.StopListening();
@ -107,7 +106,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
fileChangeService
.Setup(f => f.AdviseFileChange(It.IsAny<string>(), It.IsAny<uint>(), It.IsAny<IVsFileChangeEvents>(), out cookie))
.Returns(VSConstants.S_OK);
var tracker = new DefaultFileChangeTracker(filePath, Dispatcher, ErrorReporter, fileChangeService.Object);
var tracker = new VisualStudioFileChangeTracker(filePath, Dispatcher, ErrorReporter, fileChangeService.Object);
var called = false;
tracker.Changed += (sender, args) =>

View File

@ -1,16 +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 System;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using MonoDevelop.Core;
using Moq;
using Xunit;
namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
public class DefaultFileChangeTrackerTest : ForegroundDispatcherTestBase
public class VisualStudioMacFileChangeTrackerTest : ForegroundDispatcherTestBase
{
[ForegroundFact]
public void StartListening_AdvisesForFileChange()
@ -69,7 +65,7 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor
Assert.Equal(0, tracker.DetachFromFileServiceEventsCount);
}
private class TestFileChangeTracker : DefaultFileChangeTracker
private class TestFileChangeTracker : VisualStudioMacFileChangeTracker
{
public TestFileChangeTracker(
string filePath,