File tree Expand file tree Collapse file tree 3 files changed +66
-1
lines changed
api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/libraries
lib/src/main/kotlin/jupyter/kotlin
src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/repl Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change
1
+ package org.jetbrains.kotlinx.jupyter.api.libraries
2
+
3
+ import java.io.File
4
+
5
+ interface RepositoryHandlerScope {
6
+ fun maven (url : String )
7
+ fun dir (dir : File )
8
+ }
9
+
10
+ interface DependencyHandlerScope {
11
+ fun implementation (coordinates : String )
12
+ fun implementation (group : String , artifact : String , version : String )
13
+ }
14
+
15
+ fun RepositoryHandlerScope.mavenCentral () = maven(" https://repo.maven.apache.org/maven2/" )
16
+ fun RepositoryHandlerScope.google () = maven(" https://dl.google.com/dl/android/maven2/" )
17
+ fun RepositoryHandlerScope.mavenLocal () = maven(" *mavenLocal" )
18
+
19
+ fun JupyterIntegration.Builder.repositories (action : RepositoryHandlerScope .() -> Unit ) {
20
+ RepositoryHandlerScopeImpl (this ).action()
21
+ }
22
+
23
+ fun JupyterIntegration.Builder.dependencies (action : DependencyHandlerScope .() -> Unit ) {
24
+ DependencyHandlerScopeImpl (this ).action()
25
+ }
26
+
27
+ private class RepositoryHandlerScopeImpl (private val builder : JupyterIntegration .Builder ) : RepositoryHandlerScope {
28
+ override fun dir (dir : File ) {
29
+ builder.repositories(dir.absolutePath)
30
+ }
31
+
32
+ override fun maven (url : String ) {
33
+ builder.repositories(url)
34
+ }
35
+ }
36
+
37
+ private class DependencyHandlerScopeImpl (private val builder : JupyterIntegration .Builder ) : DependencyHandlerScope {
38
+ override fun implementation (coordinates : String ) {
39
+ builder.dependencies(coordinates)
40
+ }
41
+
42
+ override fun implementation (group : String , artifact : String , version : String ) {
43
+ implementation(" $group :$artifact :$version " )
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ abstract class ScriptTemplateWithDisplayHelpers(
20
20
21
21
fun EXECUTE (code : String ) = host.scheduleExecution(CodeExecution (code).toExecutionCallback())
22
22
23
- fun USE (library : LibraryDefinition ) = host.addLibrary(library)
23
+ fun USE (library : LibraryDefinition ) = host.scheduleExecution { addLibrary(library) }
24
24
25
25
fun USE (builder : JupyterIntegration .Builder .() -> Unit ) {
26
26
val o = object : JupyterIntegration () {
Original file line number Diff line number Diff line change @@ -140,6 +140,26 @@ class ReplTests : AbstractSingleReplTest() {
140
140
res.sortedMatches().contains(" doyaaaaaken" )
141
141
}
142
142
143
+ @Test
144
+ fun testDependencyConfigurationAnnotationCompletion () {
145
+ eval(
146
+ """
147
+ USE {
148
+ repositories {
149
+ mavenCentral()
150
+ }
151
+ dependencies {
152
+ implementation("io.github.config4k:config4k:0.4.2")
153
+ }
154
+ }
155
+ """ .trimIndent()
156
+ )
157
+
158
+ val res = repl.completeBlocking(" import io.github." , 17 )
159
+ res.shouldBeInstanceOf<CompletionResult .Success >()
160
+ res.sortedMatches().contains(" config4k" )
161
+ }
162
+
143
163
@Test
144
164
fun testExternalStaticFunctions () {
145
165
val res = eval(
You can’t perform that action at this time.
0 commit comments