MCPcopy Create free account
hub / github.com/microsoft/typescript-go / computeSnapshotChanges

Function computeSnapshotChanges

internal/api/session.go:2804–2851  ·  view source on GitHub ↗

computeSnapshotChanges computes the per-project source file differences between two snapshots. It uses DiffOrderedMaps on projects to find changed/removed projects, then DiffMaps on FilesByPath for each changed project to collect file-level changes.

(prev *project.Snapshot, next *project.Snapshot)

Source from the content-addressed store, hash-verified

2802// two snapshots. It uses DiffOrderedMaps on projects to find changed/removed projects,
2803// then DiffMaps on FilesByPath for each changed project to collect file-level changes.
2804func computeSnapshotChanges(prev *project.Snapshot, next *project.Snapshot) *SnapshotChanges {
2805 prevProjects := prev.ProjectCollection.ProjectsByPath()
2806 nextProjects := next.ProjectCollection.ProjectsByPath()
2807
2808 var changes SnapshotChanges
2809
2810 collections.DiffOrderedMaps(
2811 prevProjects, nextProjects,
2812 // onAdded: new project — nothing to retain from previous snapshot.
2813 func(_ tspath.Path, _ *project.Project) {},
2814 // onRemoved: project removed entirely.
2815 func(_ tspath.Path, oldProj *project.Project) {
2816 changes.RemovedProjects = append(changes.RemovedProjects, ProjectHandle(oldProj))
2817 },
2818 // onModified: project changed, diff its files.
2819 func(_ tspath.Path, oldProj *project.Project, newProj *project.Project) {
2820 if oldProj.GetProgram() == newProj.GetProgram() {
2821 return
2822 }
2823 var oldFiles, newFiles map[tspath.Path]*ast.SourceFile
2824 if p := oldProj.GetProgram(); p != nil {
2825 oldFiles = p.FilesByPath()
2826 }
2827 if p := newProj.GetProgram(); p != nil {
2828 newFiles = p.FilesByPath()
2829 }
2830 var projectChanges ProjectFileChanges
2831 core.DiffMaps(
2832 oldFiles, newFiles,
2833 nil, // onAdded: new file in project, not a change.
2834 func(path tspath.Path, _ *ast.SourceFile) {
2835 projectChanges.DeletedFiles = append(projectChanges.DeletedFiles, path)
2836 },
2837 func(path tspath.Path, _ *ast.SourceFile, _ *ast.SourceFile) {
2838 projectChanges.ChangedFiles = append(projectChanges.ChangedFiles, path)
2839 },
2840 )
2841 if len(projectChanges.ChangedFiles) > 0 || len(projectChanges.DeletedFiles) > 0 {
2842 if changes.ChangedProjects == nil {
2843 changes.ChangedProjects = make(map[ProjectID]*ProjectFileChanges)
2844 }
2845 changes.ChangedProjects[ProjectHandle(newProj)] = &projectChanges
2846 }
2847 },
2848 )
2849
2850 return &changes
2851}
2852
2853// Close closes the session and releases all active snapshots,
2854// regardless of their ref counts.

Callers 1

handleUpdateSnapshotMethod · 0.85

Calls 9

DiffOrderedMapsFunction · 0.92
DiffMapsFunction · 0.92
lenFunction · 0.85
ProjectsByPathMethod · 0.80
FilesByPathMethod · 0.80
ProjectHandleFunction · 0.70
GetProgramMethod · 0.65
appendFunction · 0.50
makeFunction · 0.50

Tested by

no test coverage detected