Skip to content

Commit afde50d

Browse files
Joshua-Fwaleedyaseen
authored andcommitted
Add DumpCommandHandler
1 parent 9174bf3 commit afde50d

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

src/main/kotlin/io/runescript/plugin/lang/psi/refs/RsDynamicExpressionReference.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.runescript.plugin.lang.psi.RsScript
1010
import io.runescript.plugin.lang.psi.scope.RsLocalVariableResolver
1111
import io.runescript.plugin.lang.psi.scope.RsResolveMode
1212
import io.runescript.plugin.lang.psi.scope.RsScopesUtil
13+
import io.runescript.plugin.lang.psi.type.RsAnyType
1314
import io.runescript.plugin.lang.psi.type.RsPrimitiveType
1415
import io.runescript.plugin.lang.psi.type.RsType
1516
import io.runescript.plugin.lang.psi.type.trigger.RsTriggerType
@@ -65,6 +66,11 @@ class RsDynamicExpressionReference(element: RsDynamicExpression) :
6566
if (resolvedConfig != null) {
6667
return arrayOf(PsiElementResolveResult(resolvedConfig))
6768
}
69+
} else if (type == RsAnyType) {
70+
val resolvedConfig = RsSymbolIndex.lookupAny(element, elementName)
71+
if (resolvedConfig != null) {
72+
return arrayOf(PsiElementResolveResult(resolvedConfig))
73+
}
6874
}
6975

7076
// Try to resolve the element as a command reference.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.runescript.plugin.lang.psi.type
2+
3+
object RsAnyType : RsType {
4+
override val representation: String
5+
get() = "any"
6+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,29 @@ data object EnumGetReverseIndexCommandHandler : CommandHandler {
221221
o.type = inputType ?: RsErrorType
222222
}
223223
}
224+
225+
data object DumpCommandHandler : CommandHandler {
226+
override fun RsTypeInferenceVisitor.inferTypes(
227+
reference: RsScript,
228+
o: RsCommandExpression
229+
) {
230+
val arguments = o.argumentList.expressionList
231+
if (arguments.isEmpty()) {
232+
o.error("Type mismatch: '<unit>' was given but 'any...' was expected.")
233+
} else {
234+
for (argument in arguments) {
235+
argument.typeHint = RsAnyType
236+
argument.accept(this)
237+
238+
val type = argument.type
239+
if (type is RsTupleType) {
240+
argument.error("Unable to dump multi-value types: %s".format(type.representation))
241+
} else if (type == RsUnitType) {
242+
argument.error("Unable to debug expression with no return value.")
243+
}
244+
}
245+
}
246+
247+
o.type = RsPrimitiveType.STRING
248+
}
249+
}

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
@@ -725,6 +725,7 @@ private fun RsScript.findCommandHandler(): CommandHandler {
725725
"db_find_refine" -> DbFindCommandHandler.DB_FIND_REFINE
726726
"db_find_refine_with_count" -> DbFindCommandHandler.DB_FIND_REFINE_WITH_COUNT
727727
"db_getfield" -> DbGetFieldCommandHandler
728+
"dump" -> DumpCommandHandler
728729
else -> DefaultCommandHandler
729730
}
730731
}

src/main/kotlin/io/runescript/plugin/symbollang/psi/index/RsSymbolIndex.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class RsSymbolIndex : StringStubIndexExtension<RsSymSymbol>() {
3333
}
3434
}
3535

36+
fun lookupAny(context: PsiElement, name: String): RsSymSymbol? {
37+
val module = ModuleUtil.findModuleForPsiElement(context) ?: return null
38+
val scope = GlobalSearchScope.moduleScope(module)
39+
val configs = StubIndex.getElements(KEY, name, context.project, scope, RsSymSymbol::class.java)
40+
return configs.firstOrNull()
41+
}
42+
3643
val PsiFile.nameWithoutExtension: String
3744
get() {
3845
val dot = name.lastIndexOf('.')

0 commit comments

Comments
 (0)