mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved marker from NotebookCellLines to NotebookCellLinesLexer
deleted commented code moved marker from NotebookCellLines to NotebookCellLinesLexer Merge-request: IJ-MR-104348 Merged-by: Georgii Zorabov <georgii.zorabov@jetbrains.com> GitOrigin-RevId: 43bb750315c9a1d21d9f690c74751a0c8f747d5f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
95c1ab65f4
commit
aea62835c6
-9
@@ -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<Marker> {
|
||||
override fun compareTo(other: Marker): Int = offset - other.offset
|
||||
}
|
||||
|
||||
enum class MarkersAtLines(val hasTopLine: Boolean, val hasBottomLine: Boolean) {
|
||||
NO(false, false),
|
||||
TOP(true, false),
|
||||
|
||||
+13
-5
@@ -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<NotebookCellLines.Marker>
|
||||
fun markerSequence(chars: CharSequence, ordinalIncrement: Int, offsetIncrement: Int): Sequence<Marker>
|
||||
|
||||
data class Marker(
|
||||
val ordinal: Int,
|
||||
val type: CellType,
|
||||
val offset: Int,
|
||||
val length: Int
|
||||
) : Comparable<Marker> {
|
||||
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<NotebookCellLines.Marker> = sequence {
|
||||
offsetIncrement: Int): Sequence<Marker> = 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<NotebookCellLines.Marker>): List<NotebookCellLines.Interval> {
|
||||
private fun defaultIntervals(document: Document, markers: List<Marker>): List<NotebookCellLines.Interval> {
|
||||
val intervals = toIntervalsInfo(document, markers)
|
||||
|
||||
val result = mutableListOf<NotebookCellLines.Interval>()
|
||||
@@ -54,7 +62,7 @@ interface NotebookCellLinesLexer {
|
||||
}
|
||||
}
|
||||
|
||||
private fun toIntervalsInfo(document: Document, markers: List<NotebookCellLines.Marker>): List<Triple<Int, CellType, MarkersAtLines>> {
|
||||
private fun toIntervalsInfo(document: Document, markers: List<NotebookCellLinesLexer.Marker>): List<Triple<Int, CellType, MarkersAtLines>> {
|
||||
val m = mutableListOf<Triple<Int, CellType, MarkersAtLines>>()
|
||||
|
||||
// add first if necessary
|
||||
|
||||
+3
-3
@@ -97,8 +97,8 @@ val NotebookCellLines.Interval.lastContentLine: Int
|
||||
val NotebookCellLines.Interval.contentLines: IntRange
|
||||
get() = firstContentLine .. lastContentLine
|
||||
|
||||
fun makeMarkersFromIntervals(document: Document, intervals: Iterable<NotebookCellLines.Interval>): List<NotebookCellLines.Marker> {
|
||||
val markers = ArrayList<NotebookCellLines.Marker>()
|
||||
fun makeMarkersFromIntervals(document: Document, intervals: Iterable<NotebookCellLines.Interval>): List<NotebookCellLinesLexer.Marker> {
|
||||
val markers = ArrayList<NotebookCellLinesLexer.Marker>()
|
||||
|
||||
fun addMarker(line: Int, type: NotebookCellLines.CellType) {
|
||||
val startOffset = document.getLineStartOffset(line)
|
||||
@@ -106,7 +106,7 @@ fun makeMarkersFromIntervals(document: Document, intervals: Iterable<NotebookCel
|
||||
if (line + 1 < document.lineCount) document.getLineStartOffset(line + 1)
|
||||
else document.getLineEndOffset(line)
|
||||
val length = endOffset - startOffset
|
||||
markers.add(NotebookCellLines.Marker(markers.size, type, startOffset, length))
|
||||
markers.add(NotebookCellLinesLexer.Marker(markers.size, type, startOffset, length))
|
||||
}
|
||||
|
||||
for (interval in intervals) {
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import org.assertj.core.api.Assertions.assertThat
|
||||
|
||||
class CodeCellLinesChecker(private val description: String,
|
||||
private val editorGetter: () -> EditorImpl) : (CodeCellLinesChecker.() -> Unit) -> Unit {
|
||||
private var markers: MutableList<NotebookCellLines.Marker>? = null
|
||||
private var markers: MutableList<NotebookCellLinesLexer.Marker>? = null
|
||||
private var intervals: MutableList<NotebookCellLines.Interval>? = 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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user