Skip to content

Commit

Permalink
Trying to workaround "unsynced" case for newly added files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkashyn-sfdc committed Sep 13, 2023
1 parent c6a848f commit 41dc01e
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.project.Project;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -79,6 +81,35 @@ public SyncStatus getSyncStatus(File source) {
return syncedTargets.stream().anyMatch(t -> syncInProgress(t.getLabel()))
? SyncStatus.RESYNCING
: SyncStatus.SYNCED;
} else {
// For newly added files there is no way to have them synced even though they are, in the majority of cases, are
// identical to the rest of files in the folder.
// So we are checking 5 other files from the same folder and if TargetKey collection is the same for all
// then we are using the same for file that marked as `(unsynced)`.
List<ImmutableCollection<TargetKey>> alternativeSources =
Arrays.stream(source.getParentFile().listFiles())
.filter(f -> f.isFile() && !SourceToTargetMap.getInstance(project).getRulesForSourceFile(f).isEmpty())
.limit(5)
.map(f -> SourceToTargetMap.getInstance(project).getRulesForSourceFile(f))
.toList();
ImmutableCollection<TargetKey> consensusSource = null;
for (ImmutableCollection<TargetKey> alternativeSource : alternativeSources) {
if (consensusSource == null) {
consensusSource = alternativeSource;
} else {
// If at least one is different we cannot use this approach.
if (!alternativeSource.equals(consensusSource)) {
consensusSource = null;
break;
}
}
}
if (consensusSource != null && !consensusSource.isEmpty()) {
return consensusSource.stream().anyMatch(t -> syncInProgress(t.getLabel()))
? SyncStatus.RESYNCING
: SyncStatus.SYNCED;

}
}
Label label = WorkspaceHelper.getBuildLabel(project, source);
if (label == null) {
Expand Down

0 comments on commit 41dc01e

Please sign in to comment.