Skip to content

Commit

Permalink
refactor(compiler): remove reflections dependency and implement descr…
Browse files Browse the repository at this point in the history
…iption finder

The commit removes the unused "reflections" library from the build file. Additionally, it includes a refactor of the `PatternActionFunc` class by removing the commented-out `description` method and replacing the `all` method with a more efficient `findDocByName` method. This new method provides a description for specific functions, reducing the need for reflection and improving performance.
  • Loading branch information
phodal committed Sep 6, 2024
1 parent 2c7d744 commit 88b2f73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ project(":shirelang") {
}

dependencies {
implementation("org.reflections:reflections:0.10.2")

implementation("com.nfeld.jsonpathkt:jsonpathkt:2.0.1")
implementation("org.apache.velocity:velocity-engine-core:2.3")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.phodal.shirelang.compiler.patternaction
import com.phodal.shirelang.compiler.hobbit.ast.CaseKeyValue
import com.phodal.shirelang.compiler.hobbit.ast.Statement
import com.phodal.shirelang.compiler.hobbit.ast.VariableElement
import org.reflections.Reflections
import kotlin.reflect.KClass

/**
* The `PatternActionFunc` is a sealed class in Kotlin that represents a variety of pattern action functions.
Expand Down Expand Up @@ -122,7 +120,7 @@ sealed class PatternActionFunc(open val funcName: String) {
/**
* Embedding text
*/
class Embedding( val entries: Array<String>) : PatternActionFunc("embedding")
class Embedding(val entries: Array<String>) : PatternActionFunc("embedding")

/**
* searching text
Expand Down Expand Up @@ -181,42 +179,29 @@ sealed class PatternActionFunc(open val funcName: String) {
return "$funcName(${args.joinToString(", ")})"
}
}
//
// fun description(): String {
// return when (this) {
// is Caching -> TODO()
// is Capture -> TODO()
// is CaseMatch -> TODO()
// is Cat -> TODO()
// is Crawl -> TODO()
// is Embedding -> TODO()
// is ExecuteShire -> TODO()
// is Find -> TODO()
// is From -> TODO()
// is Grep -> TODO()
// is Head -> TODO()
// is JsonPath -> TODO()
// is Notify -> TODO()
// is Print -> TODO()
// is Redact -> TODO()
// is Reranking -> TODO()
// is Searching -> TODO()
// is Sed -> TODO()
// is Select -> TODO()
// is Sort -> TODO()
// is Splitting -> TODO()
// is Tail -> TODO()
// is Thread -> TODO()
// is ToolchainFunction -> TODO()
// is Uniq -> TODO()
// is Where -> TODO()
// is Xargs -> TODO()
// }
// }

companion object {
fun all(): Set<Class<out PatternActionFunc>>? {
return Reflections("com.phodal.shirelang.compiler.patternaction").getSubTypesOf(PatternActionFunc::class.java)
fun findDocByName(funcName: String?): String? {
return when (funcName) {
"grep" -> {
"grep is a command-line utility for searching plain-text data sets for lines that match a regular expression."
}
"thread" -> {
"""
|`thread` function will run the function in a new thread
|
|Example:
|
|```shire
|---
|variables:
| "story": /any/ { thread(".shire/shell/dify-epic-story.curl.sh") | jsonpath("${'$'}.answer", true) }
|---
|```
""".trimMargin()
}
else -> null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ class ShireDocumentationProvider : AbstractDocumentationProvider() {
CompositeVariableProvider.all().find { it.name == element.text }?.description
}

ShireTypes.FUNC_NAME -> {
val funcName = element.text
PatternActionFunc.findDocByName(funcName) ?: return null
}

else -> null
}
}

// ShireTypes.FUNC_NAME -> {
// val find = PatternActionFunc.all()?.find { it.simpleName == element.text }
// }

ShireTypes.PATTERN_ACTION -> {
"Pattern action is a way to define a pattern for the agent to match. It's a JSONPath expression."
}
Expand Down

0 comments on commit 88b2f73

Please sign in to comment.