Skip to content

Commit

Permalink
Implement support for enum_getreverseindex command
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedyaseen committed Apr 15, 2024
1 parent aa989c0 commit 82ac345
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

- Add inspection and quick fix for unused local variables.
- Add varchook to valid types.
- Implement support for enum_getreverseindex command.

### Changed

- Update to IntelliJ 2024.1.

## [1.5.0] - 2023-11-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,38 @@ data object EnumCommandHandler : CommandHandler {
o.type = outputType ?: RsErrorType
}
}


data object EnumGetReverseIndexCommandHandler : CommandHandler {
override fun RsTypeInferenceVisitor.inferTypes(
reference: RsScript,
o: RsCommandExpression
) {
val arguments = o.argumentList.expressionList
var outputType: RsType? = null
if (arguments.size >= 1) {
arguments[0].typeHint = RsTypeType
arguments[0].accept(this)
if (arguments[0] is RsDynamicExpression) {
outputType = RsPrimitiveType.lookupReferencableOrNull(arguments[0].text) ?: RsErrorType
}
}
var inputType: RsType? = null
if (arguments.size >= 2) {
arguments[1].typeHint = RsTypeType
arguments[1].accept(this)
if (arguments[1] is RsDynamicExpression) {
inputType = RsPrimitiveType.lookupReferencableOrNull(arguments[1].text) ?: RsErrorType
}
}
val parameterTypes = arrayOf(
RsTypeType,
RsTypeType,
RsPrimitiveType.ENUM,
outputType ?: RsErrorType,
RsPrimitiveType.INT,
)
checkArgumentList(o.argumentList, parameterTypes)
o.type = inputType ?: RsErrorType
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
private fun RsScript.findCommandHandler(): CommandHandler {
return when (nameLiteralList[1].text) {
"enum" -> EnumCommandHandler
"enum_getreverseindex" -> EnumGetReverseIndexCommandHandler
"struct_param" -> ParamCommandHandler.STRUCT_PARAM
"lc_param" -> ParamCommandHandler.LC_PARAM
"nc_param" -> ParamCommandHandler.NC_PARAM
Expand Down

0 comments on commit 82ac345

Please sign in to comment.