Skip to content

Commit 3d0ad38

Browse files
committed
Update Kotlin version
Fix #185 Fix #187
1 parent 168a0ae commit 3d0ad38

File tree

8 files changed

+62
-20
lines changed

8 files changed

+62
-20
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Kotlin kernel for IPython/Jupyter
1010

11-
[Kotlin](https://kotlinlang.org/) (1.5.20-dev-5817) kernel for [Jupyter](https://jupyter.org).
11+
[Kotlin](https://kotlinlang.org/) (1.5.30-dev-454) kernel for [Jupyter](https://jupyter.org).
1212

1313
Beta version. Tested with Jupyter Notebook 6.0.3, Jupyter Lab 1.2.6 and Jupyter Console 6.1.0
1414
on Windows, Ubuntu Linux and macOS.

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# kotlinVersion=1.5.255-SNAPSHOT
2-
kotlinVersion=1.5.20-dev-5817
2+
kotlinVersion=1.5.30-dev-454
33
stableKotlinVersion=1.5.0
44
kotlinLanguageLevel=1.5
55
stableKotlinLanguageLevel=1.5

resources/notebook-extension/kernel.css

+4
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@
373373
line-height: var(--jp-private-completer-item-height);
374374
}
375375

376+
.jp-Completer-item .jp-Completer-match.jp-Completer-deprecated {
377+
text-decoration: line-through;
378+
}
379+
376380
.jp-Completer-item .jp-Completer-type {
377381
display: table-cell;
378382
box-sizing: border-box;

resources/notebook-extension/kernel.js

+5
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ define(function(){
477477
tail: info.tail,
478478
icon: info.icon,
479479
type: "introspection",
480+
deprecation: info.deprecation,
480481
from: from,
481482
to: to
482483
});
@@ -521,6 +522,10 @@ define(function(){
521522
.attr('data-color-index', typeColorIndex);
522523

523524
var matchTag = $('<span/>').text(displayText).addClass('jp-Completer-match');
525+
if (comp.deprecation != null) {
526+
matchTag.addClass('jp-Completer-deprecated');
527+
}
528+
524529
var typeTag = $('<span/>').text(tail).addClass('jp-Completer-typeExtended');
525530

526531
var opt = $('<li/>').addClass('jp-Completer-item');

src/main/kotlin/org/jetbrains/kotlinx/jupyter/message_types.kt

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ class CompleteReply(
326326
val displayText: String,
327327
val icon: String,
328328
val tail: String,
329+
val deprecation: String?,
329330
)
330331
}
331332

src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl/CompletionResult.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ abstract class CompletionResult {
4242
it.text,
4343
it.displayText,
4444
it.icon,
45-
it.tail
45+
it.tail,
46+
it.deprecationLevel?.name,
4647
)
4748
}
4849
)
4950
)
5051

5152
@TestOnly
5253
fun sortedMatches(): List<String> = matches.sorted()
54+
55+
@TestOnly
56+
fun sortedRaw(): List<SourceCodeCompletionVariant> = metadata.sortedBy { it.text }
5357
}
5458

5559
class Empty(

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/repl/ReplTests.kt

+38-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.jupyter.generateDiagnostic
1010
import org.jetbrains.kotlinx.jupyter.generateDiagnosticFromAbsolute
1111
import org.jetbrains.kotlinx.jupyter.repl.CompletionResult
1212
import org.jetbrains.kotlinx.jupyter.repl.ListErrorsResult
13+
import org.jetbrains.kotlinx.jupyter.test.getOrFail
1314
import org.jetbrains.kotlinx.jupyter.withPath
1415
import org.junit.jupiter.api.Assertions.assertTrue
1516
import org.junit.jupiter.api.Test
@@ -163,12 +164,7 @@ class ReplTests : AbstractSingleReplTest() {
163164

164165
runBlocking {
165166
repl.complete("val t = foo", 11) {
166-
result ->
167-
if (result is CompletionResult.Success) {
168-
assertEquals(arrayListOf("foobar", "foobaz"), result.sortedMatches())
169-
} else {
170-
fail("Result should be success")
171-
}
167+
assertEquals(arrayListOf("foobar", "foobaz"), it.getOrFail().sortedMatches())
172168
}
173169
}
174170
}
@@ -177,12 +173,7 @@ class ReplTests : AbstractSingleReplTest() {
177173
fun testNoCompletionAfterNumbers() {
178174
runBlocking {
179175
repl.complete("val t = 42", 10) {
180-
result ->
181-
if (result is CompletionResult.Success) {
182-
assertEquals(emptyList(), result.sortedMatches())
183-
} else {
184-
fail("Result should be success")
185-
}
176+
assertEquals(emptyList(), it.getOrFail().sortedMatches())
186177
}
187178
}
188179
}
@@ -206,11 +197,41 @@ class ReplTests : AbstractSingleReplTest() {
206197
)
207198
runBlocking {
208199
repl.complete("df.filter { c_ }", 14) { result ->
209-
if (result is CompletionResult.Success) {
210-
assertEquals(arrayListOf("c_meth_z(", "c_prop_x", "c_prop_y", "c_zzz"), result.sortedMatches())
211-
} else {
212-
fail("Result should be success")
213-
}
200+
assertEquals(
201+
arrayListOf("c_meth_z(", "c_prop_x", "c_prop_y", "c_zzz"),
202+
result.getOrFail().sortedMatches()
203+
)
204+
}
205+
}
206+
}
207+
208+
@Test
209+
fun testParametersCompletion() {
210+
eval("fun f(xyz: Int) = xyz * 2")
211+
212+
runBlocking {
213+
repl.complete("val t = f(x", 11) {
214+
assertEquals(arrayListOf("xyz = "), it.getOrFail().sortedMatches())
215+
}
216+
}
217+
}
218+
219+
@Test
220+
fun testDeprecationCompletion() {
221+
eval(
222+
"""
223+
@Deprecated("use id() function instead")
224+
fun id_deprecated(x: Int) = x
225+
""".trimIndent()
226+
)
227+
228+
runBlocking {
229+
repl.complete("val t = id_d", 12) { result ->
230+
assertTrue(
231+
result.getOrFail().sortedRaw().any {
232+
it.text == "id_deprecated(" && it.deprecationLevel == DeprecationLevel.WARNING
233+
}
234+
)
214235
}
215236
}
216237
}

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/testUtil.kt

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.kotlinx.jupyter.test
22

3+
import io.kotlintest.fail
34
import jupyter.kotlin.DependsOn
45
import jupyter.kotlin.JavaRuntime
56
import org.jetbrains.kotlinx.jupyter.CodeCellImpl
@@ -27,6 +28,7 @@ import org.jetbrains.kotlinx.jupyter.libraries.LibraryResolver
2728
import org.jetbrains.kotlinx.jupyter.libraries.Variable
2829
import org.jetbrains.kotlinx.jupyter.libraries.parseLibraryDescriptors
2930
import org.jetbrains.kotlinx.jupyter.log
31+
import org.jetbrains.kotlinx.jupyter.repl.CompletionResult
3032
import java.io.File
3133
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext
3234

@@ -91,6 +93,11 @@ fun readLibraries(basePath: String? = null): Map<String, String> {
9193
.toMap()
9294
}
9395

96+
fun CompletionResult.getOrFail(): CompletionResult.Success = when (this) {
97+
is CompletionResult.Success -> this
98+
else -> fail("Result should be success")
99+
}
100+
94101
class InMemoryLibraryResolver(
95102
parent: LibraryResolver?,
96103
initialDescriptorsCache: Map<LibraryReference, LibraryDescriptor>? = null,

0 commit comments

Comments
 (0)