diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs index 6be7e06fa9..7ceda03678 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultRazorDocumentManager.cs @@ -17,13 +17,11 @@ namespace Microsoft.VisualStudio.Editor.Razor { private readonly ForegroundDispatcher _foregroundDispatcher; private readonly RazorEditorFactoryService _editorFactoryService; - private readonly TextBufferProjectService _projectService; [ImportingConstructor] public DefaultRazorDocumentManager( ForegroundDispatcher dispatcher, - RazorEditorFactoryService editorFactoryService, - TextBufferProjectService projectService) + RazorEditorFactoryService editorFactoryService) { if (dispatcher == null) { @@ -35,14 +33,8 @@ namespace Microsoft.VisualStudio.Editor.Razor throw new ArgumentNullException(nameof(editorFactoryService)); } - if (projectService == null) - { - throw new ArgumentNullException(nameof(projectService)); - } - _foregroundDispatcher = dispatcher; _editorFactoryService = editorFactoryService; - _projectService = projectService; } public override void OnTextViewOpened(ITextView textView, IEnumerable subjectBuffers) @@ -66,11 +58,6 @@ namespace Microsoft.VisualStudio.Editor.Razor continue; } - if (!IsSupportedProject(textBuffer)) - { - return; - } - if (!_editorFactoryService.TryGetDocumentTracker(textBuffer, out var documentTracker) || !(documentTracker is DefaultVisualStudioDocumentTracker tracker)) { @@ -120,25 +107,5 @@ namespace Microsoft.VisualStudio.Editor.Razor } } } - - private bool IsSupportedProject(ITextBuffer textBuffer) - { - // Fundamentally we have a Razor half of the world as soon as the document is open - and then later - // the C# half of the world will be initialized. This code is in general pretty tolerant of - // unexpected /impossible states. - // - // We also want to successfully shut down if the buffer is something other than .cshtml. - object project = null; - var isSupportedProject = false; - - // We expect the document to have a hierarchy even if it's not a real 'project'. - // However the hierarchy can be null when the document is in the process of closing. - if ((project = _projectService.GetHostProject(textBuffer)) != null) - { - isSupportedProject = _projectService.IsSupportedProject(project); - } - - return isSupportedProject; - } } } diff --git a/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultRazorDocumentManagerTest.cs b/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultRazorDocumentManagerTest.cs index 3cd9f5fb81..32ec4b10c7 100644 --- a/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultRazorDocumentManagerTest.cs +++ b/test/Microsoft.VisualStudio.Editor.Razor.Test/DefaultRazorDocumentManagerTest.cs @@ -33,35 +33,12 @@ namespace Microsoft.VisualStudio.Editor.Razor private Workspace Workspace => TestWorkspace.Create(); - private TextBufferProjectService SupportedProjectService { get; } = Mock.Of( - s => s.GetHostProject(It.IsAny()) == Mock.Of() && - s.IsSupportedProject(It.IsAny()) == true && - s.GetProjectPath(It.IsAny()) == "C:/Some/Path/TestProject.csproj"); - - private TextBufferProjectService UnsupportedProjectService { get; } = Mock.Of(s => s.IsSupportedProject(It.IsAny()) == false); - - [ForegroundFact] - public void OnTextViewOpened_ForNonRazorCoreProject_DoesNothing() - { - // Arrange - var editorFactoryService = new Mock(MockBehavior.Strict); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService.Object, UnsupportedProjectService); - var textView = Mock.Of(); - var buffers = new Collection() - { - Mock.Of(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection()), - }; - - // Act & Assert - documentManager.OnTextViewOpened(textView, buffers); - } - [ForegroundFact] public void OnTextViewOpened_ForNonRazorTextBuffer_DoesNothing() { // Arrange var editorFactoryService = new Mock(MockBehavior.Strict); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService.Object, SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService.Object); var textView = Mock.Of(); var buffers = new Collection() { @@ -83,7 +60,7 @@ namespace Microsoft.VisualStudio.Editor.Razor }; var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[0], ImportDocumentManager) as VisualStudioDocumentTracker; var editorFactoryService = Mock.Of(factoryService => factoryService.TryGetDocumentTracker(It.IsAny(), out documentTracker) == true); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService, SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Act documentManager.OnTextViewOpened(textView, buffers); @@ -104,7 +81,7 @@ namespace Microsoft.VisualStudio.Editor.Razor }; var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[0], ImportDocumentManager) as VisualStudioDocumentTracker; var editorFactoryService = Mock.Of(f => f.TryGetDocumentTracker(It.IsAny(), out documentTracker) == true); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService, SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Assert 1 Assert.False(documentTracker.IsSupportedProject); @@ -116,29 +93,11 @@ namespace Microsoft.VisualStudio.Editor.Razor Assert.True(documentTracker.IsSupportedProject); } - [ForegroundFact] - public void OnTextViewClosed_FoNonRazorCoreProject_DoesNothing() - { - // Arrange - var documentManager = new DefaultRazorDocumentManager(Dispatcher, Mock.Of(), UnsupportedProjectService); - var textView = Mock.Of(); - var buffers = new Collection() - { - Mock.Of(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection()), - }; - - // Act - documentManager.OnTextViewClosed(textView, buffers); - - // Assert - Assert.False(buffers[0].Properties.ContainsProperty(typeof(VisualStudioDocumentTracker))); - } - [ForegroundFact] public void OnTextViewClosed_TextViewWithoutDocumentTracker_DoesNothing() { // Arrange - var documentManager = new DefaultRazorDocumentManager(Dispatcher, Mock.Of(), SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, Mock.Of()); var textView = Mock.Of(); var buffers = new Collection() { @@ -176,7 +135,7 @@ namespace Microsoft.VisualStudio.Editor.Razor buffers[1].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker); var editorFactoryService = Mock.Of(); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService, SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Act documentManager.OnTextViewClosed(textView2, buffers); @@ -203,7 +162,7 @@ namespace Microsoft.VisualStudio.Editor.Razor var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[0], ImportDocumentManager); buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker); var editorFactoryService = Mock.Of(); - var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService, SupportedProjectService); + var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Populate the text views documentTracker.Subscribe();