Exemple #1
0
        public void UpdateGuestProjectManager_ProjectChanged_ConfigurationChange()
        {
            // Arrange
            var oldHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                projectWorkspaceState: null);
            var newConfiguration = RazorConfiguration.Create(RazorLanguageVersion.Version_1_0, "Custom-1.0", Enumerable.Empty <RazorExtension>());
            var newHandle        = new ProjectSnapshotHandleProxy(
                oldHandle.FilePath,
                newConfiguration,
                oldHandle.RootNamespace,
                oldHandle.ProjectWorkspaceState);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default, "project");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectConfigurationChanged(hostProject);
            var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(newConfiguration, project.Configuration);
            Assert.Empty(project.TagHelpers);
        }
        public async Task ProjectAdded_DoesNotPublishWithoutProjectWorkspaceStateAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.True(false, "Serialization should not have been atempted because there is no ProjectWorkspaceState.");
                serializationSuccessful = true;
            })
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);

            // Act
            await RunOnForegroundAsync(() => ProjectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);

            Assert.Empty(publisher._deferredPublishTasks);

            // Assert
            Assert.False(serializationSuccessful);
        }
Exemple #3
0
        // This is only for testing. We want to avoid using the actual Roslyn GetService methods in unit tests.
        internal DefaultVisualStudioDocumentTrackerFactory(
            ForegroundDispatcher foregroundDispatcher,
            ProjectSnapshotManager projectManager,
            TextBufferProjectService projectService,
            [Import(typeof(VisualStudioWorkspace))] Workspace workspace)
        {
            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (projectService == null)
            {
                throw new ArgumentNullException(nameof(projectService));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            _foregroundDispatcher = foregroundDispatcher;
            _projectManager       = projectManager;
            _projectService       = projectService;
            _workspace            = workspace;
        }
        public DefaultVisualStudioDocumentTrackerFactory(
            TextBufferProjectService projectService,
            ITextDocumentFactoryService textDocumentFactory,
            VisualStudioWorkspaceAccessor workspaceAccessor,
            ImportDocumentManager importDocumentManager)
        {
            if (projectService == null)
            {
                throw new ArgumentNullException(nameof(projectService));
            }

            if (textDocumentFactory == null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

            if (workspaceAccessor == null)
            {
                throw new ArgumentNullException(nameof(workspaceAccessor));
            }

            _projectService        = projectService;
            _textDocumentFactory   = textDocumentFactory;
            _workspace             = workspaceAccessor.Workspace;
            _importDocumentManager = importDocumentManager;

            _foregroundDispatcher = _workspace.Services.GetRequiredService <ForegroundDispatcher>();
            var razorLanguageServices = _workspace.Services.GetLanguageServices(RazorLanguage.Name);

            _projectManager        = razorLanguageServices.GetRequiredService <ProjectSnapshotManager>();
            _editorSettingsManager = razorLanguageServices.GetRequiredService <EditorSettingsManagerInternal>();
        }
Exemple #5
0
 public DefaultRazorComponentSearchEngine(
     ForegroundDispatcher foregroundDispatcher,
     ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor)
 {
     _foregroundDispatcher   = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
     _projectSnapshotManager = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
 }
        public void ProjectManager_Changed_DocumentOpened_UninitializedProject_NotActive_Noops()
        {
            // Arrange
            var attemptedToSerialize = false;
            var hostProject          = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument         = new HostDocument("/path/to/file.razor", "file.razor");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
            {
                EnqueueDelay = 10,
            };

            publisher.Initialize(ProjectSnapshotManager);

            // Act
            ProjectSnapshotManager.DocumentOpened(hostProject.FilePath, hostDocument.FilePath, SourceText.From(string.Empty));

            // Assert
            Assert.Empty(publisher._deferredPublishTasks);
            Assert.False(attemptedToSerialize);
        }
Exemple #7
0
        public async Task ProjectAdded_PublishesToCorrectFilePathAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                _razorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            })
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var projectFilePath = "/path/to/project.csproj";
            var hostProject     = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);
            var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default);

            // Act
            await RunOnDispatcherThreadAsync(() =>
            {
                ProjectSnapshotManager.ProjectAdded(hostProject);
                ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState);
            }).ConfigureAwait(false);

            // Assert
            Assert.True(serializationSuccessful);
        }
Exemple #8
0
        public void UpdateGuestProjectManager_ProjectChanged_ProjectWorkspaceStateChange()
        {
            // Arrange
            var oldHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                ProjectWorkspaceState.Default);
            var newProjectWorkspaceState = ProjectWorkspaceStateWithTagHelpers;
            var newHandle = new ProjectSnapshotHandleProxy(
                oldHandle.FilePath,
                oldHandle.Configuration,
                oldHandle.RootNamespace,
                newProjectWorkspaceState);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default, "project");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, oldHandle.ProjectWorkspaceState);
            var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(RazorConfiguration.Default, project.Configuration);
            Assert.Same(newProjectWorkspaceState.TagHelpers, project.TagHelpers);
        }
