Skip to content

Commit

Permalink
Update Kotlin version
Browse files Browse the repository at this point in the history
Fix #185
Fix #187
  • Loading branch information
ileasile committed May 10, 2021
1 parent 168a0ae commit 3d0ad38
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Kotlin kernel for IPython/Jupyter

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

Beta version. Tested with Jupyter Notebook 6.0.3, Jupyter Lab 1.2.6 and Jupyter Console 6.1.0
on Windows, Ubuntu Linux and macOS.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kotlinVersion=1.5.255-SNAPSHOT
kotlinVersion=1.5.20-dev-5817
kotlinVersion=1.5.30-dev-454
stableKotlinVersion=1.5.0
kotlinLanguageLevel=1.5
stableKotlinLanguageLevel=1.5
Expand Down
4 changes: 4 additions & 0 deletions resources/notebook-extension/kernel.css
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@
line-height: var(--jp-private-completer-item-height);
}

.jp-Completer-item .jp-Completer-match.jp-Completer-deprecated {
text-decoration: line-through;
}

.jp-Completer-item .jp-Completer-type {
display: table-cell;
box-sizing: border-box;
Expand Down
5 changes: 5 additions & 0 deletions resources/notebook-extension/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ define(function(){
tail: info.tail,
icon: info.icon,
type: "introspection",
deprecation: info.deprecation,
from: from,
to: to
});
Expand Down Expand Up @@ -521,6 +522,10 @@ define(function(){
.attr('data-color-index', typeColorIndex);

var matchTag = $('<span/>').text(displayText).addClass('jp-Completer-match');
if (comp.deprecation != null) {
matchTag.addClass('jp-Completer-deprecated');
}

var typeTag = $('<span/>').text(tail).addClass('jp-Completer-typeExtended');

var opt = $('<li/>').addClass('jp-Completer-item');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class CompleteReply(
val displayText: String,
val icon: String,
val tail: String,
val deprecation: String?,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ abstract class CompletionResult {
it.text,
it.displayText,
it.icon,
it.tail
it.tail,
it.deprecationLevel?.name,
)
}
)
)

@TestOnly
fun sortedMatches(): List<String> = matches.sorted()

@TestOnly
fun sortedRaw(): List<SourceCodeCompletionVariant> = metadata.sortedBy { it.text }
}

class Empty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.jupyter.generateDiagnostic
import org.jetbrains.kotlinx.jupyter.generateDiagnosticFromAbsolute
import org.jetbrains.kotlinx.jupyter.repl.CompletionResult
import org.jetbrains.kotlinx.jupyter.repl.ListErrorsResult
import org.jetbrains.kotlinx.jupyter.test.getOrFail
import org.jetbrains.kotlinx.jupyter.withPath
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -163,12 +164,7 @@ class ReplTests : AbstractSingleReplTest() {

runBlocking {
repl.complete("val t = foo", 11) {
result ->
if (result is CompletionResult.Success) {
assertEquals(arrayListOf("foobar", "foobaz"), result.sortedMatches())
} else {
fail("Result should be success")
}
assertEquals(arrayListOf("foobar", "foobaz"), it.getOrFail().sortedMatches())
}
}
}
Expand All @@ -177,12 +173,7 @@ class ReplTests : AbstractSingleReplTest() {
fun testNoCompletionAfterNumbers() {
runBlocking {
repl.complete("val t = 42", 10) {
result ->
if (result is CompletionResult.Success) {
assertEquals(emptyList(), result.sortedMatches())
} else {
fail("Result should be success")
}
assertEquals(emptyList(), it.getOrFail().sortedMatches())
}
}
}
Expand All @@ -206,11 +197,41 @@ class ReplTests : AbstractSingleReplTest() {
)
runBlocking {
repl.complete("df.filter { c_ }", 14) { result ->
if (result is CompletionResult.Success) {
assertEquals(arrayListOf("c_meth_z(", "c_prop_x", "c_prop_y", "c_zzz"), result.sortedMatches())
} else {
fail("Result should be success")
}
assertEquals(
arrayListOf("c_meth_z(", "c_prop_x", "c_prop_y", "c_zzz"),
result.getOrFail().sortedMatches()
)
}
}
}

@Test
fun testParametersCompletion() {
eval("fun f(xyz: Int) = xyz * 2")

runBlocking {
repl.complete("val t = f(x", 11) {
assertEquals(arrayListOf("xyz = "), it.getOrFail().sortedMatches())
}
}
}

@Test
fun testDeprecationCompletion() {
eval(
"""
@Deprecated("use id() function instead")
fun id_deprecated(x: Int) = x
""".trimIndent()
)

runBlocking {
repl.complete("val t = id_d", 12) { result ->
assertTrue(
result.getOrFail().sortedRaw().any {
it.text == "id_deprecated(" && it.deprecationLevel == DeprecationLevel.WARNING
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.jupyter.test

import io.kotlintest.fail
import jupyter.kotlin.DependsOn
import jupyter.kotlin.JavaRuntime
import org.jetbrains.kotlinx.jupyter.CodeCellImpl
Expand Down Expand Up @@ -27,6 +28,7 @@ import org.jetbrains.kotlinx.jupyter.libraries.LibraryResolver
import org.jetbrains.kotlinx.jupyter.libraries.Variable
import org.jetbrains.kotlinx.jupyter.libraries.parseLibraryDescriptors
import org.jetbrains.kotlinx.jupyter.log
import org.jetbrains.kotlinx.jupyter.repl.CompletionResult
import java.io.File
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext

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

fun CompletionResult.getOrFail(): CompletionResult.Success = when (this) {
is CompletionResult.Success -> this
else -> fail("Result should be success")
}

class InMemoryLibraryResolver(
parent: LibraryResolver?,
initialDescriptorsCache: Map<LibraryReference, LibraryDescriptor>? = null,
Expand Down

0 comments on commit 3d0ad38

Please sign in to comment.