Skip to content

Commit 6b3e887

Browse files
committed
feat(toolchain): add toolchain icon and improve command completion #307
1 parent d83285e commit 6b3e887

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

core/src/main/kotlin/cc/unitmesh/devti/AutoDevIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ object AutoDevIcons {
4949

5050
@JvmField
5151
val Stop: Icon = IconLoader.getIcon("/icons/stop.svg", AutoDevIcons::class.java)
52+
53+
@JvmField
54+
val TOOLCHAIN: Icon = IconLoader.getIcon("/icons/toolchain.svg", AutoDevIcons::class.java)
5255
}

core/src/main/kotlin/cc/unitmesh/devti/bridge/utils/StructureCommandUtil.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.bridge.utils
33
import com.intellij.ide.structureView.StructureView
44
import com.intellij.ide.structureView.StructureViewTreeElement
55
import com.intellij.lang.LanguageStructureViewBuilder
6+
import com.intellij.openapi.application.invokeLater
67
import com.intellij.openapi.editor.Document
78
import com.intellij.openapi.fileEditor.FileEditor
89
import com.intellij.openapi.fileEditor.FileEditorManager
@@ -18,9 +19,9 @@ object StructureCommandUtil {
1819
* (1000-9999)
1920
* ```
2021
*/
21-
private val maxLineWith = 11
22-
private val maxDepth = 5
23-
private val maxLinesForShowLinNO = 60
22+
private const val MAX_LINE_WIDTH = 11
23+
private const val MAX_DEPTH = 5
24+
private const val MAX_LINES_FOR_SHOW_LINENO = 60
2425

2526
fun getFileStructure(project: Project, file: VirtualFile, psiFile: PsiFile): String {
2627
val viewFactory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.language)
@@ -33,8 +34,9 @@ object StructureCommandUtil {
3334
?.createStructureView(fileEditor, project)
3435
?: return "No StructureView found."
3536

36-
/// close the editor
37-
FileEditorManager.getInstance(project).closeFile(file)
37+
invokeLater {
38+
FileEditorManager.getInstance(project).closeFile(file)
39+
}
3840

3941
val root: StructureViewTreeElement = view.treeModel.root
4042
return traverseStructure(root, 0, StringBuilder()).toString()
@@ -52,9 +54,7 @@ object StructureCommandUtil {
5254
private fun traverseStructure(element: StructureViewTreeElement, depth: Int, sb: StringBuilder): StringBuilder {
5355
val indent = formatBeforeCode(element, depth)
5456
var str = element.presentation.presentableText
55-
// if (!str.isNullOrBlank() && !element.presentation.locationString.isNullOrBlank()) {
56-
// str += " (${element.presentation.locationString})"
57-
// }
57+
5858
if (!str.isNullOrBlank()) {
5959
sb.append(indent).append(str).append("\n")
6060
}
@@ -72,13 +72,13 @@ object StructureCommandUtil {
7272
return if (element.value is PsiElement) {
7373
val psiElement = element.value as PsiElement
7474
val line = formatLine(psiElement)
75-
if (line.length < maxLineWith) {
76-
line + " ".repeat(maxLineWith - line.length) + " ".repeat(depth)
75+
if (line.length < MAX_LINE_WIDTH) {
76+
line + " ".repeat(MAX_LINE_WIDTH - line.length) + " ".repeat(depth)
7777
} else {
7878
line + " ".repeat(depth)
7979
}
8080
} else {
81-
" ".repeat(maxLineWith) + " ".repeat(depth)
81+
" ".repeat(MAX_LINE_WIDTH) + " ".repeat(depth)
8282
}
8383
}
8484

@@ -88,10 +88,10 @@ object StructureCommandUtil {
8888
val start = document.getLineNumber(psiElement.textRange.startOffset)
8989
val end = document.getLineNumber(psiElement.textRange.endOffset)
9090

91-
if (end - start > maxLinesForShowLinNO) {
91+
if (end - start > MAX_LINES_FOR_SHOW_LINENO) {
9292
return "(${start + 1}-${end + 1})"
9393
}
9494

95-
return " ".repeat(maxDepth)
95+
return " ".repeat(MAX_DEPTH)
9696
}
9797
}

core/src/main/kotlin/cc/unitmesh/devti/devin/dataprovider/BuiltinCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ enum class BuiltinCommand(
120120

121121
companion object {
122122
fun all(): List<BuiltinCommand> {
123-
return values().toList()
123+
return entries.filter { it != TOOLCHAIN_COMMAND }
124124
}
125125

126126
fun example(command: BuiltinCommand): String {
Lines changed: 17 additions & 0 deletions
Loading

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/ToolchainCommandCompletion.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cc.unitmesh.devti.language.completion.provider
22

3+
import cc.unitmesh.devti.AutoDevIcons
34
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
4-
import com.intellij.codeInsight.AutoPopupController
55
import com.intellij.codeInsight.completion.*
66
import com.intellij.codeInsight.lookup.LookupElementBuilder
77
import com.intellij.util.ProcessingContext
@@ -20,14 +20,7 @@ class ToolchainCommandCompletion : CompletionProvider<CompletionParameters>() {
2020

2121
private fun createCommandCompletionCandidate(it: String) =
2222
PrioritizedLookupElement.withPriority(
23-
LookupElementBuilder.create(it)
24-
.withInsertHandler { context, _ ->
25-
context.document.insertString(context.tailOffset, ":")
26-
context.editor.caretModel.moveCaretRelatively(1, 0, false, false, false)
27-
28-
val editor = context.editor
29-
AutoPopupController.getInstance(editor.project!!).scheduleAutoPopup(editor)
30-
},
23+
LookupElementBuilder.create(it).withIcon(AutoDevIcons.TOOLCHAIN),
3124
98.0
3225
)
3326
}

exts/ext-git/src/main/kotlin/cc/unitmesh/git/actions/vcs/GitRevisionProvider.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ class GitRevisionProvider : RevisionProvider {
135135
override fun history(project: Project, file: VirtualFile): String {
136136
val filePath: FilePath = VcsUtil.getFilePath(file)
137137
val history = GitFileHistory.collectHistory(project, filePath)
138-
val historyCommitMessages = history.joinToString("\n") { it.commitMessage.toString() }
138+
val historyCommitMessages = history.withIndex().joinToString("\n") { "${it.index + 1}. ${it.value.commitMessage}" }
139139

140140
return """
141141
|filename: ${file.name}
142142
|changes: ${history.size}
143-
|historyCommits: $historyCommitMessages
143+
|historyCommits:
144+
|$historyCommitMessages
144145
""".trimMargin()
145146
}
146147
}

0 commit comments

Comments
 (0)