Exemple #9
0
        private ProjectSnapshot FindProjectByDirectory(string directory)
        {
            directory = NormalizeDirectoryPath(directory);

            if (_projectManager == null)
            {
                _projectManager = _workspace.Services.GetLanguageServices(RazorLanguage.Name).GetRequiredService <ProjectSnapshotManager>();
            }

            var projects = _projectManager.Projects;

            for (var i = 0; i < projects.Count; i++)
            {
                var project = projects[i];
                if (project.FilePath != null)
                {
                    if (string.Equals(directory, NormalizeDirectoryPath(Path.GetDirectoryName(project.FilePath)), StringComparison.OrdinalIgnoreCase))
                    {
                        return(project);
                    }
                }
            }

            return(null);
        }
Exemple #10
0
        public DefaultVisualStudioDocumentTracker(
            ProjectSnapshotManager projectManager,
            TextBufferProjectService projectService,
            Workspace workspace,
            ITextBuffer textBuffer)
        {
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (projectService == null)
            {
                throw new ArgumentNullException(nameof(projectService));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            _projectManager = projectManager;
            _projectService = projectService;
            _textBuffer     = textBuffer;
            _workspace      = workspace; // For now we assume that the workspace is the always default VS workspace.

            _textViews = new List <ITextView>();
        }
        public DefaultProjectSnapshotManagerProxy(
            CollaborationSession session,
            ForegroundDispatcher foregroundDispatcher,
            ProjectSnapshotManager projectSnapshotManager,
            JoinableTaskFactory joinableTaskFactory)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (projectSnapshotManager == null)
            {
                throw new ArgumentNullException(nameof(projectSnapshotManager));
            }

            if (joinableTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(joinableTaskFactory));
            }

            _session = session;
            _foregroundDispatcher   = foregroundDispatcher;
            _projectSnapshotManager = projectSnapshotManager;
            _joinableTaskFactory    = joinableTaskFactory;

            _latestStateSemaphore            = new AsyncSemaphore(initialCount: 1);
            _projectSnapshotManager.Changed += ProjectSnapshotManager_Changed;
        }
Exemple #12
0
        public async Task ProjectAdded_DoesNotFireWhenNotReadyAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json";

            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            },
                shouldSerialize: false)
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var projectFilePath = @"C:\path\to\project.csproj";
            var hostProject     = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);
            var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default);

            // Act
            await RunOnDispatcherThreadAsync(() =>
            {
                ProjectSnapshotManager.ProjectAdded(hostProject);
                ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState);
            }).ConfigureAwait(false);

            // Assert
            Assert.False(serializationSuccessful);
        }
        public void ProjectManager_Changed_DocumentOpened_InitializedProject_NotActive_Publishes()
        {
            // Arrange
            var serializationSuccessful = false;
            var hostProject             = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument            = new HostDocument("/path/to/file.razor", "file.razor");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, ProjectWorkspaceState.Default);
            ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
            var projectSnapshot = ProjectSnapshotManager.Projects[0];
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath);
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            })
            {
                EnqueueDelay = 10,
            };

            publisher.Initialize(ProjectSnapshotManager);

            // Act
            ProjectSnapshotManager.DocumentOpened(hostProject.FilePath, hostDocument.FilePath, SourceText.From(string.Empty));

            // Assert
            Assert.Empty(publisher._deferredPublishTasks);
            Assert.True(serializationSuccessful);
        }
        internal DocumentItemViewModel(ProjectSnapshotManager snapshotManager, DocumentSnapshot document, Action <Exception> errorHandler)
        {
            _snapshotManager = snapshotManager;
            _document        = document;
            _errorHandler    = errorHandler;

            InitializeGeneratedDocument();
        }
        private DocumentSnapshot UpdateDocument(string filePath, SourceText sourceText)
        {
            ProjectSnapshotManager.DocumentChanged(HostProject.FilePath, filePath, sourceText);
            var project  = ProjectSnapshotManager.GetLoadedProject(HostProject.FilePath);
            var document = project.GetDocument(filePath);

            return(document);
        }
        public RazorInfoViewModel(Workspace workspace, ProjectSnapshotManager projectManager, Action <Exception> errorHandler)
        {
            _workspace      = workspace;
            _projectManager = projectManager;
            _errorHandler   = errorHandler;

            UpdateCommand = new RelayCommand <object>(ExecuteUpdate, CanExecuteUpdate);
        }
        public DefaultTemplateEngineFactoryService(ProjectSnapshotManager projectManager)
        {
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            _projectManager = projectManager;
        }
