Skip to content

Commit 23e4d8e

Browse files
committed
refactor: rename diff package to core, extract session sub-package, and drop dead SAM interfaces
1 parent 1781fe3 commit 23e4d8e

39 files changed

Lines changed: 431 additions & 291 deletions

src/main/kotlin/com/ashotn/opencode/companion/OpenCodePlugin.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ashotn.opencode.companion
22

3-
import com.ashotn.opencode.companion.diff.OpenCodeDiffService
3+
import com.ashotn.opencode.companion.core.OpenCodeCoreService
44
import com.ashotn.opencode.companion.tui.OpenCodeTuiClient
55
import com.intellij.openapi.Disposable
66
import com.intellij.openapi.application.ApplicationManager
@@ -26,13 +26,13 @@ class OpenCodePlugin(private val project: Project) : Disposable {
2626
val port = com.ashotn.opencode.companion.settings.OpenCodeSettings.getInstance(project).serverPort
2727
ApplicationManager.getApplication().executeOnPooledThread {
2828
if (project.isDisposed) return@executeOnPooledThread
29-
OpenCodeDiffService.getInstance(project).startListening(port)
29+
OpenCodeCoreService.getInstance(project).startListening(port)
3030
OpenCodeTuiClient.getInstance(project).setPort(port)
3131
}
3232
} else if (state == ServerState.STOPPED) {
3333
ApplicationManager.getApplication().executeOnPooledThread {
3434
if (project.isDisposed) return@executeOnPooledThread
35-
OpenCodeDiffService.getInstance(project).stopListening()
35+
OpenCodeCoreService.getInstance(project).stopListening()
3636
OpenCodeTuiClient.getInstance(project).setPort(0)
3737
}
3838
}
@@ -41,7 +41,8 @@ class OpenCodePlugin(private val project: Project) : Disposable {
4141
val isRunning: Boolean get() = serverManager.isRunning
4242
val ownsProcess: Boolean get() = serverManager.ownsProcess
4343

44-
@Volatile private var overrideState: ServerState? = null
44+
@Volatile
45+
private var overrideState: ServerState? = null
4546
val serverState: ServerState get() = overrideState ?: serverManager.serverState
4647

4748
private fun broadcastState(state: ServerState) {
@@ -58,7 +59,7 @@ class OpenCodePlugin(private val project: Project) : Disposable {
5859
broadcastState(ServerState.RESETTING)
5960
ApplicationManager.getApplication().executeOnPooledThread {
6061
if (project.isDisposed) return@executeOnPooledThread
61-
val diffService = OpenCodeDiffService.getInstance(project)
62+
val diffService = OpenCodeCoreService.getInstance(project)
6263
diffService.stopListening()
6364
overrideState = null
6465
diffService.startListening(port)

src/main/kotlin/com/ashotn/opencode/companion/actions/ClearSelectedSessionAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ashotn.opencode.companion.actions
22

3-
import com.ashotn.opencode.companion.diff.OpenCodeDiffService
3+
import com.ashotn.opencode.companion.core.OpenCodeCoreService
44
import com.ashotn.opencode.companion.util.applyStrings
55
import com.intellij.icons.AllIcons
66
import com.intellij.openapi.actionSystem.ActionUpdateThread
@@ -28,12 +28,12 @@ class ClearSelectedSessionAction(private val project: Project? = null) : AnActio
2828
e.presentation.description = strings.disabledDescription
2929
return
3030
}
31-
val hasSelectedSession = OpenCodeDiffService.getInstance(proj).selectedSessionId() != null
31+
val hasSelectedSession = OpenCodeCoreService.getInstance(proj).selectedSessionId() != null
3232
e.applyStrings(strings, hasSelectedSession)
3333
}
3434

3535
override fun actionPerformed(e: AnActionEvent) {
3636
val proj = project ?: e.project ?: return
37-
OpenCodeDiffService.getInstance(proj).selectSession(null)
37+
OpenCodeCoreService.getInstance(proj).selectSession(null)
3838
}
3939
}

src/main/kotlin/com/ashotn/opencode/companion/api/session/SessionApiClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.ashotn.opencode.companion.api.transport.parseBooleanResponse
77
import com.ashotn.opencode.companion.api.transport.mapJsonArrayResponse
88
import com.ashotn.opencode.companion.api.transport.mapJsonObjectResponse
99
import com.ashotn.opencode.companion.api.transport.withParseContext
10-
import com.ashotn.opencode.companion.diff.DiffTextUtil
10+
import com.ashotn.opencode.companion.util.toAbsolutePath
1111
import com.ashotn.opencode.companion.ipc.OpenCodeEvent
1212
import com.ashotn.opencode.companion.ipc.SessionDiffStatus
1313
import com.ashotn.opencode.companion.util.getIntOrNull
@@ -87,7 +87,7 @@ class SessionApiClient(
8787
is ApiResult.Failure -> snapshot
8888
is ApiResult.Success -> {
8989
val match = snapshot.value.files.firstOrNull { diffFile ->
90-
DiffTextUtil.toAbsolutePath(projectBase, diffFile.file) == absFilePath
90+
toAbsolutePath(projectBase, diffFile.file) == absFilePath
9191
} ?: return ApiResult.Success(null)
9292

9393
ApiResult.Success(FileDiffPreview(before = match.before, after = match.after))

src/main/kotlin/com/ashotn/opencode/companion/diff/DiffHighlightStyle.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DiffHighlightStyle.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.intellij.ui.JBColor
44
import java.awt.Color
@@ -28,4 +28,4 @@ object DiffHighlightStyles {
2828
)
2929

3030
}
31-
}
31+
}

