Skip to content

Commit

Permalink
feat(shirelang): add crawl functionality and processor support #59
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 24, 2024
1 parent 26fd92a commit ee5a3ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import com.intellij.openapi.util.TextRange
/**
* Don't remove public modifier, it's required Kotlin compile, in IDEA will failed.
*/
public typealias PostFunction = (response: String?, textRange: TextRange?) -> Unit
public typealias PostFunction = (response: String?, textRange: TextRange?) -> Unit

Check warning on line 8 in core/src/main/kotlin/com/phodal/shirecore/config/interaction/PostFunction.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant visibility modifier

Redundant visibility modifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.phodal.shirelang.compiler.hobbit.execute

import com.intellij.openapi.application.runInEdt
import com.phodal.shirecore.agent.agenttool.browse.BrowseTool
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.runBlocking

object CrawlProcessor {
suspend fun doExecute(url: String): String? {

Check warning on line 9 in shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/CrawlProcessor.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant 'suspend' modifier

Redundant 'suspend' modifier
var body: String? = null
runInEdt {
val parse = BrowseTool.parse(url)
body = parse.body
}

return body
}

fun crawl(urls: Array<out String>): List<String> {
return runBlocking {
coroutineScope {
urls.mapNotNull {
doExecute(it)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ open class PatternFuncProcessor(open val myProject: Project, open val hole: Hobb
is PatternActionFunc.Redact -> {
RedactProcessor.redact(myProject, lastResult)
}
is PatternActionFunc.Crawl -> {
CrawlProcessor.crawl(action.urls)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ object HobbitHoleParser {
PatternActionFunc.Redact(first)
}

"crawl" -> {

Check warning on line 610 in shirelang/src/main/kotlin/com/phodal/shirelang/compiler/parser/HobbitHoleParser.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

'when' branch is never reachable
PatternActionFunc.Crawl(*args.toTypedArray())
}

null -> {
logger.warn("parsePatternAction, Unknown pattern action: ${expr.funcCall}")
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ sealed class PatternActionFunc(open val funcName: String) {
*/
class Redact(val strategy: String) : PatternActionFunc("redact")

Check notice on line 146 in shirelang/src/main/kotlin/com/phodal/shirelang/compiler/patternaction/PatternActionFunc.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'strategy' could be private

/**
* The Crawl function is used to crawl a list of urls, get markdown from html and save it to a file.
*
* @param urls The urls to crawl.
*/
class Crawl(vararg val urls: String) : PatternActionFunc("crawl")

/**
* User Custom Functions
*/
Expand Down

0 comments on commit ee5a3ea

Please sign in to comment.