Skip to content

Commit

Permalink
feat(test): set for indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 28, 2023
1 parent a51f599 commit c5f4a8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Expand Up @@ -158,7 +158,7 @@ class JavaTestContextProvider : TestContextProvider() {
return false
}

if (code.contains("class ")) {
if (code.startsWith("import") && code.contains("class ")) {
return insertClassCode(sourceFile, project, code)
}

Expand Down
Expand Up @@ -42,6 +42,10 @@ class TestCodeGenTask(
private val testContextProvider = TestContextProvider.context(lang)

override fun run(indicator: ProgressIndicator) {
indicator.isIndeterminate = true
indicator.fraction = 0.1
indicator.text = AutoDevBundle.message("intentions.chat.code.test.step.prepare-context")

val testContext = testContextProvider?.findOrCreateTestFile(request.file, request.project, request.element)
if (testContext == null) {
logger<WriteTestIntention>().error("Failed to create test file for: ${request.file}")
Expand Down Expand Up @@ -72,6 +76,9 @@ class TestCodeGenTask(
prompter += it.text
}

indicator.text = AutoDevBundle.message("intentions.chat.code.test.step.collect-context")
indicator.fraction = 0.3

prompter += "\n"

val additionContextRef: Ref.ObjectRef<String> = Ref.ObjectRef()
Expand All @@ -94,14 +101,22 @@ class TestCodeGenTask(
"Start ${testContext.testClassName} with `import` syntax here: \n"
}

indicator.fraction = 0.8
indicator.text = AutoDevBundle.message("intentions.chat.code.test.step.prompt")

val flow: Flow<String> =
ConnectorFactory.getInstance().connector(request.project).stream(prompter, "")

logger<WriteTestIntention>().warn("Prompt: $prompter")

indicator.fraction = 0.9
indicator.text = AutoDevBundle.message("intentions.chat.code.test.step.write-test")

writeTestToFile(request.project, flow, testContext, testContextProvider!!)

navigateTestFile(testContext.file, request.editor, request.project)

indicator.fraction = 1.0
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -24,3 +24,7 @@ intentions.chat.code.test.family.name=Test this
intentions.assistant.name=AutoDev AI Assistant
Intention.category.llm=AutoDev LLM
intentions.assistant.popup.title=AutoDev AI Assistant
intentions.chat.code.test.step.prepare-context=Prepre context
intentions.chat.code.test.step.prompt=Prompting to LLM
intentions.chat.code.test.step.write-test=Writing testing
intentions.chat.code.test.step.collect-context=Collect prompt context

0 comments on commit c5f4a8f

Please sign in to comment.