Skip to content

Commit

Permalink
feat(variable-resolver): add support for toolchain variables #27
Browse files Browse the repository at this point in the history
Updated the BuiltinVariableResolver to handle toolchain variables. Also, renamed the 'variable' function in ToolchainVariableProvider to 'provide' for clarity.
  • Loading branch information
phodal committed Jun 30, 2024
1 parent d59fcb8 commit fdbb4c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ToolchainVariableProvider {
private val EP_NAME: ExtensionPointName<ToolchainVariableProvider> =
ExtensionPointName("com.phodal.shireToolchainVariableProvider")

fun variable(variable: ToolchainVariable, element: PsiElement?): ToolchainVariableProvider? {
fun provide(variable: ToolchainVariable, element: PsiElement?): ToolchainVariableProvider? {
return EP_NAME.extensionList.firstOrNull {
it.isResolvable(variable, element)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.phodal.shirelang.compiler.variable

import com.intellij.openapi.diagnostic.logger
import com.intellij.psi.PsiManager
import com.phodal.shirecore.provider.variable.DefaultPsiContextVariableProvider
import com.phodal.shirecore.provider.variable.PsiContextVariableProvider
import com.phodal.shirecore.provider.variable.PsiContextVariable
import com.phodal.shirecore.provider.variable.*
import com.phodal.shirelang.compiler.variable._base.VariableResolver
import com.phodal.shirelang.compiler.variable._base.VariableResolverContext

Expand Down Expand Up @@ -33,9 +31,26 @@ class BuiltinVariableResolver(
logger<CompositeVariableResolver>().error("Failed to resolve variable: ${it.key}", e)
""
}
} else {
result[it.key] = ""

return@forEach
}

val toolchainVariable = ToolchainVariable.from(it.key)
if (toolchainVariable != null) {
val provider = ToolchainVariableProvider.provide(toolchainVariable, context.element)
if (provider != null) {
result[it.key] = try {
provider.resolveAll(toolchainVariable, context.element)
} catch (e: Exception) {
logger<CompositeVariableResolver>().error("Failed to resolve variable: ${it.key}", e)
""
}

return@forEach
}
}

result[it.key] = ""
}

return result
Expand Down

0 comments on commit fdbb4c9

Please sign in to comment.