Skip to content

Commit b4e52ac

Browse files
committed
refactor: extract function for better code reuse in interal
1 parent 0b32427 commit b4e52ac

File tree

1 file changed

+30
-12
lines changed
  • unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/base

1 file changed

+30
-12
lines changed

unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/base/LangWorker.kt

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,42 @@ interface LangWorker {
8181
}
8282
}
8383

84-
val result = jobs.map { job ->
85-
val jobContext = contextFromJob(job, workerContext)
84+
val result = executeJob().map {
85+
outputFile.appendText(it.toString() + "\n")
86+
it
87+
}
8688

87-
val flatten = workerContext.codeContextStrategies.map { type ->
88-
type.builder(jobContext).build()
89-
}.flatten()
89+
return@coroutineScope result
90+
}
9091

91-
flatten.map {
92-
outputFile.appendText(it.toString() + "\n")
93-
}
92+
/**
93+
* Executes a job and returns a list of typed instructions.
94+
*
95+
* This method iterates over the list of jobs and creates a job context for each job using the provided worker context.
96+
* It then iterates over the code context strategies of the worker context and builds a list of typed instructions
97+
* using the job context and each code context strategy. The resulting list of typed instructions is flattened and returned.
98+
*
99+
* @return a list of typed instructions generated by executing the jobs
100+
*/
101+
fun executeJob(): List<TypedIns> {
102+
return jobs.map { job ->
103+
val jobContext = createJob(job, workerContext)
94104

95-
flatten
105+
workerContext.codeContextStrategies.map { type ->
106+
type.builder(jobContext).build()
107+
}.flatten()
96108
}.flatten()
97-
98-
return@coroutineScope result
99109
}
100110

101-
fun contextFromJob(job: InstructionFileJob, workerContext: WorkerContext) = JobContext(
111+
/**
112+
* Creates a JobContext object based on the given InstructionFileJob and WorkerContext.
113+
*
114+
* @param job The InstructionFileJob object representing the job to be processed.
115+
* @param workerContext The WorkerContext object containing the context information for the worker.
116+
* @return A JobContext object containing the job, quality types, file tree, output configuration, completion types,
117+
* maximum completion in one file, project context, and quality threshold.
118+
*/
119+
fun createJob(job: InstructionFileJob, workerContext: WorkerContext) = JobContext(
102120
job,
103121
workerContext.qualityTypes,
104122
fileTree,

0 commit comments

Comments
 (0)