Skip to content

Commit 741f071

Browse files
committed
createFiles show file list ok
1 parent fd07593 commit 741f071

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

src/main/scala/functorcoder/actions/Commands.scala

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@ object Commands {
7171
case Some(value) =>
7272
// split the path
7373
val pathParts = value.split("/")
74-
// generate the full path for parent and 1 to 5 levels up
74+
// generate parent path for and 1 to 5 levels up
7575
val parentPaths =
7676
(1 to 5).map { i =>
7777
pathParts.take(pathParts.length - i).mkString("/")
7878
}
79-
showMessageAndLog(
80-
"parent paths: " + parentPaths.mkString(", ")
81-
)
79+
8280
quickPick.createQuickPick(
8381
title = "create files/folders",
8482
placeHolder = "select a parent folder",
@@ -90,26 +88,37 @@ object Commands {
9088
// create the files and folders according to the tree
9189
showMessageAndLog("creating files in: " + path)
9290
quickPick.createInputBox(
93-
title = "Create files/folders description",
91+
title = "Create files/folders under " + path,
9492
placeHolder = "describe your project",
9593
onInput = { input =>
9694
val respFuture = llm.sendPrompt(functorcoder.llm.llmPrompt.CreateFiles(input))
9795
respFuture.foreach { response =>
9896
// parse the response to a tree of files and folders
99-
val tree = treeParse.parse(response)
100-
showMessageAndLog("current directory: " + currDir)
97+
val treeOpt = treeParse.parse(response)
98+
val filesList = treeOpt.map(createFiles.tree2list).getOrElse(Seq()).mkString(", ")
10199

102100
quickPick.createQuickPick(
103101
title = "Files and Folders",
104102
placeHolder = "select to apply creating files and folders",
105103
items = Seq(
106104
(
107-
"files created!",
105+
s"create $filesList",
108106
"",
109107
{ () =>
108+
treeOpt match {
109+
case scala.util.Success(tree) =>
110+
createFiles.createFilesAndFolders(
111+
tree,
112+
path
113+
)
114+
case scala.util.Failure(exception) =>
115+
showMessageAndLog(
116+
s"Failed to parse tree: ${treeOpt.toString}, exception: ${exception.getMessage}"
117+
)
118+
}
110119
// create the files and folders according to the tree
111-
tree.toString
112-
showMessageAndLog("files created!")
120+
121+
// showMessageAndLog("files created!")
113122
}
114123
)
115124
)

src/main/scala/functorcoder/actions/createFiles.scala

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object createFiles {
3232

3333
treeParse.parse(promptResponse) match {
3434
case scala.util.Success(tree) =>
35-
createFilesAndFolders(tree)
35+
createFilesAndFolders(tree, "")
3636
case scala.util.Failure(exception) =>
3737
showMessageAndLog(s"Trying again with $retry retries left")
3838
if (retry > 0) {
@@ -47,12 +47,26 @@ object createFiles {
4747
* @param tree
4848
* the tree of files and folders
4949
*/
50-
def createFilesAndFolders(tree: TreeNode[String]): Unit = {
50+
def createFilesAndFolders(tree: TreeNode[String], parentPath0: String): Unit = {
5151
// recursively create files and folders
5252
showMessageAndLog(s"Files and folders tree: $tree")
5353
val TreeNode(root, children) = tree
54+
val parentPath: String = parentPath0 + "/" + root
55+
5456
children.foreach { child =>
55-
createFilesAndFolders(child)
57+
val file = child.value
58+
showMessageAndLog(s"Creating file in $parentPath, file: $file")
59+
createFilesAndFolders(child, parentPath)
60+
}
61+
}
62+
63+
def tree2list(tree: TreeNode[String]): Seq[String] = {
64+
val TreeNode(root, children) = tree
65+
val childList = children.flatMap(tree2list)
66+
if (childList.isEmpty) {
67+
Seq(root)
68+
} else {
69+
Seq(root) ++ childList
5670
}
5771
}
5872
}

src/main/scala/functorcoder/llm/wk.worksheet.sc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import functorcoder.llm.llmPrompt
22
import functorcoder.llm.llmPrompt.Prompt
33
import scala.collection.mutable.ArrayBuffer
44
import functorcoder.algo.treeParse
5+
import functorcoder.actions.createFiles.*
56

67
val Modification = llmPrompt
78
.Modification(code = "val x = 1", taskRequirement = "add documentation")
@@ -28,3 +29,5 @@ TreeNode("root", ArrayBuffer())
2829

2930
val input = "(root [(folder1 [(file1 file2) folder2]) folder3])"
3031
val tree = treeParse.parse(input)
32+
33+
tree2list(tree.get)

src/main/scala/vscextension/quickPick.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ object quickPick {
4040
modifieF(quickPick)
4141
quickPick.buttons = js.Array(vscode.QuickInputButtons.Back)
4242

43-
quickPick.items = items.toJSArray.map { (itemStr, itemDesc, _) => //
43+
quickPick.items = items.map { (itemStr, itemDesc, _) => //
4444
vscode
4545
.QuickPickItem(itemStr)
4646
.setAlwaysShow(true)
4747
.setButtons(js.Array(vscode.QuickInputButtons.Back))
48-
.setDescription(itemStr)
4948
.setDetail(itemDesc)
50-
}
49+
}.toJSArray
5150

5251
quickPick.onDidChangeSelection { selection =>
5352
println(s"selected: ${selection(0).label}")

0 commit comments

Comments
 (0)