Skip to content

Commit

Permalink
fix(db): fix toolchain call issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 9, 2024
1 parent cfebc0f commit 99eb680
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.phodal.shire
pluginName = shire
pluginRepositoryUrl = https://github.com/phodal/shire
# SemVer format -> https://semver.org
pluginVersion = 0.7.3
pluginVersion = 0.7.4

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ object HobbitHoleParser {
val args = parseParameters(funcCall) ?: emptyList()
val funcName = funcCall?.funcName?.text ?: return null

// todo: handle with toolchain functions
val patternActionFunc = when (PatternActionFuncType.values().find { it.funcName == funcName }) {
PatternActionFuncType.GREP -> {
if (args.isEmpty()) {
Expand Down Expand Up @@ -652,20 +653,16 @@ object HobbitHoleParser {
}
}

PatternActionFuncType.TOOLCHAIN_FUNCTION -> PatternActionFunc.ToolchainFunction(funcName, args)

null -> {
logger.warn("parsePatternAction, Unknown pattern action: ${expr.funcCall}")
return null
}

PatternActionFuncType.FROM,
PatternActionFuncType.WHERE,
PatternActionFuncType.SELECT,
PatternActionFuncType.CASE_MATCH -> {
val funcName = funcCall.funcName.text ?: ""
PatternActionFunc.ToolchainFunction(funcName, args)
}

PatternActionFuncType.TOOLCHAIN_FUNCTION -> PatternActionFunc.ToolchainFunction(funcName, args)
else -> PatternActionFunc.ToolchainFunction(funcName, args)
}

return patternActionFunc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
result = tableNames.map {
getTable(project, it.trim())
}.flatten().toMutableList()
} else {
result = getTable(project, dbName).toMutableList()
}
}
is List<*> -> {
Expand Down Expand Up @@ -107,6 +109,18 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
}
}

is String -> {
val allTables = DatabaseSchemaAssistant.getAllTables(project)
if (first.startsWith("[") && first.endsWith("]")) {
val tableNames = first.substring(1, first.length - 1).split(",")
return tableNames.map {
DatabaseSchemaAssistant.getTableColumn(allTables.first { table -> table.name == it.trim() })
}
} else {
return DatabaseSchemaAssistant.getTableColumn(allTables.first { table -> table.name == first })
}
}

else -> {
logger<DatabaseFunctionProvider>().error("args types: ${first.javaClass}")
return "ShireError: Table function requires a data source or a list of table names"
Expand Down

0 comments on commit 99eb680

Please sign in to comment.