-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All commits (need to be split into smaller commits)
- Loading branch information
Showing
64 changed files
with
2,769 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
alias(libs.plugins.kotlinJvm) | ||
alias(libs.plugins.sqldelight) | ||
alias(libs.plugins.kotlinSerialization) | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
sqldelight { | ||
databases { | ||
create("Database") { | ||
packageName.set("com.kitakkun.backintime.tooling.database") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.websocket.event) | ||
implementation(projects.tooling.model) | ||
implementation(projects.tooling.shared) | ||
implementation(libs.sqldelight.sqlite.driver) | ||
implementation(libs.sqldelight.coroutines.extensions) | ||
implementation(libs.kotlinx.serialization.json) | ||
testImplementation(libs.kotlin.test) | ||
} |
52 changes: 52 additions & 0 deletions
52
...tabase/src/main/kotlin/com/kitakkun/backintime/tooling/database/BackInTimeDatabaseImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.kitakkun.backintime.tooling.database | ||
|
||
import app.cash.sqldelight.coroutines.asFlow | ||
import app.cash.sqldelight.coroutines.mapToList | ||
import com.kitakkun.backintime.tooling.model.InstanceEventData | ||
import com.kitakkun.backintime.tooling.shared.BackInTimeDatabase | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class BackInTimeDatabaseImpl : BackInTimeDatabase { | ||
companion object { | ||
val instance: BackInTimeDatabaseImpl by lazy { BackInTimeDatabaseImpl() } | ||
} | ||
|
||
init { | ||
// Fix no suitable driver found for jdbc:sqlite: | ||
// FYI: https://stackoverflow.com/questions/16725377/unable-to-connect-to-database-no-suitable-driver-found | ||
Class.forName("org.sqlite.JDBC") | ||
} | ||
|
||
private val database = createDatabase() | ||
private val instanceEventQueries: InstanceEventQueries = database.instanceEventQueries | ||
|
||
override fun saveEvent(sessionId: String, event: InstanceEventData) { | ||
instanceEventQueries.insert(event.eventId, sessionId, event.instanceId, event) | ||
} | ||
|
||
override fun selectEventsForInstance(instanceId: String): Flow<List<InstanceEventData>> { | ||
return instanceEventQueries.selectByInstanceId(instanceId).asFlow() | ||
.mapToList(Dispatchers.IO) | ||
.map { it.mapNotNull { it.event } } | ||
} | ||
|
||
override fun getAllEventsAsFlow(): Flow<List<InstanceEventData>> = instanceEventQueries.selectAll().asFlow().mapToList(Dispatchers.IO).map { it.mapNotNull { it.event } } | ||
|
||
override fun selectEventsForSession(sessionId: String?): Flow<List<InstanceEventData>> { | ||
return if (sessionId == null) { | ||
getAllEventsAsFlow() | ||
} else { | ||
instanceEventQueries.selectBySessionId(sessionId).asFlow().mapToList(Dispatchers.IO).map { it.mapNotNull { it.event } } | ||
} | ||
} | ||
|
||
override fun allInstanceIdForSessionAsFlow(sessionId: String): Flow<List<String>> = instanceEventQueries.selectAllInstanceId(sessionId).asFlow().mapToList(Dispatchers.IO) | ||
|
||
override fun allEventsForInstanceAsFlow(sessionId: String, instanceId: String): Flow<List<InstanceEventData>> { | ||
return instanceEventQueries.selectAllForInstance(sessionId, instanceId).asFlow().mapToList(Dispatchers.IO).map { | ||
it.mapNotNull { it.event } | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...g/database/src/main/kotlin/com/kitakkun/backintime/tooling/database/SqlDelightDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.kitakkun.backintime.tooling.database | ||
|
||
import app.cash.sqldelight.ColumnAdapter | ||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver | ||
import com.kitakkun.backintime.tooling.model.InstanceEventData | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
private val instanceEventAdapter = object : ColumnAdapter<InstanceEventData, String> { | ||
override fun encode(value: InstanceEventData): String { | ||
return Json.encodeToString(value) | ||
} | ||
|
||
override fun decode(databaseValue: String): InstanceEventData { | ||
return Json.decodeFromString(databaseValue) | ||
} | ||
} | ||
|
||
fun createDatabase(url: String = JdbcSqliteDriver.IN_MEMORY): Database { | ||
val driver = JdbcSqliteDriver(url) | ||
Database.Schema.create(driver) | ||
return Database( | ||
driver = driver, | ||
instanceEventAdapter = InstanceEvent.Adapter(eventAdapter = instanceEventAdapter), | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
...ng/database/src/main/sqldelight/com/kitakkun/backintime/tooling/database/InstanceEvent.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import com.kitakkun.backintime.tooling.model.InstanceEventData; | ||
|
||
CREATE TABLE IF NOT EXISTS instanceEvent ( | ||
id TEXT PRIMARY KEY NOT NULL, | ||
sessionId TEXT NOT NULL, | ||
instanceId TEXT NOT NULL, | ||
event TEXT AS InstanceEventData | ||
); | ||
|
||
insert: | ||
INSERT OR IGNORE INTO instanceEvent(id, sessionId, instanceId, event) VALUES (?, ?, ?, ?); | ||
|
||
selectByInstanceId: | ||
SELECT * FROM instanceEvent WHERE instanceId == ?; | ||
|
||
selectAll: | ||
SELECT * FROM instanceEvent; | ||
|
||
selectBySessionId: | ||
SELECT * FROM instanceEvent WHERE sessionId == ?; | ||
|
||
selectAllInstanceId: | ||
SELECT DISTINCT instanceId FROM instanceEvent WHERE sessionId == ?; | ||
|
||
selectAllForInstance: | ||
SELECT * FROM instanceEvent WHERE sessionId == ? AND instanceId == ?; |
12 changes: 12 additions & 0 deletions
12
...se/src/test/kotlin/com/kitakkun/backintime/tooling/database/BackInTimeDatabaseImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.kitakkun.backintime.tooling.database | ||
|
||
import com.kitakkun.backintime.tooling.model.InstanceEventData | ||
import kotlin.test.Test | ||
|
||
class BackInTimeDatabaseImplTest { | ||
@Test | ||
fun test() { | ||
val database = BackInTimeDatabaseImpl() | ||
database.saveEvent("sessionId", InstanceEventData.Unregister(instanceId = "uuid", time = 0L)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
...plugin/src/main/kotlin/com/kitakkun/backintime/tooling/idea/BackInTimeToolComposePanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
package com.kitakkun.backintime.tooling.idea | ||
|
||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.awt.ComposePanel | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.Project | ||
import com.kitakkun.backintime.tooling.idea.service.BackInTimeDebuggerServiceImpl | ||
import com.kitakkun.backintime.tooling.idea.service.BackInTimeDebuggerSettingsImpl | ||
import com.kitakkun.backintime.tooling.idea.service.PluginStateServiceImpl | ||
import com.kitakkun.backintime.tooling.ui.BackInTimeDebuggerApp | ||
import com.kitakkun.backintime.tooling.ui.BackInTimeTheme | ||
import com.kitakkun.backintime.tooling.ui.compositionlocal.LocalIDENavigator | ||
import com.kitakkun.backintime.tooling.ui.compositionlocal.LocalPluginStateService | ||
import com.kitakkun.backintime.tooling.ui.compositionlocal.LocalServer | ||
import com.kitakkun.backintime.tooling.ui.compositionlocal.LocalSettings | ||
|
||
class BackInTimeToolComposePanel { | ||
class BackInTimeToolComposePanel(project: Project) { | ||
val panel = ComposePanel().apply { | ||
setContent { | ||
|
||
CompositionLocalProvider( | ||
LocalIDENavigator provides project.service<IDENavigatorImpl>(), | ||
LocalSettings provides BackInTimeDebuggerSettingsImpl.getInstance(), | ||
LocalServer provides BackInTimeDebuggerServiceImpl.getInstance(), | ||
LocalPluginStateService provides PluginStateServiceImpl.getInstance() | ||
) { | ||
BackInTimeTheme { | ||
BackInTimeDebuggerApp() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tooling/idea-plugin/src/main/kotlin/com/kitakkun/backintime/tooling/idea/IDENavigatorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.kitakkun.backintime.tooling.idea | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.application.ReadAction | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.diagnostic.thisLogger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiClass | ||
import com.intellij.psi.PsiManager | ||
import com.intellij.psi.util.ClassUtil | ||
import com.kitakkun.backintime.tooling.shared.IDENavigator | ||
|
||
@Service(Service.Level.PROJECT) | ||
class IDENavigatorImpl(project: Project) : IDENavigator { | ||
private val psiManager = PsiManager.getInstance(project) | ||
|
||
override fun navigateToClass(classFqName: String) { | ||
ApplicationManager.getApplication().executeOnPooledThread { | ||
val psiClass = ReadAction.compute<PsiClass?, Throwable> { | ||
ClassUtil.findPsiClass(psiManager, classFqName) | ||
} | ||
if (psiClass != null) { | ||
ApplicationManager.getApplication().invokeLater { | ||
ReadAction.run<Throwable> { | ||
thisLogger().warn("Navigating to ${psiClass.nameIdentifier}") | ||
psiClass.navigate(true) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.