Skip to content

Commit

Permalink
fix: Add directory checks and optimize token usage
Browse files Browse the repository at this point in the history
- Added check to skip directories when reading file content.
- Optimized token usage by removing unnecessary `\r` characters.
  • Loading branch information
lkk214 committed Dec 31, 2024
1 parent 0a7da20 commit 79736c3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,16 @@ class IntelliJIDE(
content
} else {
val file = File(URI(filepath))
if (!file.exists()) return ""
if (!file.exists() || file.isDirectory) return ""
withContext(Dispatchers.IO) {
FileInputStream(file).use { fis ->
val sizeToRead = minOf(100000, file.length()).toInt()
val buffer = ByteArray(sizeToRead)
val bytesRead = fis.read(buffer, 0, sizeToRead)
if (bytesRead <= 0) return@use ""
String(buffer, 0, bytesRead, Charset.forName("UTF-8"))
// `\r` takes up unnecessary tokens
.lineSequence().joinToString("\n")
}
}
}
Expand Down

0 comments on commit 79736c3

Please sign in to comment.