src/lsp/semantic.bend checks
raw source on the hub · import 0x013e0f9a479bbebad5ed196725eede95/src/lsp/semantic.bend as Semantic
lsp/semantic: every token of a document classified for the editor's
semantic highlighting, from the lexer's kinds and the binder's resolution.
A name's class comes from what it refers to: a parameter stays a parameter
at every use, a constructor of this file is one wherever it appears. A name
from elsewhere is read by its shape: Bool.pick a function, U32 a type,
Nil{ a constructor.
5 imports
import Base import ../lazy/lazy.bend as Lazy import ../syntax/lex.bend as Lex import ../syntax/bind.bend as Bind import ./enc.bend as Enc
Types
type Sem source · line 21 · raw
Data
a classified token: where, how long, which type of the legend
Sem@line:U32 -> @col:U32 -> @len:U32 -> @typ:U32 -> Sem
type Cursor source · line 82 · raw
Data
the binders and uses are in source order, as the tokens are: each token takes the head of either list when it sits there, so a document classifies in one pass
Cursor@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> @uses:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> Cursor
type Entry source · line 127 · raw
Data
a binder where the index keeps it: its name, position and kind
Entry@name:String -> @line:U32 -> @col:U32 -> @kind:0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind -> Entry
type Index source · line 134 · raw
Data
binders as a binary trie on the low bits of a key (a binder's line, or its name's hash), a leaf holding the entries that reach it in source order: a lookup is a walk down and a short scan, and finds what a scan of every binder from the front would, as a miss down the path is a miss everywhere
INoneIndex
ILeaf@es:List<&2, Entry> -> Index
INode@lo:Index -> @hi:Index -> Index
type Kinds source · line 248 · raw
Data
a document's binders, indexed once for every use's lookup: by position, and its items and constructors by name
Kinds@at:Index -> @named:Index -> Kinds
type Step source · line 296 · raw
Data
a token's class, when it has one, and the cursor after it
Step@typ:Maybe<&2, U32> -> @cur:Cursor -> Step
Definitions
def legend source · line 16 · raw
List<&2, String>
the legend, by index: keyword 0, function 1, type 2, enumMember 3, parameter 4, variable 5, property 6, string 7, number 8, comment 9, typeParameter 10
def upper_first source · line 25 · raw
@cs:List<&2, Char> -> Bool
does the name start with a capital?
def last_segment source · line 33 · raw
@cs:List<&2, Char> -> @+acc:List<&2, Char> -> List<&2, Char>
the last segment of a dotted name
def of_kind source · line 44 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind -> @+name:String -> U32
the legend's type for a binder of this kind (an item is a type when capitalized, else a function)
def of_maybe_kind source · line 66 · raw
@mm:Maybe<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind> -> @name:String -> U32
the type for a binder that may not have been found (a variable then)
def by_shape source · line 75 · raw
@+name:String -> @braced:Bool -> U32
a name from elsewhere: braced: a constructor; capitalized: a type; dotted: a function; else a variable
def at_head_bind source · line 86 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> @+line:U32 -> @+col:U32 -> Bool
does the next binder sit at this position?
def at_head_use source · line 94 · raw
@uses:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool
does the next use sit at this position?
def behind_bind source · line 103 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> @+line:U32 -> @+col:U32 -> Bool
a list's head is behind the token: it was never matched (a name the lexer and the binder disagree on); it is dropped so the rest can line up again
def behind_use source · line 111 · raw
@uses:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool
is the next use behind this position?
def head_bind_kind source · line 119 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> U32
the type of the next binder
def depth source · line 140 · raw
Nat
how many bits of a key the index branches on
def path source · line 144 · raw
@dd:Nat -> @+key:U32 -> List<&2, Bool>
a key's way down the index: its low bits, lowest first
def idx.es source · line 152 · raw
@ii:Index -> List<&2, Entry>
the entries at a leaf, none elsewhere
def idx.near source · line 162 · raw
@bb:Bool -> @ii:Index -> Index
the half of a node a bit goes down, empty elsewhere
def idx.join source · line 172 · raw
@bb:Bool -> @sub:Index -> @far:Index -> Index
a node whose half down a bit is sub, and the other half far
def idx.put source · line 180 · raw
@pp:List<&2, Bool> -> @+ii:Index -> @+ee:Entry -> Index
the index with an entry in front of the ones down its path
def idx.find source · line 188 · raw
@pp:List<&2, Bool> -> @ii:Index -> List<&2, Entry>
the entries at the end of a key's path
def hash source · line 196 · raw
@ss:String -> @+acc:U32 -> U32
a name's key: its chars folded, base 31
def by_line source · line 204 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> Index
every binder, keyed by its line, in source order
def by_name.one source · line 212 · raw
@+name:String -> @line:U32 -> @col:U32 -> @kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind -> @ii:Index -> Index
an item or constructor into the index by its name's key; other binders pass
def by_name source · line 222 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> Index
the file's items and constructors, keyed by name, in source order
def at.go source · line 230 · raw
@es:List<&2, Entry> -> @+line:U32 -> @+col:U32 -> Maybe<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind>
the first entry at a position, as Bind.kind_at finds it
def named.go source · line 239 · raw
@es:List<&2, Entry> -> @+name:String -> Maybe<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind>
the first entry of a name, as Bind.kind_of_item finds it
def kind_at source · line 252 · raw
@kk:Kinds -> @+line:U32 -> @col:U32 -> Maybe<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind>
the kind of the binder at a position
def kind_of_item source · line 257 · raw
@kk:Kinds -> @+name:String -> Maybe<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.BindKind>
the kind of an item or constructor of the file, by name
def of_target source · line 262 · raw
@tg:0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Target -> @all:Kinds -> @name:String -> @braced:Bool -> U32
the type of a use, from what it refers to
def head_use_class source · line 272 · raw
@uses:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> @all:Kinds -> @braced:Bool -> U32
the type of the next use
def tail_binds source · line 280 · raw
@binds:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bind>
the binders after the next
def tail_uses source · line 288 · raw
@uses:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use>
the uses after the next
def use_class source · line 300 · raw
@+hu:Bool -> @+us:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Use> -> @+all:Kinds -> @+name:String -> @+braced:Bool -> U32
the class of a name: the use that sits on its head, else its own shape
def name_step source · line 309 · raw
@cur:Cursor -> @+all:Kinds -> @+name:String -> @+line:U32 -> @+col:U32 -> @+braced:Bool -> Step
a name token's type, taking the binder or the use that sits on it, and the cursor after it
def of_tok source · line 322 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @cur:Cursor -> @all:Kinds -> @name:String -> @line:U32 -> @col:U32 -> @braced:Bool -> Step
names ask the binder; keywords are keywords; comments, strings and numbers are left to the editor's grammar, which tells a doc comment from a plain one
def opens_brace source · line 344 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> Bool
does the token list start with {?
def typ_of source · line 352 · raw
@st:Step -> Maybe<&2, U32>
a step's type
def cur_of source · line 357 · raw
@st:Step -> Cursor
a step's cursor
def put source · line 362 · raw
@mm:Maybe<&2, U32> -> @+line:U32 -> @+col:U32 -> @+len:U32 -> @rest:List<&2, Sem> -> List<&2, Sem>
a classified token onto the list, when it has a type
def classify source · line 370 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @cur:Cursor -> @+all:Kinds -> List<&2, Sem>
every token, in order, against the cursor
def sent.one source · line 379 · raw
@+ee:0x013e0f9a479bbebad5ed196725eede95/src/lsp/enc.Enc -> @+cs:List<&2, Char> -> @sem:Sem -> Sem
a token's column and length in an encoding, on its line's chars
def sent.seek source · line 385 · raw
@lines:List<&2, String> -> @cur:U32 -> @line:U32 -> List<&2, String>
the lines from a token's line on, from lines that start at line cur
def sent source · line 391 · raw
@sems:List<&2, Sem> -> @+ee:0x013e0f9a479bbebad5ed196725eede95/src/lsp/enc.Enc -> @lines:List<&2, String> -> @cur:U32 -> List<&2, Sem>
the tokens, in order, with columns and lengths in the negotiated encoding (enc.bend's out.col); lines starts at line cur, and the tokens never go back a line
def encode source · line 403 · raw
@sems:List<&2, Sem> -> @+pl:U32 -> @+pc:U32 -> List<&2, U32>
LSP's encoding: five numbers a token, positions relative to the previous token (a line delta, and a column delta on the same line, absolute on a new one)
def data.of source · line 412 · raw
@ee:0x013e0f9a479bbebad5ed196725eede95/src/lsp/enc.Enc -> @+lines:List<&2, String> -> @bb:0x013e0f9a479bbebad5ed196725eede95/src/syntax/bind.Bound -> @toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> List<&2, U32>
def data source · line 418 · raw
@ee:0x013e0f9a479bbebad5ed196725eede95/src/lsp/enc.Enc -> @+text:String -> List<&2, U32>
a document's semantic tokens, encoded, their columns and lengths in the negotiated encoding