@@ -8,6 +8,7 @@ import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
8
8
import cc.unitmesh.devti.language.compiler.model.LineInfo
9
9
import cc.unitmesh.devti.language.utils.findFile
10
10
import cc.unitmesh.devti.language.utils.lookupFile
11
+ import cc.unitmesh.devti.sketch.ui.patch.readText
11
12
import com.intellij.openapi.project.Project
12
13
import com.intellij.openapi.vfs.VirtualFile
13
14
import com.intellij.psi.PsiManager
@@ -35,8 +36,8 @@ class FileInsCommand(private val myProject: Project, private val prop: String) :
35
36
virtualFile = myProject.findFile(filename, false )
36
37
}
37
38
38
- val contentsToByteArray = virtualFile?.contentsToByteArray ()
39
- if (contentsToByteArray == null ) {
39
+ val content = virtualFile?.readText ()
40
+ if (content == null ) {
40
41
AutoDevNotifications .warn(myProject, " File not found: $prop " )
41
42
// / not show error message to just notify
42
43
return " File not found: $prop "
@@ -46,29 +47,25 @@ class FileInsCommand(private val myProject: Project, private val prop: String) :
46
47
47
48
val lang = PsiManager .getInstance(myProject).findFile(virtualFile)?.language?.displayName ? : " "
48
49
49
- contentsToByteArray.let { bytes ->
50
-
51
- val content = bytes.toString(Charsets .UTF_8 )
52
- val fileContent = if (range != null ) {
53
- val subContent = try {
54
- content.split(" \n " ).slice(range.startLine - 1 until range.endLine)
55
- .joinToString(" \n " )
56
- } catch (e: StringIndexOutOfBoundsException ) {
57
- content
58
- }
59
-
60
- subContent
61
- } else {
50
+ val fileContent = if (range != null ) {
51
+ val subContent = try {
52
+ content.split(" \n " ).slice(range.startLine - 1 until range.endLine)
53
+ .joinToString(" \n " )
54
+ } catch (e: StringIndexOutOfBoundsException ) {
62
55
content
63
56
}
64
57
65
- // add file path
66
- output.append(" // File: $prop \n " )
67
- output.append(" \n ```$lang \n " )
68
- output.append(fileContent)
69
- output.append(" \n ```\n " )
58
+ subContent
59
+ } else {
60
+ content
70
61
}
71
62
63
+ // add file path
64
+ output.append(" // File: $prop \n " )
65
+ output.append(" \n ```$lang \n " )
66
+ output.append(fileContent)
67
+ output.append(" \n ```\n " )
68
+
72
69
return output.toString()
73
70
}
74
71
}
0 commit comments