Skip to content

Commit 910daa0

Browse files
committed
fix(devins-lang): handle nullable inputStream and improve string concatenation for better performance and readability.
1 parent 68fd6b6 commit 910daa0

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class DevInsCompiler(
122122
val variableId = id?.text
123123
val variable = ToolHubVariable.lookup(myProject, variableId)
124124
if (variable.isNotEmpty()) {
125-
output.append(variable.map { it }.joinToString("\n"))
125+
output.append(variable.joinToString("\n") { it })
126126
return
127127
}
128128

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ enum class BuiltinCommand(
1414
) {
1515
FILE("file", "Read the content of a file", AllIcons.Actions.Copy, true, true),
1616
REV("rev", "Read git change by file", AllIcons.Vcs.History, true, true),
17-
1817
/**
1918
* Every language will have a symbol completion, which is the most basic completion, for example,
2019
* - Java: [com.intellij.codeInsight.completion.JavaKeywordCompletion]
@@ -50,17 +49,13 @@ enum class BuiltinCommand(
5049
fun example(command: BuiltinCommand): String {
5150
val commandName = command.commandName
5251
val inputStream = BuiltinCommand::class.java.getResourceAsStream("/agent/toolExamples/$commandName.devin")
53-
if (inputStream == null) {
54-
throw IllegalStateException("Example file not found: $commandName.devin")
55-
}
52+
?: throw IllegalStateException("Example file not found: $commandName.devin")
5653

57-
return inputStream!!.use {
54+
return inputStream.use {
5855
it.readAllBytes().toString(StandardCharsets.UTF_8)
5956
}
6057
}
6158

62-
fun fromString(agentName: String): BuiltinCommand? {
63-
return values().find { it.commandName == agentName }
64-
}
59+
fun fromString(agentName: String): BuiltinCommand? = values().find { it.commandName == agentName }
6560
}
6661
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/ToolHubVariable.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import com.intellij.openapi.util.NlsSafe
99
* For example, you prompt could be:
1010
* ```devin
1111
* Here is the tools you can use:
12-
* $agent
12+
* $agents
13+
* ```
14+
*
15+
* Or
16+
*
17+
* ```devin
18+
* Here is the tools you can use:
19+
* $commands
1320
* ```
1421
*/
1522
enum class ToolHubVariable(val hubName: String, val type: String, val description: String) {
@@ -26,7 +33,7 @@ enum class ToolHubVariable(val hubName: String, val type: String, val descriptio
2633
/**
2734
* @param variableId should be one of the [ToolHubVariable] name
2835
*/
29-
fun lookup(myProject: Project, variableId: @NlsSafe String?): List<String> {
36+
fun lookup(myProject: Project, variableId: String?): List<String> {
3037
return when (variableId) {
3138
AGENTS.hubName -> CustomAgentConfig.loadFromProject(myProject).map {
3239
"- " + it.name + ". " + it.description

0 commit comments

Comments
 (0)