[DS-4464] added cell language providing for Jupyter files and added tests

[DS-4464] Changed intervals gen in NotebookOutputInlayControllerTest to custom because of non-backedNotebook file

[DS-4464] changed name of function in RMarkdownCellLinesTest and in CodeCellLinesChecker and fixed formatting

[DS-4464] changed name to call a proper function in each class

[DS-4464] moved CodeCellLinesChecker.IntervalsSetter.interval to CodeCellLinesChecker, made public, removed duplications

[DS-4464] reusing marker instead of creating new in markerSequence and fixed formatting in KotlinTest

[DS-4464] made markerSequence map, added property for markdownLanguage in tests and removed unused cast

[DS-4464] fixed params in markerSequence, moved intervalsGeneratorFromLexer to JupyterNotebookCellTypeAwareLexerProvider

[DS-4464] added cell language providing for Jupyter files and added tests

Merge-request: IJ-MR-105885
Merged-by: Georgii Zorabov <georgii.zorabov@jetbrains.com>

GitOrigin-RevId: 4afcad6442ac795fe1f01a5662d770a716dbb407
This commit is contained in:
Georgii Zorabov
2023-04-20 17:18:48 +00:00
committed by intellij-monorepo-bot
parent 51a371c2b5
commit 602bb2058a
2 changed files with 18 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ import org.jetbrains.plugins.notebooks.visualization.NotebookCellLines.MarkersAt
import kotlin.math.max
interface NotebookCellLinesLexer {
fun markerSequence(chars: CharSequence, ordinalIncrement: Int, offsetIncrement: Int): Sequence<Marker>
fun markerSequence(chars: CharSequence, ordinalIncrement: Int, offsetIncrement: Int, defaultLanguage: Language): Sequence<Marker>
data class Marker(
val ordinal: Int,
@@ -47,7 +47,7 @@ interface NotebookCellLinesLexer {
}
}
private fun defaultIntervals(document: Document, markers: List<Marker>): List<NotebookCellLines.Interval> {
fun defaultIntervals(document: Document, markers: List<Marker>): List<NotebookCellLines.Interval> {
val intervals = toIntervalsInfo(document, markers)
val result = mutableListOf<NotebookCellLines.Interval>()
@@ -60,12 +60,6 @@ interface NotebookCellLinesLexer {
return result
}
fun intervalsGeneratorFromLexer(lexer: NotebookCellLinesLexer): IntervalsGenerator = object : IntervalsGenerator {
override fun makeIntervals(document: Document): List<NotebookCellLines.Interval> {
val markers = lexer.markerSequence(document.charsSequence, 0, 0).toList()
return defaultIntervals(document, markers)
}
}
}
}

View File

@@ -18,9 +18,10 @@ class CodeCellLinesChecker(private val description: String,
markers = mutableListOf()
}
fun marker(cellType: NotebookCellLines.CellType, offset: Int, length: Int, language : Language? = null) {
fun marker(cellType: NotebookCellLines.CellType, offset: Int, length: Int, language: Language? = null) {
markers!!.add(
NotebookCellLinesLexer.Marker(ordinal = markers!!.size + markersStartOrdinal, type = cellType, offset = offset, length = length, language = language))
NotebookCellLinesLexer.Marker(ordinal = markers!!.size + markersStartOrdinal, type = cellType, offset = offset, length = length,
language = language))
}
}
@@ -32,9 +33,21 @@ class CodeCellLinesChecker(private val description: String,
}
class IntervalsSetter(private val list: MutableList<NotebookCellLines.Interval>, private val startOrdinal: Int) {
fun interval(cellType: NotebookCellLines.CellType, lines: IntRange, markers: NotebookCellLines.MarkersAtLines, language : Language? = null) {
fun interval(cellType: NotebookCellLines.CellType,
lines: IntRange,
markers: NotebookCellLines.MarkersAtLines,
language: Language? = null) {
list += NotebookCellLines.Interval(list.size + startOrdinal, cellType, lines, markers, language)
}
fun interval(cellType: NotebookCellLines.CellType, lines: IntRange, language: Language? = null) {
val markers =
if (cellType == NotebookCellLines.CellType.RAW && lines.first == 0)
NotebookCellLines.MarkersAtLines.NO
else
NotebookCellLines.MarkersAtLines.TOP
interval(cellType, lines, markers, language)
}
}
fun intervals(startLine: Int = 0, startOrdinal: Int = 0, handler: IntervalsSetter.() -> Unit) {