diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/ForeignFunctionProcessor.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/ForeignFunctionProcessor.kt index ec7001377..351ace621 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/ForeignFunctionProcessor.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/ForeignFunctionProcessor.kt @@ -1,7 +1,7 @@ package com.phodal.shirelang.compiler.hobbit.execute import com.intellij.openapi.project.Project -import com.phodal.shirecore.lookupFile +import com.phodal.shirecore.findFile import com.phodal.shirecore.provider.shire.FileRunService import com.phodal.shirelang.compiler.SHIRE_ERROR import com.phodal.shirelang.compiler.hobbit.function.ForeignFunction @@ -13,11 +13,7 @@ class ForeignFunctionProcessor { ): Any { val filename = func.funcPath - val virtualFile = try { - project.lookupFile(filename) ?: return "$SHIRE_ERROR: File not found: $filename" - } catch (e: Exception) { - return "$SHIRE_ERROR: File not found: $filename" - } + val virtualFile = project.findFile(filename) ?: return "$SHIRE_ERROR: File not found: $filename" val runService = FileRunService.provider(project, virtualFile) diff --git a/shirelang/src/test/kotlin/com/phodal/shirelang/ShireCompileTest.kt b/shirelang/src/test/kotlin/com/phodal/shirelang/ShireCompileTest.kt index bb41e1d14..9377d72d2 100644 --- a/shirelang/src/test/kotlin/com/phodal/shirelang/ShireCompileTest.kt +++ b/shirelang/src/test/kotlin/com/phodal/shirelang/ShireCompileTest.kt @@ -439,6 +439,16 @@ Summary webpage: ${'$'}fileName""", results["var2"].toString() } fun testShouldSupportForeignFunction() { + @Language("JavaScript") + val jsMainWithArgs = """ + const args = process.argv.slice(2); + console.log(args[0]); + + process.exit(0); + """.trimIndent() + + myFixture.addFileToProject("hello.js", jsMainWithArgs) + @Language("Shire") val code = """ --- @@ -446,7 +456,7 @@ Summary webpage: ${'$'}fileName""", results["var2"].toString() description: "Generate Summary" interaction: AppendCursor functions: - normal: "hello.py"(string) + normal: "hello.js"(string) variables: "var2": /.*ple.shire/ { normal } --- @@ -454,11 +464,6 @@ Summary webpage: ${'$'}fileName""", results["var2"].toString() Summary webpage: ${'$'}fileName """.trimIndent() val file = myFixture.addFileToProject("sample.shire", code) - - @Language("Python") - val pythonHello = """print('hello world')""" - val helloPy = myFixture.addFileToProject("hello.py", pythonHello) - myFixture.openFileInEditor(file.virtualFile) val compile = ShireSyntaxAnalyzer(project, file as ShireFile, myFixture.editor).parse() @@ -470,6 +475,6 @@ Summary webpage: ${'$'}fileName""", results["var2"].toString() } } - assertEquals(": File not found: hello.py", results["var2"].toString()) + assertEquals(": [ForeignFunctionProcessor] No run service found for file: hello.js", results["var2"].toString()) } }