From aea62835c6f54e2c1478c4b803a481ebefd72272 Mon Sep 17 00:00:00 2001 From: Georgii Zorabov Date: Wed, 8 Mar 2023 21:36:21 +0000 Subject: [PATCH] moved marker from NotebookCellLines to NotebookCellLinesLexer deleted commented code moved marker from NotebookCellLines to NotebookCellLinesLexer Merge-request: IJ-MR-104348 Merged-by: Georgii Zorabov GitOrigin-RevId: 43bb750315c9a1d21d9f690c74751a0c8f747d5f --- .../visualization/NotebookCellLines.kt | 9 --------- .../visualization/NotebookCellLinesLexer.kt | 18 +++++++++++++----- .../NotebookVisualizationUiUtil.kt | 6 +++--- .../visualization/CodeCellLinesChecker.kt | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLines.kt b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLines.kt index 6290f5c5eda9..214a056a7fd0 100644 --- a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLines.kt +++ b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLines.kt @@ -24,15 +24,6 @@ interface NotebookCellLines { CODE, MARKDOWN, RAW } - data class Marker( - val ordinal: Int, - val type: CellType, - val offset: Int, - val length: Int - ) : Comparable { - override fun compareTo(other: Marker): Int = offset - other.offset - } - enum class MarkersAtLines(val hasTopLine: Boolean, val hasBottomLine: Boolean) { NO(false, false), TOP(true, false), diff --git a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLinesLexer.kt b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLinesLexer.kt index c78e793eb9d4..c1085757205a 100644 --- a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLinesLexer.kt +++ b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookCellLinesLexer.kt @@ -8,14 +8,22 @@ import org.jetbrains.plugins.notebooks.visualization.NotebookCellLines.MarkersAt import kotlin.math.max interface NotebookCellLinesLexer { - fun markerSequence(chars: CharSequence, ordinalIncrement: Int, offsetIncrement: Int): Sequence + fun markerSequence(chars: CharSequence, ordinalIncrement: Int, offsetIncrement: Int): Sequence + data class Marker( + val ordinal: Int, + val type: CellType, + val offset: Int, + val length: Int + ) : Comparable { + override fun compareTo(other: Marker): Int = offset - other.offset + } companion object { fun defaultMarkerSequence(underlyingLexerFactory: () -> Lexer, tokenToCellType: (IElementType) -> CellType?, chars: CharSequence, ordinalIncrement: Int, - offsetIncrement: Int): Sequence = sequence { + offsetIncrement: Int): Sequence = sequence { val lexer = underlyingLexerFactory() lexer.start(chars, 0, chars.length) var ordinal = 0 @@ -23,7 +31,7 @@ interface NotebookCellLinesLexer { val tokenType = lexer.tokenType ?: break val cellType = tokenToCellType(tokenType) if (cellType != null) { - yield(NotebookCellLines.Marker( + yield(Marker( ordinal = ordinal++ + ordinalIncrement, type = cellType, offset = lexer.currentPosition.offset + offsetIncrement, @@ -34,7 +42,7 @@ interface NotebookCellLinesLexer { } } - private fun defaultIntervals(document: Document, markers: List): List { + private fun defaultIntervals(document: Document, markers: List): List { val intervals = toIntervalsInfo(document, markers) val result = mutableListOf() @@ -54,7 +62,7 @@ interface NotebookCellLinesLexer { } } -private fun toIntervalsInfo(document: Document, markers: List): List> { +private fun toIntervalsInfo(document: Document, markers: List): List> { val m = mutableListOf>() // add first if necessary diff --git a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookVisualizationUiUtil.kt b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookVisualizationUiUtil.kt index 759ccdbb45c2..8352e747ac34 100644 --- a/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookVisualizationUiUtil.kt +++ b/notebooks/visualization/src/org/jetbrains/plugins/notebooks/visualization/NotebookVisualizationUiUtil.kt @@ -97,8 +97,8 @@ val NotebookCellLines.Interval.lastContentLine: Int val NotebookCellLines.Interval.contentLines: IntRange get() = firstContentLine .. lastContentLine -fun makeMarkersFromIntervals(document: Document, intervals: Iterable): List { - val markers = ArrayList() +fun makeMarkersFromIntervals(document: Document, intervals: Iterable): List { + val markers = ArrayList() fun addMarker(line: Int, type: NotebookCellLines.CellType) { val startOffset = document.getLineStartOffset(line) @@ -106,7 +106,7 @@ fun makeMarkersFromIntervals(document: Document, intervals: Iterable EditorImpl) : (CodeCellLinesChecker.() -> Unit) -> Unit { - private var markers: MutableList? = null + private var markers: MutableList? = null private var intervals: MutableList? = null private var markersStartOffset: Int = 0 private var markersStartOrdinal: Int = 0 @@ -19,7 +19,7 @@ class CodeCellLinesChecker(private val description: String, fun marker(cellType: NotebookCellLines.CellType, offset: Int, length: Int) { markers!!.add( - NotebookCellLines.Marker(ordinal = markers!!.size + markersStartOrdinal, type = cellType, offset = offset, length = length)) + NotebookCellLinesLexer.Marker(ordinal = markers!!.size + markersStartOrdinal, type = cellType, offset = offset, length = length)) } }