1
1
package org.jetbrains.kotlin.jupyter
2
2
3
3
import jupyter.kotlin.textResult
4
- import org.jetbrains.kotlin.jupyter.repl.completion.CompletionResult
5
- import org.jetbrains.kotlin.jupyter.repl.completion.KotlinCompleter
6
- import org.jetbrains.kotlin.jupyter.repl.completion.ListErrorsResult
7
- import org.jetbrains.kotlin.jupyter.repl.completion.SourceCodeImpl
4
+ import org.jetbrains.kotlin.jupyter.libraries.parseLibraryDescriptor
5
+ import org.jetbrains.kotlin.jupyter.repl.CompletionResult
6
+ import org.jetbrains.kotlin.jupyter.repl.KotlinCompleter
7
+ import org.jetbrains.kotlin.jupyter.repl.ListErrorsResult
8
+ import org.jetbrains.kotlin.jupyter.repl.SourceCodeImpl
8
9
import kotlin.script.experimental.api.ScriptDiagnostic
9
10
import kotlin.script.experimental.api.SourceCode
10
11
import kotlin.script.experimental.api.SourceCodeCompletionVariant
@@ -51,12 +52,12 @@ fun doCommandCompletion(code: String, cursor: Int): CompletionResult {
51
52
return KotlinCompleter .getResult(code, cursor, completions)
52
53
}
53
54
54
- fun runCommand (code : String , repl : ReplForJupyter ? ): Response {
55
+ fun runCommand (code : String , repl : ReplForJupyter ): Response {
55
56
val args = code.trim().substring(1 ).split(" " )
56
57
val cmd = getCommand(args[0 ]) ? : return AbortResponseWithMessage (textResult(" Failed!" ), " unknown command: $code \n to see available commands, enter :help" )
57
58
return when (cmd) {
58
59
ReplCommands .classpath -> {
59
- val cp = repl!! .currentClasspath
60
+ val cp = repl.currentClasspath
60
61
OkResponseWithMessage (textResult(" Current classpath (${cp.count()} paths):\n ${cp.joinToString(" \n " )} " ))
61
62
}
62
63
ReplCommands .help -> {
@@ -66,9 +67,16 @@ fun runCommand(code: String, repl: ReplForJupyter?): Response {
66
67
if (it.argumentsUsage != null ) s + = " \n Usage: %${it.name} ${it.argumentsUsage} "
67
68
s
68
69
}
69
- val libraries = repl?.resolverConfig?.libraries?.awaitBlocking()?.toList()?.joinToStringIndented {
70
- " ${it.first} ${it.second.link ? : " " } "
71
- }
70
+ val libraryFiles =
71
+ repl.homeDir?.resolve(LibrariesDir )?.listFiles { file -> file.isFile && file.name.endsWith(" .$LibraryDescriptorExt " ) } ? : emptyArray()
72
+ val libraries = libraryFiles.toList().mapNotNull { file ->
73
+ val libraryName = file.nameWithoutExtension
74
+ log.info(" Parsing descriptor for library '$libraryName '" )
75
+ val descriptor = log.catchAll(" Parsing descriptor for library '$libraryName ' failed" ) {
76
+ parseLibraryDescriptor(file.readText())
77
+ }
78
+ if (descriptor != null ) " $libraryName ${descriptor.link ? : " " } " else null
79
+ }.joinToStringIndented()
72
80
OkResponseWithMessage (textResult(" Commands:\n $commands \n\n Magics\n $magics \n\n Supported libraries:\n $libraries " ))
73
81
}
74
82
}
0 commit comments