generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable recording datasets works in local
- Loading branch information
Showing
6 changed files
with
78 additions
and
1 deletion.
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
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/cc/unitmesh/devti/recording/EmptyRecording.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,7 @@ | ||
package cc.unitmesh.devti.recording | ||
|
||
class EmptyRecording: Recording { | ||
override fun write(instruction: RecordingInstruction) { | ||
// do nothing | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/cc/unitmesh/devti/recording/JsonlRecording.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,21 @@ | ||
package cc.unitmesh.devti.recording | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.guessProjectDir | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import java.nio.file.Path | ||
|
||
@Service(Service.Level.PROJECT) | ||
class JsonlRecording(val project: Project) : Recording { | ||
private val recordingPath: Path = Path.of(project.guessProjectDir()!!.path, "recording.jsonl") | ||
override fun write(instruction: RecordingInstruction) { | ||
if (!recordingPath.toFile().exists()) { | ||
recordingPath.toFile().createNewFile() | ||
} | ||
|
||
recordingPath.toFile().appendText(Json.encodeToString(instruction) + "\n") | ||
} | ||
} | ||
|
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,5 @@ | ||
package cc.unitmesh.devti.recording | ||
|
||
interface Recording { | ||
fun write(instruction: RecordingInstruction) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/cc/unitmesh/devti/recording/RecordingInstruction.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,9 @@ | ||
package cc.unitmesh.devti.recording | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RecordingInstruction( | ||
val instruction: String, | ||
val output: String, | ||
) |