Exemple #18
0
        public override void Initialize(ProjectSnapshotManager projectManager)
        {
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            _projectManager = projectManager;
        }
 public RazorComponentRenameEndpoint(
     ForegroundDispatcher foregroundDispatcher,
     DocumentResolver documentResolver,
     RazorComponentSearchEngine componentSearchEngine,
     ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor)
 {
     _foregroundDispatcher   = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
     _documentResolver       = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
     _componentSearchEngine  = componentSearchEngine ?? throw new ArgumentNullException(nameof(componentSearchEngine));
     _projectSnapshotManager = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
 }
Exemple #20
0
        public DefaultVisualStudioDocumentTracker(
            string filePath,
            string projectPath,
            ProjectSnapshotManager projectManager,
            EditorSettingsManagerInternal editorSettingsManager,
            Workspace workspace,
            ITextBuffer textBuffer,
            ImportDocumentManager importDocumentManager)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath));
            }

            if (projectPath == null)
            {
                throw new ArgumentNullException(nameof(projectPath));
            }

            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (editorSettingsManager == null)
            {
                throw new ArgumentNullException(nameof(editorSettingsManager));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (importDocumentManager == null)
            {
                throw new ArgumentNullException(nameof(importDocumentManager));
            }

            _filePath              = filePath;
            _projectPath           = projectPath;
            _projectManager        = projectManager;
            _editorSettingsManager = editorSettingsManager;
            _textBuffer            = textBuffer;
            _importDocumentManager = importDocumentManager;
            _workspace             = workspace; // For now we assume that the workspace is the always default VS workspace.

            _textViews = new List <ITextView>();
        }
