From cdb2030993939b039ed509be7fc84cd84126abfa Mon Sep 17 00:00:00 2001 From: ab5tract Date: Fri, 25 Oct 2024 23:08:14 +0200 Subject: [PATCH] Add loading of core libraries in the same way as dependencies --- .../RakudoImplementationDetailInspection.kt | 2 +- .../UndeclaredOrDeprecatedRoutineInspection.kt | 7 ++++--- .../comma/services/RakuServiceConstants.java | 4 +++- .../support/moduleDetails/DependencyDetails.kt | 11 +++++++++++ .../scripts/find-core-provided-libraries.raku | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/scripts/find-core-provided-libraries.raku diff --git a/src/main/java/org/raku/comma/inspection/inspections/RakudoImplementationDetailInspection.kt b/src/main/java/org/raku/comma/inspection/inspections/RakudoImplementationDetailInspection.kt index 6f8132f9..7de55173 100644 --- a/src/main/java/org/raku/comma/inspection/inspections/RakudoImplementationDetailInspection.kt +++ b/src/main/java/org/raku/comma/inspection/inspections/RakudoImplementationDetailInspection.kt @@ -28,7 +28,7 @@ class RakudoImplementationDetailInspection : RakuInspection() { val resolution = reference.resolve() if (excludeCall(element.callName, resolution)) { holder.registerProblem(element, - DESCRIPTION_FORMAT_METHOD.format(element.callName), + DESCRIPTION_FORMAT_METHOD.format(element.callName, "method"), ProblemHighlightType.INFORMATION) } } diff --git a/src/main/java/org/raku/comma/inspection/inspections/UndeclaredOrDeprecatedRoutineInspection.kt b/src/main/java/org/raku/comma/inspection/inspections/UndeclaredOrDeprecatedRoutineInspection.kt index a27c60e7..321918c7 100644 --- a/src/main/java/org/raku/comma/inspection/inspections/UndeclaredOrDeprecatedRoutineInspection.kt +++ b/src/main/java/org/raku/comma/inspection/inspections/UndeclaredOrDeprecatedRoutineInspection.kt @@ -18,13 +18,13 @@ class UndeclaredOrDeprecatedRoutineInspection : RakuInspection() { // Only do the analysis if the core setting symbols are available. // TODO!!! Get the CoreSettings stuff extracted working again. - val setting = element.getProject().service().symbolCache?.getCoreSettingFile() + val setting = element.getProject().service().symbolCache.getCoreSettingFile() ?: return if (setting.virtualFile.name == "DUMMY") return // Resolve the reference. val subName = element.callName - if (subName == "::") return + if (subName.startsWith("::")) return val reference = element.reference as PsiReferenceBase.Poly<*> ?: return val results = reference.multiResolve(true) @@ -52,7 +52,8 @@ class UndeclaredOrDeprecatedRoutineInspection : RakuInspection() { private fun RakuSubCallName.isValidNqp(): Boolean { if (! this.callName.startsWith("nqp::")) return false - return PsiTreeUtil.findChildrenOfType(containingFile, RakuUseStatement::class.java).any { it.moduleName == "nqp" } + return PsiTreeUtil.findChildrenOfType(containingFile, RakuUseStatement::class.java) + .any { it.moduleName == "nqp" || it.moduleName == "MONKEY-GUTS" } || this.project.service().isProjectRakudoCore() } } \ No newline at end of file diff --git a/src/main/java/org/raku/comma/services/RakuServiceConstants.java b/src/main/java/org/raku/comma/services/RakuServiceConstants.java index 40010d59..e4bc27f5 100644 --- a/src/main/java/org/raku/comma/services/RakuServiceConstants.java +++ b/src/main/java/org/raku/comma/services/RakuServiceConstants.java @@ -23,7 +23,9 @@ public class RakuServiceConstants { "NativeCall::Types", "NativeCall::Compiler::GNU", "NativeCall::Compiler::MSVC", - "Test", "Pod::To::Text", "Telemetry" + "Test", + "Pod::To::Text", + "Telemetry" ); public static final List PRAGMAS = List.of( diff --git a/src/main/java/org/raku/comma/services/support/moduleDetails/DependencyDetails.kt b/src/main/java/org/raku/comma/services/support/moduleDetails/DependencyDetails.kt index 286cc539..403cbb28 100644 --- a/src/main/java/org/raku/comma/services/support/moduleDetails/DependencyDetails.kt +++ b/src/main/java/org/raku/comma/services/support/moduleDetails/DependencyDetails.kt @@ -26,6 +26,7 @@ class DependencyDetails(private val project: Project, private val runScope: Coro // This should *only* be called by the RakuDependencyService.doInitialize() fun dependenciesToRakuFiles(state: ModuleDetailsState): Deferred { if (project.service().zef == null) return CompletableDeferred(state) + return runScope.async { fillProvidesToRakuFiles(state) } @@ -111,6 +112,16 @@ class DependencyDetails(private val project: Project, private val runScope: Coro // TODO: Do something with the notInstalled details val result = Json.decodeFromString(output) provideMap.putAll(result.pathLookup) + + val coreLocateScript = RakuUtils.getResourceAsFile("scripts/find-core-provided-libraries.raku") + ?: throw ExecutionException("Resource bundle is corrupted: locate script is missing") + val corePathCollectorScript = RakuCommandLine(sdkHome) + corePathCollectorScript.addParameter(coreLocateScript.absolutePath) + output = corePathCollectorScript.executeAndRead(null).joinToString("\n") + // TODO: Do something with the notInstalled details + val coreResult = Json.decodeFromString(output) + provideMap.putAll(coreResult.pathLookup) + return@future provideMap } catch (e: Exception) { RakuSdkUtil.reactToSdkIssue(project, "Cannot use current Raku SDK ${e.message!!}") diff --git a/src/main/resources/scripts/find-core-provided-libraries.raku b/src/main/resources/scripts/find-core-provided-libraries.raku new file mode 100644 index 00000000..8c9e5fbd --- /dev/null +++ b/src/main/resources/scripts/find-core-provided-libraries.raku @@ -0,0 +1,18 @@ + +use JSON::Fast; + +sub MAIN() { + my $repo = CompUnit::RepositoryRegistry.repository-for-name("core"); + + my %path-lookup = |$repo.installed.map(-> $d { + $d.meta.kv.map(-> $k,$v { + $k => [ $d.content($v.keys.head).IO.absolute ] + }) + }).flat; + + say to-json + %( + pathLookup => %path-lookup, + notInstalled => [] + ); +}