src/main/kotlin/com/ashotn/opencode/companion/diff/DiffHunk.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DiffHunk.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
/**
44
* A single contiguous block of changed lines within a file.
@@ -17,4 +17,4 @@ data class DiffHunk(
1717
val removedLines: List<String>,
1818
val addedLines: List<String>,
1919
val sessionId: String,
20-
)
20+
)

src/main/kotlin/com/ashotn/opencode/companion/diff/DiffHunkComputer.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DiffHunkComputer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.ashotn.opencode.companion.api.session.FileDiff
44
import com.intellij.diff.comparison.ComparisonManager
@@ -31,8 +31,8 @@ internal class DiffHunkComputer(private val logger: Logger) {
3131
} catch (e: com.intellij.openapi.progress.ProcessCanceledException) {
3232
throw e
3333
} catch (e: Exception) {
34-
logger.warn("OpenCodeDiffService: failed to compute hunks for ${fileDiff.file}", e)
34+
logger.warn("OpenCodeCoreService: failed to compute hunks for ${fileDiff.file}", e)
3535
emptyList()
3636
}
3737
}
38-
}
38+
}

src/main/kotlin/com/ashotn/opencode/companion/diff/DiffHunksChangedListener.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DiffHunksChangedListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.intellij.util.messages.Topic
44

@@ -17,4 +17,4 @@ fun interface DiffHunksChangedListener {
1717
val TOPIC: Topic<DiffHunksChangedListener> =
1818
Topic.create("OpenCode Diff Hunks Changed", DiffHunksChangedListener::class.java)
1919
}
20-
}
20+
}

src/main/kotlin/com/ashotn/opencode/companion/diff/DiffTracer.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DiffTracer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.google.gson.GsonBuilder
44
import com.intellij.openapi.diagnostic.Logger
@@ -121,4 +121,4 @@ internal class JsonlDiffTracer(
121121
return createdWriter
122122
}
123123
}
124-
}
124+
}

src/main/kotlin/com/ashotn/opencode/companion/diff/DocumentSyncService.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/DocumentSyncService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.ashotn.opencode.companion.ipc.SessionDiffStatus
44
import com.intellij.openapi.application.ApplicationManager
@@ -113,4 +113,4 @@ internal class DocumentSyncService(
113113
companion object {
114114
private const val DOCUMENT_RELOAD_COOLDOWN_MILLIS = 500L
115115
}
116-
}
116+
}

src/main/kotlin/com/ashotn/opencode/companion/diff/EditorDiffRenderer.kt renamed to src/main/kotlin/com/ashotn/opencode/companion/core/EditorDiffRenderer.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ashotn.opencode.companion.diff
1+
package com.ashotn.opencode.companion.core
22

33
import com.ashotn.opencode.companion.settings.OpenCodeSettings
44
import com.intellij.openapi.Disposable
@@ -54,7 +54,7 @@ class EditorDiffRenderer(private val project: Project) : Disposable, FileEditorM
5454
bus.subscribe(FileDocumentManagerListener.TOPIC, object : FileDocumentManagerListener {
5555
override fun fileContentReloaded(file: VirtualFile, document: Document) {
5656
val filePath = file.path
57-
val diffService = OpenCodeDiffService.getInstance(project)
57+
val diffService = OpenCodeCoreService.getInstance(project)
5858
if (!diffService.hasPendingHunks(filePath)) return
5959
ApplicationManager.getApplication().invokeLater {
6060
refreshFile(filePath)
@@ -65,7 +65,7 @@ class EditorDiffRenderer(private val project: Project) : Disposable, FileEditorM
6565

6666
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
6767
val filePath = file.path
68-
val diffService = OpenCodeDiffService.getInstance(project)
68+
val diffService = OpenCodeCoreService.getInstance(project)
6969
if (diffService.hasPendingHunks(filePath)) {
7070
ApplicationManager.getApplication().invokeLater {
7171
refreshFile(filePath)
@@ -78,7 +78,7 @@ class EditorDiffRenderer(private val project: Project) : Disposable, FileEditorM
7878
if (!OpenCodeSettings.getInstance(project).inlineDiffEnabled) {
7979
clearAll()
8080
} else {
81-
val diffService = OpenCodeDiffService.getInstance(project)
81+
val diffService = OpenCodeCoreService.getInstance(project)
8282
diffService.allTrackedFiles().forEach { refreshFile(it) }
8383
}
8484
}
@@ -88,7 +88,7 @@ class EditorDiffRenderer(private val project: Project) : Disposable, FileEditorM
8888

8989
if (!OpenCodeSettings.getInstance(project).inlineDiffEnabled) return
9090

91-
val diffService = OpenCodeDiffService.getInstance(project)
91+
val diffService = OpenCodeCoreService.getInstance(project)
9292
val hunks = diffService.getHunks(filePath)
9393
log.debug("EditorDiffRenderer: refresh file=$filePath pendingHunkCount=${hunks.size}")
9494
if (hunks.isEmpty()) return
@@ -179,4 +179,4 @@ class EditorDiffRenderer(private val project: Project) : Disposable, FileEditorM
179179
fun getInstance(project: Project): EditorDiffRenderer =
180180
project.getService(EditorDiffRenderer::class.java)
181181
}
182-
}
182+
}

0 commit comments

Comments
 (0)