Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,4 @@ interface CodeRuntime : EnabledStrategy {
fun wrapCode(code: String): String = code
fun <T : Any> wrapExecution(fn: java.util.function.Supplier<T?>): T? = fn.get()

companion object {
private class TestObject {
@Suppress("unused")
fun square(x: Int): Int = x * x
}

private interface TestInterface {
fun square(x: Int): Int
}

@JvmStatic
fun test(factory: java.util.function.Function<Map<String, Any>, CodeRuntime>) {
val testImpl = object : TestInterface {
override fun square(x: Int): Int = x * x
}
with(factory.apply(mapOf("message" to "hello"))) {
test("hello", run("message"))
}
with(factory.apply(mapOf("function" to TestObject()))) {
test(25, run("function.square(5)"))
}
with(factory.apply(mapOf("function" to testImpl))) {
test(25, run("function.square(5)"))
}
}

private fun <T : Any> test(expected: T, actual: T?) {
require(expected == actual) { actual.toString() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ object FileSelectionUtils {
rootFile: File,
maxFilesPerDir: Int = 20,
treatDocumentsAsText: Boolean = false,
fn: (File) -> Boolean = { !isLLMIgnored(it.toPath()) }
filter: (File) -> Boolean = { !isLLMIgnored(it.toPath()) },
render: (File) -> String = { it.name }
): String {
val sb = StringBuilder()
val filterFn = if (treatDocumentsAsText) {
{ file: File -> fn(file) && file.isDocumentFile() }
} else fn
{ file: File -> filter(file) && file.isDocumentFile() }
} else filter
if (!filterFn(rootFile)) {
log.debug("Skipping root file for tree: ${rootFile.absolutePath}")
return "" // Root itself doesn't match, so empty tree
Expand All @@ -31,20 +32,25 @@ object FileSelectionUtils {
entriesToConsider.forEachIndexed { index, child ->
buildAsciiSubTree(
child, "", // Initial parentContinuationPrefix for children of the root
index == entriesToConsider.size - 1, maxFilesPerDir, filterFn, sb
index == entriesToConsider.size - 1, maxFilesPerDir, filterFn, sb, render
)
}
} else {
// If rootFile is not a directory, just show its name
sb.append(rootFile.name)
sb.append(render(rootFile))
sb.appendLine()
}
return sb.toString()
}

private fun buildAsciiSubTree(
currentFile: File, parentContinuationPrefix: String, // Prefix like "│ " or " "
isLastInSiblings: Boolean, maxFilesPerDir: Int, filterFn: (File) -> Boolean, sb: StringBuilder
currentFile: File,
parentContinuationPrefix: String, // Prefix like "│ " or " "
isLastInSiblings: Boolean,
maxFilesPerDir: Int,
filterFn: (File) -> Boolean,
sb: StringBuilder,
render: (File) -> String = { it.name }
) {
if (!filterFn(currentFile)) {
// If the current file is filtered out, do not display it or its children.
Expand All @@ -53,7 +59,7 @@ object FileSelectionUtils {
}
sb.append(parentContinuationPrefix)
sb.append(if (isLastInSiblings) "└── " else "├── ")
sb.append(currentFile.name)
sb.append(render(currentFile))
if (currentFile.isDirectory) {
sb.append("/")
}
Expand Down
Loading
Loading