Exemple #21
0
        public DefaultVisualStudioDocumentTrackerFactory(
            ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
            JoinableTaskContext joinableTaskContext,
            ProjectSnapshotManager projectManager,
            WorkspaceEditorSettings workspaceEditorSettings,
            ProjectPathProvider projectPathProvider,
            ITextDocumentFactoryService textDocumentFactory,
            ImportDocumentManager importDocumentManager,
            Workspace workspace)
        {
            if (projectSnapshotManagerDispatcher is null)
            {
                throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
            }

            if (projectManager is null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (workspaceEditorSettings is null)
            {
                throw new ArgumentNullException(nameof(workspaceEditorSettings));
            }

            if (projectPathProvider is null)
            {
                throw new ArgumentNullException(nameof(projectPathProvider));
            }

            if (textDocumentFactory is null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

            if (importDocumentManager is null)
            {
                throw new ArgumentNullException(nameof(importDocumentManager));
            }

            if (workspace is null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
            _joinableTaskContext     = joinableTaskContext;
            _projectManager          = projectManager;
            _workspaceEditorSettings = workspaceEditorSettings;
            _projectPathProvider     = projectPathProvider;
            _textDocumentFactory     = textDocumentFactory;
            _importDocumentManager   = importDocumentManager;
            _workspace = workspace;
        }
        public DefaultVisualStudioDocumentTrackerFactory(
            ForegroundDispatcher foregroundDispatcher,
            ProjectSnapshotManager projectManager,
            WorkspaceEditorSettings workspaceEditorSettings,
            ProjectPathProvider projectPathProvider,
            ITextDocumentFactoryService textDocumentFactory,
            ImportDocumentManager importDocumentManager,
            Workspace workspace)
        {
            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (workspaceEditorSettings == null)
            {
                throw new ArgumentNullException(nameof(workspaceEditorSettings));
            }

            if (projectPathProvider == null)
            {
                throw new ArgumentNullException(nameof(projectPathProvider));
            }

            if (textDocumentFactory == null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

            if (importDocumentManager == null)
            {
                throw new ArgumentNullException(nameof(importDocumentManager));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            _foregroundDispatcher    = foregroundDispatcher;
            _projectManager          = projectManager;
            _workspaceEditorSettings = workspaceEditorSettings;
            _projectPathProvider     = projectPathProvider;
            _textDocumentFactory     = textDocumentFactory;
            _importDocumentManager   = importDocumentManager;
            _workspace = workspace;
        }
Exemple #23
0
        public DefaultVisualStudioDocumentTrackerFactory(
            ForegroundDispatcher foregroundDispatcher,
            ProjectSnapshotManager projectManager,
            EditorSettingsManagerInternal editorSettingsManager,
            TextBufferProjectService projectService,
            ITextDocumentFactoryService textDocumentFactory,
            ImportDocumentManager importDocumentManager,
            Workspace workspace)
        {
            if (foregroundDispatcher == null)
            {
                throw new ArgumentNullException(nameof(foregroundDispatcher));
            }

            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            if (editorSettingsManager == null)
            {
                throw new ArgumentNullException(nameof(editorSettingsManager));
            }

            if (projectService == null)
            {
                throw new ArgumentNullException(nameof(projectService));
            }

            if (textDocumentFactory == null)
            {
                throw new ArgumentNullException(nameof(textDocumentFactory));
            }

            if (importDocumentManager == null)
            {
                throw new ArgumentNullException(nameof(importDocumentManager));
            }

            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            _foregroundDispatcher  = foregroundDispatcher;
            _projectManager        = projectManager;
            _editorSettingsManager = editorSettingsManager;
            _projectService        = projectService;
            _textDocumentFactory   = textDocumentFactory;
            _importDocumentManager = importDocumentManager;
            _workspace             = workspace;
        }
Exemple #24
0
 public RazorComponentRenameEndpoint(
     ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
     DocumentResolver documentResolver,
     RazorComponentSearchEngine componentSearchEngine,
     ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor,
     LanguageServerFeatureOptions languageServerFeatureOptions)
 {
     _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
     _documentResolver             = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
     _componentSearchEngine        = componentSearchEngine ?? throw new ArgumentNullException(nameof(componentSearchEngine));
     _projectSnapshotManager       = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
     _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
 }
        internal DocumentCollectionViewModel(ProjectSnapshotManager projectManager, ProjectSnapshot project, Action <Exception> errorHandler)
        {
            _projectManager = projectManager;
            _project        = project;
            _errorHandler   = errorHandler;

            Documents = new ObservableCollection <DocumentItemViewModel>();

            foreach (var filePath in project.DocumentFilePaths)
            {
                Documents.Add(new DocumentItemViewModel(projectManager, project.GetDocument(filePath), _errorHandler));
            }
        }
Exemple #26
0
        public DefaultRazorComponentSearchEngine(
            ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
            ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor,
            ILoggerFactory loggerFactory)
        {
            if (loggerFactory is null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
            _projectSnapshotManager           = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
            _logger = loggerFactory.CreateLogger <DefaultRazorComponentSearchEngine>();
        }
        public async Task UpdateLSPFileInfo_SolutionClosing_ClearsAllDocuments()
        {
            // Arrange
            await TestAccessor.GetDynamicFileInfoAsync(Project.FilePath, Document1.FilePath, CancellationToken.None).ConfigureAwait(false);

            await TestAccessor.GetDynamicFileInfoAsync(Project.FilePath, Document2.FilePath, CancellationToken.None).ConfigureAwait(false);

            Provider.Updated += (sender, documentFilePath) => throw new InvalidOperationException("Should not have been called!");

            ProjectSnapshotManager.SolutionClosed();
            ProjectSnapshotManager.DocumentClosed(Project.FilePath, Document1.FilePath, new EmptyTextLoader(string.Empty));

            // Act & Assert
            Provider.UpdateLSPFileInfo(new Uri(Document2.FilePath), LSPDocumentContainer);
            Provider.UpdateLSPFileInfo(new Uri(Document1.FilePath), LSPDocumentContainer);
        }
        public async Task UpdateLSPFileInfo_DocumentRemoved_Noops()
        {
            // Arrange
            await TestAccessor.GetDynamicFileInfoAsync(Project.FilePath, Document1.FilePath, CancellationToken.None).ConfigureAwait(false);

            var called = false;

            Provider.Updated += (sender, args) => called = true;
            ProjectSnapshotManager.DocumentRemoved(Project.HostProject, Document1.State.HostDocument);

            // Act
            Provider.UpdateLSPFileInfo(new Uri(Document1.FilePath), LSPDocumentContainer);

            // Assert
            Assert.False(called);
        }
Exemple #29
0
        public async Task ProjectRemoved_UnSetPublishFilePath_NoopsAsync()
        {
            // Arrange
            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore)
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var hostProject = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            await RunOnDispatcherThreadAsync(() => ProjectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);

            // Act & Assert
            await RunOnDispatcherThreadAsync(() => ProjectSnapshotManager.ProjectRemoved(hostProject)).ConfigureAwait(false);

            Assert.Empty(publisher.DeferredPublishTasks);
        }
        public async Task ProjectRemoved_UnSetPublishFilePath_NoopsAsync()
        {
            // Arrange
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger)
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            await RunOnForegroundAsync(() => ProjectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);

            // Act & Assert
            await RunOnForegroundAsync(() => ProjectSnapshotManager.ProjectRemoved(hostProject)).ConfigureAwait(false);

            Assert.Empty(publisher._deferredPublishTasks);
        }