Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #211

Merged
merged 17 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,12 @@ jobs:
run: |
PROPERTIES="$(./gradlew properties --console=plain -q)"
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"

echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT

echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier

# Build plugin
- name: Build plugin
run: ./gradlew buildPlugin
Expand Down Expand Up @@ -179,14 +174,6 @@ jobs:
distribution: zulu
java-version: 17

# Run Qodana inspections
- name: Qodana - Code Inspection
uses: JetBrains/[email protected]
with:
cache-default-branch-only: true
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

# Run plugin structure verification along with IntelliJ Plugin Verifier
verify:
name: Verify plugin
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
Expand Down Expand Up @@ -43,4 +44,6 @@ bin/
.DS_Store
tmp/

*.log
*.log
src/main/resources/static/main.html
src/main/resources/static/main.js
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/encodings.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/gradle.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/vcs.xml

This file was deleted.

2 changes: 1 addition & 1 deletion gui
48 changes: 38 additions & 10 deletions src/main/kotlin/ai/devchat/common/PathUtils.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package ai.devchat.common

import kotlinx.coroutines.*
import java.io.File
import java.io.IOException
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes

import java.security.MessageDigest
import java.util.concurrent.Executors

object PathUtils {
val workPath: String = Paths.get(System.getProperty("user.home"), ".chat").toString()
val workflowPath: String = Paths.get(workPath, "scripts").toString()
val workflowMericoPath: String = Paths.get(workPath, "scripts", "merico").toString()
val sitePackagePath: String = Paths.get(workPath, "site-packages").toString()
val pythonPath: String = "$sitePackagePath:$workflowPath"
val mambaWorkPath = Paths.get(workPath, "mamba").toString()
Expand All @@ -25,10 +28,14 @@ object PathUtils {
else -> throw RuntimeException("Unsupported OS: ${OSInfo.OS_NAME}")
}}-code_editor" + if (OSInfo.isWindows) ".exe" else ""

fun copyResourceDirToPath(resourcePath: String, outputPath: String, overwrite: Boolean = false): String {
private val dispatcher = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()).asCoroutineDispatcher()

suspend fun copyResourceDirToPath(resourcePath: String, outputPath: String, overwrite: Boolean = false): String = withContext(dispatcher) {
Log.info("copy files stage 1")
val uri = javaClass.getResource(resourcePath)?.toURI() ?: throw IllegalArgumentException(
"Resource not found: $resourcePath"
)
Log.info("copy files stage 2")
val sourcePath = if (uri.scheme == "jar") {
val fileSystem = try {
FileSystems.newFileSystem(uri, emptyMap<String, Any>())
Expand All @@ -39,18 +46,27 @@ object PathUtils {
} else {
Paths.get(uri)
}
Log.info("copy files stage 3")

val targetPath = Paths.get(outputPath)
if (!Files.exists(targetPath.parent)) Files.createDirectories(targetPath.parent)
if (overwrite && Files.exists(targetPath)) targetPath.toFile().deleteRecursively()
if (!overwrite && Files.exists(targetPath)) {
return@withContext targetPath.toString()
}
// if (overwrite && Files.exists(targetPath)) targetPath.toFile().deleteRecursively()

Log.info("copy files stage 4")
// Handle single file copying
if (Files.isRegularFile(sourcePath)) {
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING)
targetPath.toFile().setExecutable(true)
return targetPath.toString()
return@withContext targetPath.toString()
}
Log.info("copy files stage 5")

val jobs = mutableListOf<Deferred<Unit>>()

Log.info("copy files stage 6")
Files.walkFileTree(sourcePath, object : SimpleFileVisitor<Path>() {
@Throws(IOException::class)
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
Expand All @@ -63,15 +79,27 @@ object PathUtils {
@Throws(IOException::class)
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
val target = targetPath.resolve(sourcePath.relativize(file).toString())
if (!Files.exists(target) || attrs.lastModifiedTime() > Files.getLastModifiedTime(target)) {
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING)
Files.setLastModifiedTime(target, attrs.lastModifiedTime())
}
jobs.add(async {
if (shouldCopyFile(file, target, attrs, overwrite)) {
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING)
Files.setLastModifiedTime(target, attrs.lastModifiedTime())
}
})
return FileVisitResult.CONTINUE
}
})
Log.info("copy files stage 7")

jobs.awaitAll()
Log.info("copy files stage 8")
targetPath.toString()
}

return targetPath.toString()
private fun shouldCopyFile(source: Path, target: Path, sourceAttrs: BasicFileAttributes, overwrite: Boolean): Boolean {
if (!Files.exists(target)) return true
if (!overwrite) return false
if (sourceAttrs.lastModifiedTime() != Files.getLastModifiedTime(target)) return true
return false
}

fun createTempFile(content: String, prefix: String = "devchat-tmp-", suffix: String = ""): String? {
Expand All @@ -84,4 +112,4 @@ object PathUtils {
return null
}
}
}
}
10 changes: 9 additions & 1 deletion src/main/kotlin/ai/devchat/core/DevChatClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class ChatResponse(
var date: String? = null,
var content: String? = "",
@SerialName("finish_reason") var finishReason: String? = "",
@SerialName("is_error") var isError: Boolean = false,
var isError: Boolean = false,
var extra: JsonElement? = null
) {
fun reset() {
Expand Down Expand Up @@ -327,6 +327,14 @@ class DevChatClient(val project: Project, private val localServicePort: Int) {
onFinish(-1)
cancelMessage()
}
if (chunk.isError) {
val errorMessage = chunk.content?.takeIf { it.isNotBlank() }
?: "Unknown error occurred"
onError(errorMessage)
Log.warn("Error on sending message: ${chunk.toString()}")
onFinish(1)
cancelMessage()
}
onData(chunk)
}
onFinish(0)
Expand Down
Loading
Loading