Skip to content

Commit

Permalink
feat(shirelang): add ShireToolchainFunctionProvider and update GitFun…
Browse files Browse the repository at this point in the history
…ctionProvider #112

Added a new ShireToolchainFunctionProvider class to handle Shire toolchain functions. This provider supports built-in functions, variables, and processes in Shire. Also, updated the GitFunctionProvider to use 'entries' instead of 'values' for function name matching.
  • Loading branch information
phodal committed Sep 30, 2024
1 parent 5c718b9 commit 90a962f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.phodal.shirelang.provider

import com.intellij.openapi.project.Project
import com.phodal.shirecore.provider.function.ToolchainFunctionProvider

enum class ShireProvideType(val type: String) {
Variable("variable"),
Function("function"),
Process("process")
;

companion object {
fun fromString(value: String): ShireProvideType? {
return entries.firstOrNull { it.type == value }
}
}
}

enum class ShireToolchainFunction(val funName: String) {
/**
* The provider function offers, Built-in functions in Shire, Built-in variables in Shire, Built-in processes in Shire
* for example: `provider("variable")` will return all variables in tables
*/
Provider("provider");

companion object {
fun fromString(value: String): ShireToolchainFunction? {
return entries.firstOrNull { it.funName == value }
}
}
}

class ShireToolchainFunctionProvider : ToolchainFunctionProvider {
override fun isApplicable(project: Project, funcName: String): Boolean {
return ShireToolchainFunction.entries.any { it.funName == funcName }
}

override fun execute(project: Project, funcName: String, args: List<Any>, allVariables: Map<String, Any?>): Any {
val gitFunc = ShireToolchainFunction.fromString(funcName)
?: throw IllegalArgumentException("Shire[Toolchain]: Invalid Toolchain function name")

return when (gitFunc) {
ShireToolchainFunction.Provider -> {
val type = args.first() as String
when (ShireProvideType.fromString(type)) {
ShireProvideType.Variable -> {
return allVariables
}

ShireProvideType.Function -> {
return emptyList<Any>()
}

ShireProvideType.Process -> {
return emptyList<Any>()
}

null -> TODO()
}
}
}
}
}
2 changes: 2 additions & 0 deletions shirelang/src/main/resources/com.phodal.shirelang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,7 @@
implementationClass="com.phodal.shirelang.provider.ShirePsiVariableProvider"/>
<shireLanguageToolchainProvider language="Shire"
implementationClass="com.phodal.shirelang.provider.ShireLanguageToolchainProvider"/>

<shireToolchainFunctionProvider implementation="com.phodal.shirelang.provider.ShireToolchainFunctionProvider"/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ enum class GitFunction(val funName: String) {

companion object {
fun fromString(value: String): GitFunction? {
return values().firstOrNull { it.funName == value }
return entries.firstOrNull { it.funName == value }
}
}
}

class GitFunctionProvider : ToolchainFunctionProvider {
override fun isApplicable(project: Project, funcName: String): Boolean {
return GitFunction.values().any { it.funName == funcName }
return GitFunction.entries.any { it.funName == funcName }
}

override fun execute(project: Project, funcName: String, args: List<Any>, allVariables: Map<String, Any?>): Any {
Expand Down

0 comments on commit 90a962f

Please sign in to comment.