Compare commits

...

2 Commits

Author SHA1 Message Date
chylex 2493fd01f1
Release 1.0.1 2022-06-16 20:10:28 +02:00
chylex 8055375330
Fix grouping files belonging to multiple projects under a random project
Closes #1
2022-06-16 20:06:27 +02:00
3 changed files with 50 additions and 3 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
group = "com.chylex.intellij.rider.vcsgroupbyproject"
version = "1.0.0"
version = "1.0.1"
repositories {
mavenCentral()

View File

@ -8,14 +8,20 @@ import com.intellij.openapi.vcs.changes.ui.ChangesBrowserNode
import com.intellij.openapi.vcs.changes.ui.ChangesGroupingPolicyFactory
import com.intellij.openapi.vcs.changes.ui.StaticFilePath
import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.vcsUtil.VcsUtil
import com.intellij.workspaceModel.ide.WorkspaceModel
import com.jetbrains.rider.model.RdCustomLocation
import com.jetbrains.rider.model.RdProjectDescriptor
import com.jetbrains.rider.model.RdProjectModelItemDescriptor
import com.jetbrains.rider.model.RdUnloadProjectDescriptor
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
import com.jetbrains.rider.projectView.workspace.containingEntity
import com.jetbrains.rider.projectView.workspace.containingProjectEntity
import com.jetbrains.rider.projectView.workspace.getProjectModelEntities
import com.jetbrains.rider.projectView.workspace.isProject
import com.jetbrains.rider.projectView.workspace.isProjectFile
import com.jetbrains.rider.projectView.workspace.isProjectFolder
import com.jetbrains.rider.projectView.workspace.isUnloadedProject
import java.io.File
import javax.swing.tree.DefaultTreeModel
@ -28,7 +34,7 @@ class ProjectChangesGroupingPolicy(private val project: Project, private val mod
return nextPolicyParent
}
val descriptor = file.containingEntity(project)?.let(ProjectModelEntity::containingProjectEntity)?.descriptor
val descriptor = getSingleProjectEntity(file, project)?.descriptor
if (descriptor !is RdProjectDescriptor && descriptor !is RdUnloadProjectDescriptor) {
return nextPolicyParent
}
@ -62,6 +68,41 @@ class ProjectChangesGroupingPolicy(private val project: Project, private val mod
mutableMapOf()
}
@Suppress("UnstableApiUsage")
private fun getSingleProjectEntity(file: VirtualFile, project: Project): ProjectModelEntity? {
val workspaceModel = WorkspaceModel.getInstance(project)
val entities = walkFileParentsUntilResultIsNotEmpty(file) { workspaceModel.getProjectModelEntities(it, project) }
if (entities == null) {
return null
}
return entities
.filter(::isProjectOrProjectFile)
.map(ProjectModelEntity::containingProjectEntity)
.toSet()
.singleOrNull()
}
private inline fun <T> walkFileParentsUntilResultIsNotEmpty(leafFile: VirtualFile, getValue: (VirtualFile) -> List<T>?): List<T>? {
var file: VirtualFile? = leafFile
while (file != null) {
val value = getValue(file)
if (value.isNullOrEmpty()) {
file = file.parent
}
else {
return value
}
}
return null
}
private fun isProjectOrProjectFile(entity: ProjectModelEntity): Boolean {
return entity.isProjectFile() || entity.isProjectFolder() || entity.isProject() || entity.isUnloadedProject()
}
private fun getFolder(descriptor: RdProjectModelItemDescriptor): FilePath? {
val location = descriptor.location
if (location !is RdCustomLocation) {

View File

@ -11,6 +11,12 @@
Click the 'Group By' icon in the panel's toolbar and select 'Project' to group files by project, or both 'Project' and 'Directory' to first group by project and then by directory.
]]></description>
<change-notes><![CDATA[
<ul>
<li>Fixed grouping files belonging to multiple projects under a random project.</li>
</ul>
]]></change-notes>
<depends>com.intellij.modules.rider</depends>
<extensions defaultExtensionNs="com.intellij">