Skip to content

Commit

Permalink
chore: init for python
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 27, 2023
1 parent 27caa2f commit df2c429
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cc.unitmesh.pick.worker.lang

import cc.unitmesh.pick.ext.CodeDataStructUtil
import cc.unitmesh.pick.ext.buildSourceCode
import cc.unitmesh.pick.worker.WorkerContext
import cc.unitmesh.pick.worker.base.LangWorker
import cc.unitmesh.pick.worker.job.InstructionFileJob
import chapi.ast.kotlinast.KotlinAnalyser
import chapi.ast.typescriptast.TypeScriptAnalyser
import org.slf4j.Logger

class PythonWorker(override val context: WorkerContext) : LangWorker {
override val jobs: MutableList<InstructionFileJob> = mutableListOf()

override val fileTree: HashMap<String, InstructionFileJob> = hashMapOf()
override val logger: Logger = org.slf4j.LoggerFactory.getLogger(PythonWorker::class.java)

val extLength = ".pyt".length

override fun prepareJob(job: InstructionFileJob) {
this.jobs.add(job)

try {
val container = TypeScriptAnalyser().analysis(job.code, job.fileSummary.location)
job.codeLines = job.code.lines()
container.DataStructures.map { ds ->
ds.Imports = container.Imports

ds.Content = CodeDataStructUtil.contentByPosition(job.codeLines, ds.Position)
ds.Functions.map {
it.apply {
it.Content = CodeDataStructUtil.contentByPosition(job.codeLines, it.Position)
}
}
}

job.container = container
} catch (e: Exception) {
e.printStackTrace()
}
}
}

0 comments on commit df2c429

Please sign in to comment.