Skip to content

Commit

Permalink
drop isListMerged in order to simplify code
Browse files Browse the repository at this point in the history
(cherry picked from commit 0d0c06c8e2fecc4576ea8649c9d44d88d99ec072)

IJ-CR-97764

GitOrigin-RevId: 35ba4fd8459345ea3b50c63e4d2a06d139bc65a0
  • Loading branch information
ArseniiCherniaev authored and intellij-monorepo-bot committed Nov 3, 2022
1 parent 01af8af commit d94bc25
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 135 deletions.
1 change: 0 additions & 1 deletion platform/util/resources/misc/registry.properties
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ debugger.auto.attach.from.console.description=Auto attach to all processes avail
debugger.preload.event.info=true
debugger.sync.commands.reschedule.delay=50
debugger.attach.dialog.enabled=false
debugger.attach.dialog.list.processes.merged=true
debugger.attach.dialog.enabled.description=Show new "Attach to Process" dialog instead of popup

execution.java.always.debug=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import com.intellij.execution.process.ProcessInfo
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.UserDataHolderBase
import com.intellij.util.containers.MultiMap
import com.intellij.xdebugger.attach.XAttachDebugger
import com.intellij.xdebugger.attach.XAttachDebuggerProvider
import com.intellij.xdebugger.attach.XAttachHost
import com.intellij.xdebugger.attach.XAttachPresentationGroup
Expand Down Expand Up @@ -68,64 +66,6 @@ internal suspend fun collectAttachProcessItemsGroupByProcessInfo(
}
}

internal suspend fun collectAttachProcessItems(project: Project,
host: XAttachHost,
attachDebuggerProviders: List<XAttachDebuggerProvider>): AttachItemsInfo {

return try {
val dataHolder = UserDataHolderBase()

val currentItems = mutableListOf<AttachToProcessItem>()
val dialogItems = mutableListOf<AttachDialogProcessItem>()

val applicableDebuggerProviders = attachDebuggerProviders.filter { it.isAttachHostApplicable(host) }
for (process in host.processList) {
coroutineContext.ensureActive()
val groupsWithDebuggers = MultiMap<XAttachPresentationGroup<ProcessInfo>, XAttachDebugger>()
for (provider in applicableDebuggerProviders) {
groupsWithDebuggers.putValues(provider.presentationGroup,
provider.getAvailableDebuggers(project, host, process!!, dataHolder))
}
for (group in groupsWithDebuggers.keySet()) {
val debuggers = groupsWithDebuggers[group]
if (!debuggers.isEmpty()) {
val attachToProcessItem = AttachToProcessItem(group, false, host, process!!, ArrayList(debuggers), project, dataHolder)
currentItems.add(attachToProcessItem)
dialogItems.add(attachToProcessItem.toDialogItem())
}
}
}

val recentItems = getRecentItems(currentItems, host, project, dataHolder)

AttachItemsInfo(dialogItems, recentItems, dataHolder)
}
catch (processesFetchingProblemException: ProcessesFetchingProblemException) {
throw processesFetchingProblemException
}
catch (cancellationException: CancellationException) {
throw cancellationException
}
catch (executionException: ExecutionException) {
AttachItemsInfo.EMPTY
}
catch (t: Throwable) {
logger.error(t)
AttachItemsInfo.EMPTY
}
}

private fun getRecentItems(currentItems: List<AttachToProcessItem>,
host: XAttachHost,
project: Project,
dataHolder: UserDataHolderBase): List<AttachDialogProcessItem> {
return AttachToProcessActionBase.getRecentItems(currentItems, host, project, dataHolder).groupBy { it.processInfo.pid }.map { groupedItems ->
val firstItem = groupedItems.value.first()
val processInfo = firstItem.processInfo
return@map AttachDialogProcessItem.create(processInfo, groupedItems.value.groupBy { it.group }, dataHolder)
}
}

private fun getRecentItems(currentItems: List<AttachToProcessItem>,
currentDialogItems: Map<ProcessInfo, AttachDialogProcessItem>,
host: XAttachHost,
Expand All @@ -143,7 +83,3 @@ private fun getRecentItems(currentItems: List<AttachToProcessItem>,
return@mapNotNull AttachDialogRecentItem(dialogItem, groupedItems.value.sortedBy { it.group.order }.flatMap { it.debuggers })
}
}

