Skip to content

Commit 0b4d253

Browse files
committedSep 30, 2024··
refactor(provider): Rename 'Process' to 'Lifecycle' and optimize variable and function retrieval #112
Update the ShireToolchainFunctionProvider to reflect the rename of 'Process' to 'Lifecycle'. This change also enhances the retrieval of built-in variables and functions, improving performance and maintainability.
1 parent 90a962f commit 0b4d253

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed
 

‎shirelang/src/main/kotlin/com/phodal/shirelang/compiler/patternaction/PatternActionFunc.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,15 @@ sealed class PatternActionFunc(val type: PatternActionFuncType) {
198198
private val logger = logger<PatternActionFunc>()
199199

200200
fun findDocByName(funcName: String?): String? {
201-
return PatternActionFuncType.values().find { it.funcName == funcName }?.description
201+
return PatternActionFuncType.entries.find { it.funcName == funcName }?.description
202+
}
203+
204+
fun all(): List<PatternActionFuncType> {
205+
return PatternActionFuncType.entries
202206
}
203207

204208
fun from(funcName: String, args: List<String>): PatternActionFunc? {
205-
return when (PatternActionFuncType.values().find { it.funcName == funcName }) {
209+
return when (PatternActionFuncType.entries.find { it.funcName == funcName }) {
206210
PatternActionFuncType.GREP -> {
207211
if (args.isEmpty()) {
208212
logger.error("parsePatternAction, grep requires at least 1 argument")

‎shirelang/src/main/kotlin/com/phodal/shirelang/compiler/variable/CompositeVariableProvider.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ object CompositeVariableProvider {
1717
fun all(): List<VariableDisplay> {
1818
val results = mutableListOf<VariableDisplay>()
1919

20-
ContextVariable.values().forEach {
20+
ContextVariable.entries.forEach {
2121
results.add(VariableDisplay(it.variableName, it.description, 99.0))
2222
}
2323

24-
PsiContextVariable.values().forEach {
24+
PsiContextVariable.entries.forEach {
2525
results.add(VariableDisplay(it.variableName, it.description ?: "", 90.0))
2626
}
2727

28-
VcsToolchainVariable.values().forEach {
28+
VcsToolchainVariable.entries.forEach {
2929
results.add(VariableDisplay(it.variableName, it.description, 80.0))
3030
}
3131

32-
DatabaseToolchainVariable.values().forEach {
32+
DatabaseToolchainVariable.entries.forEach {
3333
results.add(VariableDisplay(it.variableName, it.description, 70.0))
3434
}
3535

‎shirelang/src/main/kotlin/com/phodal/shirelang/provider/ShireToolchainFunctionProvider.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package com.phodal.shirelang.provider
22

33
import com.intellij.openapi.project.Project
44
import com.phodal.shirecore.provider.function.ToolchainFunctionProvider
5+
import com.phodal.shirelang.compiler.patternaction.PatternActionFunc
6+
import com.phodal.shirelang.compiler.variable.CompositeVariableProvider
57

68
enum class ShireProvideType(val type: String) {
79
Variable("variable"),
810
Function("function"),
9-
Process("process")
11+
Lifecycle("lifecycle")
1012
;
1113

1214
companion object {
@@ -18,7 +20,7 @@ enum class ShireProvideType(val type: String) {
1820

1921
enum class ShireToolchainFunction(val funName: String) {
2022
/**
21-
* The provider function offers, Built-in functions in Shire, Built-in variables in Shire, Built-in processes in Shire
23+
* The provider function offers, Built-in functions in Shire, Built-in variables in Shire, lifecycle in Shire
2224
* for example: `provider("variable")` will return all variables in tables
2325
*/
2426
Provider("provider");
@@ -44,15 +46,15 @@ class ShireToolchainFunctionProvider : ToolchainFunctionProvider {
4446
val type = args.first() as String
4547
when (ShireProvideType.fromString(type)) {
4648
ShireProvideType.Variable -> {
47-
return allVariables
49+
CompositeVariableProvider.all()
4850
}
4951

5052
ShireProvideType.Function -> {
51-
return emptyList<Any>()
53+
PatternActionFunc.all()
5254
}
5355

54-
ShireProvideType.Process -> {
55-
return emptyList<Any>()
56+
ShireProvideType.Lifecycle -> {
57+
emptyList()
5658
}
5759

5860
null -> TODO()

0 commit comments

Comments
 (0)
Please sign in to comment.