@@ -13,6 +13,7 @@ import com.intellij.openapi.editor.Document
13
13
import com.intellij.openapi.fileEditor.FileEditor
14
14
import com.intellij.openapi.fileEditor.FileEditorManager
15
15
import com.intellij.openapi.project.Project
16
+ import com.intellij.openapi.project.guessProjectDir
16
17
import com.intellij.openapi.vfs.VirtualFile
17
18
import com.intellij.psi.PsiDocumentManager
18
19
import com.intellij.psi.PsiElement
@@ -32,6 +33,7 @@ class StructureInCommand(val myProject: Project, val prop: String) : InsCommand
32
33
*/
33
34
private val maxLineWith = 11
34
35
private val maxDepth = 5
36
+ private val maxLinesForShowLinNO = 150
35
37
36
38
private val logger = logger<StructureInCommand >()
37
39
override suspend fun execute (): String? {
@@ -49,7 +51,10 @@ class StructureInCommand(val myProject: Project, val prop: String) : InsCommand
49
51
}.get()
50
52
} ? : return null
51
53
52
- return " ```\n " + getFileStructure(myProject, virtualFile, psiFile) + " \n ```"
54
+ val structure = getFileStructure(myProject, virtualFile, psiFile)
55
+ val baseDir = myProject.guessProjectDir().toString()
56
+ val filepath = virtualFile.path.removePrefix(baseDir)
57
+ return " // $filepath \n ```\n " + structure + " \n ```"
53
58
}
54
59
55
60
fun getFileStructure (project : Project , file : VirtualFile , psiFile : PsiFile ): String {
@@ -95,10 +100,6 @@ class StructureInCommand(val myProject: Project, val prop: String) : InsCommand
95
100
}
96
101
97
102
private fun formatBeforeCode (element : StructureViewTreeElement , depth : Int ): String {
98
- if (depth > maxDepth) {
99
- return " " .repeat(maxLineWith) + " " .repeat(depth)
100
- }
101
-
102
103
return if (element.value is PsiElement ) {
103
104
val psiElement = element.value as PsiElement
104
105
val line = formatLine(psiElement)
@@ -118,7 +119,11 @@ class StructureInCommand(val myProject: Project, val prop: String) : InsCommand
118
119
val start = document.getLineNumber(psiElement.textRange.startOffset)
119
120
val end = document.getLineNumber(psiElement.textRange.endOffset)
120
121
121
- return " (${start + 1 } -${end + 1 } )"
122
+ if (end - start > maxLinesForShowLinNO) {
123
+ return " (${start + 1 } -${end + 1 } )"
124
+ }
125
+
126
+ return " " .repeat(maxDepth)
122
127
}
123
128
124
129
fun file (project : Project , path : String ): VirtualFile ? {
0 commit comments