mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-28 19:11:03 +08:00
fix(jetbrains): submit typed file mentions
This commit is contained in:
+11
-1
@@ -48,7 +48,17 @@ class KiloPromptCompletionProvider(
|
||||
/** A file mention token at a caret/mouse offset, with whether it resolves to a real file. */
|
||||
data class MentionHit(val start: Int, val end: Int, val value: String, val resolved: Boolean)
|
||||
|
||||
fun mentionPaths(): Set<String> = paths.toSet()
|
||||
fun mentionPaths(text: String? = null): Set<String> {
|
||||
val known = paths.toSet()
|
||||
if (text == null) return known
|
||||
return mentionSpans(text).mapNotNullTo(known.toMutableSet()) { span ->
|
||||
when {
|
||||
span.value in mentionNames() -> null
|
||||
span.value in known || exists[span.value] == true -> span.value
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The file mention spanning [offset], or null when the offset is outside a mention,
|
||||
|
||||
+1
-1
@@ -521,7 +521,7 @@ class PromptPanel(
|
||||
ApplicationManager.getApplication().executeOnPooledThread {
|
||||
try {
|
||||
val files = items.map { it.part() }
|
||||
val mentioned = onMentions(txt, completion?.mentionPaths().orEmpty())
|
||||
val mentioned = onMentions(txt, completion?.mentionPaths(txt).orEmpty())
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
submitting = false
|
||||
if (project.isDisposed) return@invokeLater
|
||||
|
||||
+10
@@ -308,6 +308,16 @@ class KiloPromptCompletionProviderTest : BasePlatformTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
fun `test mentionPaths includes existing hand typed mentions from text`() {
|
||||
var done = false
|
||||
rpc.fileResolver = { path -> if (path == "src/x.kt") listOf(file(path)) else emptyList() }
|
||||
|
||||
provider.validate("see @src/x.kt and ${MentionAction.GIT_CHANGES.token}", -1) { done = true }
|
||||
waitFor { done }
|
||||
|
||||
assertEquals(setOf("src/x.kt"), provider.mentionPaths("see @src/x.kt and ${MentionAction.GIT_CHANGES.token}"))
|
||||
}
|
||||
|
||||
fun `test mention under caret is not flagged`() {
|
||||
assertTrue(provider.highlights("@nope", caret = 5).isEmpty())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user