private fun AttachToProcessItem.toDialogItem(): AttachDialogProcessItem {
return AttachDialogProcessItem.create(processInfo, mapOf(group to listOf(this)), dataHolder)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.observable.properties.AtomicLazyProperty
import com.intellij.util.ui.JBUI
import com.intellij.xdebugger.impl.ui.attach.dialog.items.AttachToProcessItemsListBase
import com.intellij.xdebugger.impl.ui.attach.dialog.items.list.AttachListColumnSettingsState
import com.intellij.xdebugger.impl.ui.attach.dialog.items.tree.AttachTreeColumnSettingsState
import com.intellij.xdebugger.impl.ui.attach.dialog.statistics.AttachDialogStatisticsCollector

Expand All @@ -31,7 +30,7 @@ class AttachDialogState(val dialogDisposable: Disposable) {
val selectedDebuggersFilter = AtomicLazyProperty<AttachDialogDebuggersFilter> { AttachDialogAllDebuggersFilter }

val attachTreeColumnSettings = AttachTreeColumnSettingsState()
val attachListColumnSettings = if (isListMerged()) AttachTreeColumnSettingsState() else AttachListColumnSettingsState()
val attachListColumnSettings = AttachTreeColumnSettingsState()

val selectedViewType = AtomicLazyProperty { getDefaultView() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package com.intellij.xdebugger.impl.ui.attach.dialog

import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.registry.Registry
import com.intellij.util.ui.StartupUiUtil
import java.awt.Font
import java.awt.FontMetrics
import javax.swing.JComponent

private val logger = Logger.getInstance(AttachToProcessDialog::class.java)

fun isListMerged(): Boolean = Registry.`is`("debugger.attach.dialog.list.processes.merged")

fun getProcessName(textToTruncate: String, fontMetrics: FontMetrics, maxWidth: Int): @NlsSafe String {
if (textToTruncate.isEmpty()) return ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ internal abstract class AttachToProcessView(

private suspend fun processAsPlainList(host: XAttachHost) {
val itemsInfo = try {
if (isListMerged()) {
collectAttachProcessItemsGroupByProcessInfo(project, host, attachDebuggerProviders)
}
else {
collectAttachProcessItems(project, host, attachDebuggerProviders)
}
collectAttachProcessItemsGroupByProcessInfo(project, host, attachDebuggerProviders)
}
catch (processesFetchingException: ProcessesFetchingProblemException) {
processDiagnosticInfo(processesFetchingException, host)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.intellij.util.ui.JBUI
import com.intellij.xdebugger.XDebuggerBundle
import com.intellij.xdebugger.impl.ui.attach.dialog.extensions.XAttachDialogUiInvisiblePresentationGroup
import com.intellij.xdebugger.impl.ui.attach.dialog.extensions.XAttachTreeDebuggersPresentationProvider
import com.intellij.xdebugger.impl.ui.attach.dialog.isListMerged
import com.intellij.xdebugger.impl.ui.attach.dialog.items.AttachColumnSettingsState
import com.intellij.xdebugger.impl.ui.attach.dialog.items.AttachNodeContainer
import com.intellij.xdebugger.impl.ui.attach.dialog.items.AttachTableCell
Expand Down Expand Up @@ -43,9 +42,7 @@ internal class DebuggersListCell(private val node: AttachToProcessListItem, stat
}


internal class CommandLineListCell(private val node: AttachToProcessListItem, state: AttachColumnSettingsState) : AttachTableCell(state,
if (isListMerged()) 3 else 2,
XDebuggerBundle.message(
internal class CommandLineListCell(private val node: AttachToProcessListItem, state: AttachColumnSettingsState) : AttachTableCell(state, 3, XDebuggerBundle.message(
"xdebugger.attach.command.line.column.name")) {

override fun getTextToDisplay(): String = node.item.commandLineText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.intellij.openapi.util.Disposer
import com.intellij.ui.speedSearch.FilteringTableModel
import com.intellij.ui.table.JBTable
import com.intellij.xdebugger.XDebuggerBundle
import com.intellij.xdebugger.attach.XAttachPresentationGroup
import com.intellij.xdebugger.impl.ui.attach.dialog.AttachDialogState
import com.intellij.xdebugger.impl.ui.attach.dialog.AttachItemsInfo
import com.intellij.xdebugger.impl.ui.attach.dialog.isListMerged
import com.intellij.xdebugger.impl.ui.attach.dialog.items.*
import com.intellij.xdebugger.impl.ui.attach.dialog.items.separators.AttachGroupColumnRenderer
import com.intellij.xdebugger.impl.ui.attach.dialog.items.separators.AttachGroupFirstColumnRenderer
Expand Down Expand Up @@ -146,12 +144,10 @@ internal class AttachToProcessItemsList(itemNodes: List<AttachToProcessElement>,

class AttachToProcessListColumnModel : DefaultTableColumnModel() {
init {
val columnsCount = if (isListMerged()) 4 else 3
val columnsCount = 4
addColumn(TableColumn(0).apply { identifier = 0; headerValue = XDebuggerBundle.message("xdebugger.attach.executable.column.name") })
addColumn(TableColumn(1).apply { identifier = 1; headerValue = XDebuggerBundle.message("xdebugger.attach.pid.column.name") })
if (isListMerged()) {
addColumn(TableColumn(2).apply { identifier = 2; headerValue = XDebuggerBundle.message("xdebugger.attach.debuggers.column.name") })
}
addColumn(TableColumn(2).apply { identifier = 2; headerValue = XDebuggerBundle.message("xdebugger.attach.debuggers.column.name") })
addColumn(TableColumn(columnsCount - 1).apply { identifier = columnsCount - 1; headerValue = XDebuggerBundle.message("xdebugger.attach.command.line.column.name") })
}
}
Expand All @@ -161,7 +157,7 @@ internal class AttachToProcessTableModel(private val itemNodes: List<AttachToPro

override fun getRowCount(): Int = itemNodes.size

override fun getColumnCount(): Int = if (isListMerged()) 4 else 3
override fun getColumnCount(): Int = 4

override fun getValueAt(rowIndex: Int, columnIndex: Int): Any {
val itemNode = itemNodes[rowIndex]
Expand All @@ -171,60 +167,14 @@ internal class AttachToProcessTableModel(private val itemNodes: List<AttachToPro
if (columnIndex < 0 || columnIndex >= columnCount) throw IllegalStateException("Unexpected column number: $columnIndex")
if (columnIndex == 0) return ExecutableListCell(state.attachListColumnSettings, itemNode)
if (columnIndex == 1) return PidListCell(itemNode.item.processInfo.pid, state.attachListColumnSettings)
if (isListMerged() && columnIndex == 2) return DebuggersListCell(itemNode, state.attachListColumnSettings)
if (columnIndex == 2) return DebuggersListCell(itemNode, state.attachListColumnSettings)
if (columnIndex == columnCount - 1) return CommandLineListCell(itemNode, state.attachListColumnSettings)
throw IllegalStateException("Unexpected column number: $columnIndex")
}
}

internal suspend fun buildList(itemsInfo: AttachItemsInfo, dialogState: AttachDialogState): AttachToProcessItemsList {
return if (isListMerged()) {
buildMergedList(itemsInfo, dialogState)
}
else {
buildListGroupedByProvider(itemsInfo, dialogState)
}
}

private suspend fun buildListGroupedByProvider(itemsInfo: AttachItemsInfo, dialogState: AttachDialogState): AttachToProcessItemsList {
val allGroups = mutableSetOf<AttachToProcessListGroupBase>()

val recentItems = itemsInfo.recentItems
var firstGroup = true
if (recentItems.any()) {
val recentGroup = AttachToProcessListRecentGroup().apply { isFirstGroup = true }
firstGroup = false
allGroups.add(recentGroup)

for (recentItem in recentItems) {
recentGroup.add(AttachToProcessListItem(recentItem))
}
}

val itemGroups = mutableMapOf<XAttachPresentationGroup<*>, AttachToProcessListGroup>()

for (item in itemsInfo.processItems) {
coroutineContext.ensureActive()

val presentationGroup = item.getGroups().singleOrNull() ?: throw IllegalStateException("List view does not support items with several groups")
itemGroups.putIfAbsent(presentationGroup, AttachToProcessListGroup(presentationGroup).apply {
allGroups.add(this)
this.isFirstGroup = firstGroup
firstGroup = false
})
val group = itemGroups[presentationGroup] ?: throw IllegalStateException("Group should be available at this point")

val itemNode = AttachToProcessListItem(item)
group.add(itemNode)
}

val itemNodes = mutableListOf<AttachToProcessElement>()
for (group in allGroups.sortedBy { it.getOrder() }) {
itemNodes.add(group)
itemNodes.addAll(group.getNodes())
}

return AttachToProcessItemsList(itemNodes, dialogState)
return buildMergedList(itemsInfo, dialogState)
}

private suspend fun buildMergedList(itemsInfo: AttachItemsInfo, dialogState: AttachDialogState): AttachToProcessItemsList {
Expand Down

0 comments on commit d94bc25

Please sign in to comment.