Skip to content

Commit

Permalink
DEV2-3893 filter unwanted workspace root paths (#691)
Browse files Browse the repository at this point in the history
* DEV2-3893 filter unwanted workspace root paths

* fix

* fix

* add tests
  • Loading branch information
yonip23 authored Nov 20, 2023
1 parent 02f6279 commit f640f00
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.util.concurrency.AppExecutorUtil
import com.tabnineCommon.binary.requests.fileLifecycle.Workspace
import com.tabnineCommon.general.DependencyContainer
import java.io.File
import java.net.URL
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -57,10 +58,22 @@ class WorkspaceListenerService {
Logger.getInstance(javaClass).debug("$url in project ${project.name} has unsupported protocol (${url.protocol})")
continue
}
if (File(url.path).list()?.isEmpty() != false) {
Logger.getInstance(javaClass).debug("${url.path} in project ${project.name} is empty, skipping")
continue
}
rootPaths.add(url.path)
}

Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $rootPaths")
return rootPaths
val dedupedRootPaths = dedupRootPaths(rootPaths)

Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $dedupedRootPaths")
return dedupedRootPaths
}

companion object {
fun dedupRootPaths(rootPaths: List<String>): List<String> {
return rootPaths.filter { path1 -> rootPaths.none { path2 -> path1 != path2 && path1.startsWith(path2) } }
}
}
}
25 changes: 25 additions & 0 deletions Common/src/test/kotlin/WorkspaceListenerDedupPathsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import com.tabnineCommon.lifecycle.WorkspaceListenerService
import org.junit.Test

class WorkspaceListenerDedupPathsTest {
@Test
fun shouldNotDedupDisjointPaths() {
val rootPaths = listOf("/path1", "/path2", "/path3")
val dedupedPaths = WorkspaceListenerService.Companion.dedupRootPaths(rootPaths)
assert(dedupedPaths == rootPaths)
}

@Test
fun shouldNotDedupDifferentPaths() {
val rootPaths = listOf("/root/path1", "/root/path2", "/root/path3")
val dedupedPaths = WorkspaceListenerService.Companion.dedupRootPaths(rootPaths)
assert(dedupedPaths == rootPaths)
}

@Test
fun shouldDedupSubPaths() {
val rootPaths = listOf("/root/path1", "/root/path1/path2", "/root/path3")
val dedupedPaths = WorkspaceListenerService.Companion.dedupRootPaths(rootPaths)
assert(dedupedPaths == listOf("/root/path1", "/root/path3"))
}
}

0 comments on commit f640f00

Please sign in to comment.