Skip to content

Commit 82ac345

Browse files
committed
Implement support for enum_getreverseindex command
1 parent aa989c0 commit 82ac345

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
- Add inspection and quick fix for unused local variables.
88
- Add varchook to valid types.
9+
- Implement support for enum_getreverseindex command.
910

1011
### Changed
12+
1113
- Update to IntelliJ 2024.1.
1214

1315
## [1.5.0] - 2023-11-27

src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/CommandHandler.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,38 @@ data object EnumCommandHandler : CommandHandler {
186186
o.type = outputType ?: RsErrorType
187187
}
188188
}
189+
190+
191+
data object EnumGetReverseIndexCommandHandler : CommandHandler {
192+
override fun RsTypeInferenceVisitor.inferTypes(
193+
reference: RsScript,
194+
o: RsCommandExpression
195+
) {
196+
val arguments = o.argumentList.expressionList
197+
var outputType: RsType? = null
198+
if (arguments.size >= 1) {
199+
arguments[0].typeHint = RsTypeType
200+
arguments[0].accept(this)
201+
if (arguments[0] is RsDynamicExpression) {
202+
outputType = RsPrimitiveType.lookupReferencableOrNull(arguments[0].text) ?: RsErrorType
203+
}
204+
}
205+
var inputType: RsType? = null
206+
if (arguments.size >= 2) {
207+
arguments[1].typeHint = RsTypeType
208+
arguments[1].accept(this)
209+
if (arguments[1] is RsDynamicExpression) {
210+
inputType = RsPrimitiveType.lookupReferencableOrNull(arguments[1].text) ?: RsErrorType
211+
}
212+
}
213+
val parameterTypes = arrayOf(
214+
RsTypeType,
215+
RsTypeType,
216+
RsPrimitiveType.ENUM,
217+
outputType ?: RsErrorType,
218+
RsPrimitiveType.INT,
219+
)
220+
checkArgumentList(o.argumentList, parameterTypes)
221+
o.type = inputType ?: RsErrorType
222+
}
223+
}

src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
685685
private fun RsScript.findCommandHandler(): CommandHandler {
686686
return when (nameLiteralList[1].text) {
687687
"enum" -> EnumCommandHandler
688+
"enum_getreverseindex" -> EnumGetReverseIndexCommandHandler
688689
"struct_param" -> ParamCommandHandler.STRUCT_PARAM
689690
"lc_param" -> ParamCommandHandler.LC_PARAM
690691
"nc_param" -> ParamCommandHandler.NC_PARAM

0 commit comments

Comments
 (0)