From 9010a2c3a3872327fde7fb4447871bb21ae9df2b Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Tue, 22 Feb 2022 13:21:24 +0300 Subject: [PATCH] doc: Range datatype (#3296) --- .../protocol-language-server.md | 31 +++++++++++++++++-- .../scala/org/enso/text/editing/model.scala | 28 ++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/docs/language-server/protocol-language-server.md b/docs/language-server/protocol-language-server.md index cfcf5510e0..edf4ea06ea 100644 --- a/docs/language-server/protocol-language-server.md +++ b/docs/language-server/protocol-language-server.md @@ -983,17 +983,44 @@ struct Position { A representation of a range of text in a text file. +For example, given the function. + +``` +0|inc x = +1| x + 1 + ^^^^^^^^^ + 012345678 +``` + +The range of `inc` is + +```typescript +{ + start: { line: 0, character: 0}, + end: { line: 0, character: 3} +} +``` + +The range of `1` is + +```typescript +{ + start: { line: 1, character: 8}, + end: { line: 1, character: 9} +} +``` + #### Format ```typescript interface Range { /** - * The range's start position. + * The range's start position (inclusive). */ start: Position; /** - * The range's end position. + * The range's end position (exclusive). */ end: Position; } diff --git a/lib/scala/text-buffer/src/main/scala/org/enso/text/editing/model.scala b/lib/scala/text-buffer/src/main/scala/org/enso/text/editing/model.scala index 888a5ac538..afd9cf40cf 100644 --- a/lib/scala/text-buffer/src/main/scala/org/enso/text/editing/model.scala +++ b/lib/scala/text-buffer/src/main/scala/org/enso/text/editing/model.scala @@ -4,8 +4,8 @@ object model { /** A representation of a position in a text file. * - * @param line a line position in a document (zero-based). - * @param character a character offset + * @param line a line position in a document (zero-based) + * @param character a character offset (zero-based) */ case class Position(line: Int, character: Int) extends Ordered[Position] { @@ -26,8 +26,28 @@ object model { /** A representation of a range of text in a text file. * - * @param start the range's start position - * @param end the range's end position + * ==Example== + * Given the function. + * + * {{{ + * 0|inc x = + 1| x + 1 + * ^^^^^^^^^ + * 012345678 + * }}} + * + * The range of `inc` is + * {{{ + * Range(Position(0, 0), Position(0, 3)) + * }}} + * + * The range of `1` is + * {{{ + * Range(Position(1, 8), Position(1, 9)) + * }}} + * + * @param start the range's start position (inclusive) + * @param end the range's end position (exclusive) */ case class Range(start: Position, end: Position)