~/bend-docscommunity

src/lsp/enc.bend checks

raw source on the hub · import 0x013e0f9a479bbebad5ed196725eede95/src/lsp/enc.bend as Enc

lsp/enc: position encodings (LSP 3.17 positionEncoding), the one place a character offset crosses the protocol boundary. Pure. bolt counts columns in code points (a Bend String is a list of them); a client that offers utf-32 gets exactly those, and any other gets UTF-16 code units, where a char outside the Basic Multilingual Plane counts 2. Every position the server reads goes through into, and every one it sends through out (proto.bend's position, semantic.bend's tokens).

4 imports
import Base
import ../lazy/lazy.bend as Lazy
import 0x81c67699424929b5c44cd8577e18117f/main.bend as Ezjson
import 0x81c67699424929b5c44cd8577e18117f/src/value.bend as J

Types

type Enc source · line 14 · raw

Data

the encodings the server speaks

type Cols source · line 150 · raw

Data

a document as the boundary sees it: the encoding its columns convert by and the text's lines

Definitions

def name source · line 19 · raw

@ee:Enc -> String

an encoding's name on the wire

def offers source · line 28 · raw

@cells:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> Bool

does a list of encodings (JSON cells) offer utf-32? A cell that is not a string offers nothing

def cells source · line 37 · raw

@jj:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> 0x81c67699424929b5c44cd8577e18117f/src/value.Json

the cells of an array, JNil when it is not one

def chosen source · line 45 · raw

@yes:Bool -> Enc

the encoding for utf-32 offered or not

def negotiate source · line 54 · raw

@params:0x81c67699424929b5c44cd8577e18117f/src/value.Json -> Enc

the encoding initialize settles on: utf-32 when the client's general.positionEncodings offers it, else UTF-16, LSP's default

def wide source · line 61 · raw

@cc:Char -> Bool

does a char take two UTF-16 code units (it lies past U+FFFF)?

def units.step source · line 65 · raw

@isw:Bool -> @rest:Nat -> Nat

the units a char and the ones after it take: two for a wide char, else one

def units source · line 74 · raw

@cs:List<&2, Char> -> @nn:Nat -> Nat

the UTF-16 code units the first n chars of a line take; a column past the line's end counts one unit a column

def points.skip source · line 85 · raw

@isw:Bool -> @pp:Nat -> Nat

the units left after a char, from 1+p units: p after a narrow one, one fewer after a wide one (none when the offset falls inside its pair)

def points source · line 97 · raw

@cs:List<&2, Char> -> @uu:Nat -> Nat

the chars the first u UTF-16 code units of a line cover; an offset inside a pair covers its char, and one past the line's end counts one column a unit

def out.of source · line 107 · raw

@ee:Enc -> @cs:List<&2, Char> -> @nn:Nat -> Nat

a code-point column of a line in an encoding

def into.of source · line 115 · raw

@ee:Enc -> @cs:List<&2, Char> -> @uu:Nat -> Nat

an encoding's column of a line as a code-point column

def wide_in source · line 123 · raw

@cs:List<&2, Char> -> Bool

does a line hold a char past U+FFFF? Stops at the first

def wide_any source · line 131 · raw

@lines:List<&2, String> -> Bool

does any line hold one? Stops at the first

def narrowed source · line 141 · raw

@ee:Enc -> @wide:Bool -> Enc

the encoding a document's columns convert by: UTF-16 on lines with no wide char counts exactly as utf-32 does (LAWS.bend's enc_narrow), so such a document converts as utf-32 and never looks a line up

def cols.of source · line 154 · raw

@ee:Enc -> @+lines:List<&2, String> -> Cols

a document's lines under an encoding

def cols source · line 158 · raw

@ee:Enc -> @text:String -> Cols

a document's text under an encoding

def chars source · line 162 · raw

@lines:List<&2, String> -> @line:U32 -> List<&2, Char>

a line's chars, none past the end

def out.col source · line 166 · raw

@ee:Enc -> @cs:List<&2, Char> -> @col:U32 -> U32

a code-point column of a line's chars, sent in an encoding

def out.at source · line 175 · raw

@ee:Enc -> @lines:List<&2, String> -> @line:U32 -> @col:U32 -> U32

a code-point column of a document's line, sent in an encoding; utf-32 never looks the line up

def out source · line 183 · raw

@cc:Cols -> @line:U32 -> @col:U32 -> U32

a code-point column sent in the negotiated encoding

def into.col source · line 188 · raw

@ee:Enc -> @cs:List<&2, Char> -> @col:U32 -> U32

a column of a line's chars read in an encoding, as a code-point column

def into.at source · line 197 · raw

@ee:Enc -> @lines:List<&2, String> -> @line:U32 -> @col:U32 -> U32

a column of a document's line read in an encoding; utf-32 never looks the line up

def into source · line 205 · raw

@cc:Cols -> @line:U32 -> @col:U32 -> U32

a column read in the negotiated encoding, as a code-point column