Skip to content

Commit 1963b9d

Browse files
committed
fix(tests): add updateCustomFormat import to CustomLLMProviderTest
1 parent edfd55a commit 1963b9d

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,25 @@ enum class BuiltinCommand(
159159

160160
suspend fun fromString(commandName: String): BuiltinCommand? {
161161
val builtinCommand = entries.find { it.commandName == commandName }
162-
if (builtinCommand == null) {
163-
val providerName = toolchainProviderName(commandName)
164-
val provider = ToolchainFunctionProvider.lookup(providerName)
165-
if (provider != null) {
166-
return TOOLCHAIN_COMMAND
167-
}
162+
if (builtinCommand != null) {
163+
return builtinCommand
164+
}
168165

169-
ToolchainFunctionProvider.all().forEach {
170-
if (it.funcNames().contains(commandName)) {
171-
return TOOLCHAIN_COMMAND
172-
}
173-
}
166+
val providerName = toolchainProviderName(commandName)
167+
val provider = ToolchainFunctionProvider.lookup(providerName)
168+
if (provider != null) {
169+
return TOOLCHAIN_COMMAND
170+
}
174171

175-
val project = ProjectManager.getInstance().openProjects.first()
176-
AutoDevNotifications.warn(project, "Command not found: $commandName")
177-
return null
172+
ToolchainFunctionProvider.all().forEach {
173+
if (it.funcNames().contains(commandName)) {
174+
return TOOLCHAIN_COMMAND
175+
}
178176
}
179177

180-
return builtinCommand
178+
val project = ProjectManager.getInstance().openProjects.first()
179+
AutoDevNotifications.warn(project, "Command not found: $commandName")
180+
return null
181181
}
182182

183183
fun toolchainProviderName(commandName: String): String {

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.intellij.openapi.diagnostic.logger
2121
import com.intellij.openapi.editor.Editor
2222
import com.intellij.openapi.project.Project
2323
import com.intellij.openapi.project.guessProjectDir
24-
import com.intellij.openapi.util.NlsSafe
2524
import com.intellij.psi.PsiElement
2625
import com.intellij.psi.util.elementType
2726
import kotlinx.coroutines.Dispatchers
@@ -59,6 +58,7 @@ class DevInsCompiler(
5958

6059
output.append(text)
6160
}
61+
6262
DevInTypes.USED -> processUsed(it as DevInUsed)
6363
DevInTypes.COMMENTS -> {
6464
if (text.startsWith("[flow]:")) {
@@ -74,6 +74,7 @@ class DevInsCompiler(
7474
}
7575
}
7676
}
77+
7778
else -> {
7879
output.append(text)
7980
logger.warn("Unknown element type: ${it.elementType}")
@@ -129,7 +130,7 @@ class DevInsCompiler(
129130
return
130131
}
131132

132-
val propText = runReadAction { propElement?.text } ?: ""
133+
val propText = runReadAction { propElement?.text } ?: ""
133134
processingCommand(command, propText, used, fallbackText = usedText, originCmdName)
134135
}
135136

@@ -176,13 +177,13 @@ class DevInsCompiler(
176177
prop: String,
177178
used: DevInUsed,
178179
fallbackText: String,
179-
originCmdName: @NlsSafe String
180+
originCmdName: String
180181
) {
181182
val command: InsCommand = toInsCommand(commandNode, prop, used, originCmdName)
182183

183184
val execResult = command.execute()
184185

185-
val isSucceed = execResult?.contains("$DEVINS_ERROR") == false
186+
val isSucceed = execResult?.contains(DEVINS_ERROR) == false
186187
val result = if (isSucceed) {
187188
val hasReadCodeBlock = commandNode in listOf(
188189
BuiltinCommand.WRITE,
@@ -206,7 +207,12 @@ class DevInsCompiler(
206207
output.append(result)
207208
}
208209

209-
suspend fun toInsCommand(commandNode: BuiltinCommand, prop: String, used: DevInUsed, originCmdName: String): InsCommand = when (commandNode) {
210+
suspend fun toInsCommand(
211+
commandNode: BuiltinCommand,
212+
prop: String,
213+
used: DevInUsed,
214+
originCmdName: String
215+
): InsCommand = when (commandNode) {
210216
BuiltinCommand.FILE -> {
211217
FileInsCommand(myProject, prop)
212218
}
@@ -362,12 +368,12 @@ class DevInsCompiler(
362368

363369
val result = try {
364370
val cmd = runReadAction { used.text.removePrefix("/") }
365-
provider.execute(myProject!!, prop, args, emptyMap(), cmd).toString()
371+
provider.execute(myProject, prop, args, emptyMap(), cmd).toString()
366372
} catch (e: Exception) {
367373
logger<DevInsCompiler>().warn(e)
368374
val text = runReadAction { used.text }
369375
val error = "Error executing toolchain function: $text + $prop"
370-
AutoDevNotifications.notify(myProject!!, error)
376+
AutoDevNotifications.notify(myProject, error)
371377
error
372378
}
373379

@@ -414,7 +420,7 @@ class DevInsCompiler(
414420
companion object {
415421
suspend fun transpileCommand(file: DevInFile): List<BuiltinCommand> {
416422
val children = runReadAction { file.children }
417-
val result = children.mapNotNull { it ->
423+
return children.mapNotNull { it ->
418424
when (it.elementType) {
419425
DevInTypes.USED -> {
420426
val used = it as DevInUsed
@@ -431,14 +437,14 @@ class DevInsCompiler(
431437

432438
command
433439
}
440+
434441
else -> null
435442
}
436443
}
444+
437445
else -> null
438446
}
439447
}
440-
441-
return result
442448
}
443449
}
444450
}

0 commit comments

Comments
 (0)