Exemplo n.º 1
0
        private void ProjectManager_Changed(object sender, ProjectChangeEventArgs e)
        {
            switch (e.Kind)
            {
            case ProjectChangeKind.ProjectAdded:
            {
                var projectSnapshot = _projectManager.GetLoadedProject(e.ProjectFilePath);
                foreach (var documentFilePath in projectSnapshot.DocumentFilePaths)
                {
                    Enqueue(projectSnapshot, projectSnapshot.GetDocument(documentFilePath));
                }

                break;
            }

            case ProjectChangeKind.ProjectChanged:
            {
                var projectSnapshot = _projectManager.GetLoadedProject(e.ProjectFilePath);
                foreach (var documentFilePath in projectSnapshot.DocumentFilePaths)
                {
                    Enqueue(projectSnapshot, projectSnapshot.GetDocument(documentFilePath));
                }

                break;
            }

            case ProjectChangeKind.DocumentAdded:
            {
                var project = _projectManager.GetLoadedProject(e.ProjectFilePath);
                Enqueue(project, project.GetDocument(e.DocumentFilePath));

                break;
            }

            case ProjectChangeKind.DocumentChanged:
            {
                var project = _projectManager.GetLoadedProject(e.ProjectFilePath);
                Enqueue(project, project.GetDocument(e.DocumentFilePath));

                break;
            }

            case ProjectChangeKind.ProjectRemoved:
            case ProjectChangeKind.DocumentRemoved:
            {
                // ignore
                break;
            }

            default:
                throw new InvalidOperationException($"Unknown ProjectChangeKind {e.Kind}");
            }
        }
        internal Task HandleEndBuildAsync(BuildEventArgs args)
        {
            if (!args.Success)
            {
                // Build failed
                return(Task.CompletedTask);
            }

            return(_projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync((projectItem, ct) =>
            {
                if (!_projectService.IsSupportedProject(projectItem))
                {
                    // We're hooked into all build events, it's possible to get called with an unsupported project item type.
                    return;
                }

                var projectPath = _projectService.GetProjectPath(projectItem);
                var projectSnapshot = _projectManager.GetLoadedProject(projectPath);
                if (projectSnapshot != null)
                {
                    var workspaceProject = _projectManager.Workspace.CurrentSolution?.Projects.FirstOrDefault(
                        project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));
                    if (workspaceProject != null)
                    {
                        // Trigger a tag helper update by forcing the project manager to see the workspace Project
                        // from the current solution.
                        _workspaceStateGenerator.Update(workspaceProject, projectSnapshot, CancellationToken.None);
                    }
                }
            }, args.SolutionItem, CancellationToken.None));
        }
        // 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 projectPath = _projectService.GetProjectPath(pHierProj);
            var project     = _projectManager.GetLoadedProject(projectPath);

            if (project != null && project.WorkspaceProject != null)
            {
                var workspaceProject = _projectManager.Workspace.CurrentSolution.GetProject(project.WorkspaceProject.Id);
                if (workspaceProject != null)
                {
                    // Trigger a tag helper update by forcing the project manager to see the workspace Project
                    // from the current solution.
                    _projectManager.WorkspaceProjectChanged(workspaceProject);
                }
            }

            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 projectPath     = _projectService.GetProjectPath(pHierProj);
            var projectSnapshot = _projectManager.GetLoadedProject(projectPath);

            if (projectSnapshot != null)
            {
                var workspaceProject = _projectManager.Workspace.CurrentSolution.Projects.FirstOrDefault(
                    wp => FilePathComparer.Instance.Equals(wp.FilePath, projectSnapshot.FilePath));
                if (workspaceProject != null)
                {
                    // Trigger a tag helper update by forcing the project manager to see the workspace Project
                    // from the current solution.
                    _workspaceStateGenerator.Update(workspaceProject, projectSnapshot, CancellationToken.None);
                }
            }

            return(VSConstants.S_OK);
        }
        internal Task OnProjectBuiltAsync(IVsHierarchy projectHierarchy, CancellationToken cancellationToken)
        {
            var projectFilePath = _projectService.GetProjectPath(projectHierarchy);

            return(_projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
            {
                var projectSnapshot = _projectManager.GetLoadedProject(projectFilePath);
                if (projectSnapshot != null)
                {
                    var workspaceProject = _projectManager.Workspace.CurrentSolution.Projects.FirstOrDefault(
                        wp => FilePathComparer.Instance.Equals(wp.FilePath, projectSnapshot.FilePath));
                    if (workspaceProject != null)
                    {
                        // Trigger a tag helper update by forcing the project manager to see the workspace Project
                        // from the current solution.
                        _workspaceStateGenerator.Update(workspaceProject, projectSnapshot, cancellationToken);
                    }
                }
            }, cancellationToken));
        }
        // Internal for testing
        internal void ProjectOperations_EndBuild(object sender, BuildEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            _foregroundDispatcher.AssertForegroundThread();

            if (!args.Success)
            {
                // Build failed
                return;
            }

            var projectItem = args.SolutionItem;

            if (!_projectService.IsSupportedProject(projectItem))
            {
                // We're hooked into all build events, it's possible to get called with an unsupported project item type.
                return;
            }

            var projectPath     = _projectService.GetProjectPath(projectItem);
            var projectSnapshot = _projectManager.GetLoadedProject(projectPath);

            if (projectSnapshot != null)
            {
                var workspaceProject = _projectManager.Workspace.CurrentSolution?.Projects.FirstOrDefault(
                    project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));
                if (workspaceProject != null)
                {
                    // Trigger a tag helper update by forcing the project manager to see the workspace Project
                    // from the current solution.
                    _workspaceStateGenerator.Update(workspaceProject, projectSnapshot);
                }
            }
        }
Exemplo n.º 7
0
        private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
        {
            _foregroundDispatcher.AssertForegroundThread();

            switch (args.Kind)
            {
            case ProjectChangeKind.ProjectAdded:
            {
                var projectSnapshot = _projectManager.GetLoadedProject(args.ProjectFilePath);
                foreach (var documentFilePath in projectSnapshot.DocumentFilePaths)
                {
                    if (_projectManager.IsDocumentOpen(documentFilePath))
                    {
                        var document = projectSnapshot.GetDocument(documentFilePath);
                        Enqueue(document);
                    }
                }

                break;
            }

            case ProjectChangeKind.ProjectChanged:
            {
                var projectSnapshot = _projectManager.GetLoadedProject(args.ProjectFilePath);
                foreach (var documentFilePath in projectSnapshot.DocumentFilePaths)
                {
                    if (_projectManager.IsDocumentOpen(documentFilePath))
                    {
                        var document = projectSnapshot.GetDocument(documentFilePath);
                        Enqueue(document);
                    }
                }

                break;
            }

            case ProjectChangeKind.DocumentAdded:
            {
                var project = _projectManager.GetLoadedProject(args.ProjectFilePath);
                if (_projectManager.IsDocumentOpen(args.DocumentFilePath))
                {
                    var document = project.GetDocument(args.DocumentFilePath);
                    Enqueue(document);
                }

                break;
            }

            case ProjectChangeKind.DocumentChanged:
            {
                var project = _projectManager.GetLoadedProject(args.ProjectFilePath);
                if (_projectManager.IsDocumentOpen(args.DocumentFilePath))
                {
                    var document = project.GetDocument(args.DocumentFilePath);
                    Enqueue(document);
                }

                break;
            }

            case ProjectChangeKind.ProjectRemoved:
            case ProjectChangeKind.DocumentRemoved:
            {
                // ignore
                break;
            }

            default:
                throw new InvalidOperationException($"Unknown ProjectChangeKind {args.Kind}");
            }
        }