src/lsp/semantic.bend checks
raw source on the hub · import 0xd96f2ab40f5df4925c42e96d0ba857ff/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.
4 imports
import Base import ../syntax/lex.bend as Lex import ../syntax/bind.bend as Bind import ./enc.bend as Enc
Types
type Sem source · line 20 · 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 81 · 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, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> Cursor
type Step source · line 160 · 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 15 · 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 24 · raw
@cs:List<&2, Char> -> Bool
does the name start with a capital?
def last_segment source · line 32 · raw
@cs:List<&2, Char> -> @+acc:List<&2, Char> -> List<&2, Char>
the last segment of a dotted name
def of_kind source · line 43 · raw
@kk:0xd96f2ab40f5df4925c42e96d0ba857ff/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 65 · raw
@mm:Maybe<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/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 74 · 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 85 · raw
@binds:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @+line:U32 -> @+col:U32 -> Bool
does the next binder sit at this position?
def at_head_use source · line 93 · raw
@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool
does the next use sit at this position?
def behind_bind source · line 102 · raw
@binds:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/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 110 · raw
@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool
is the next use behind this position?
def head_bind_kind source · line 118 · raw
@binds:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> U32
the type of the next binder
def of_target source · line 126 · raw
@tg:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Target -> @all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @name:String -> @braced:Bool -> U32
the type of a use, from what it refers to
def head_use_class source · line 136 · raw
@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @braced:Bool -> U32
the type of the next use
def tail_binds source · line 144 · raw
@binds:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind>
the binders after the next
def tail_uses source · line 152 · raw
@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use>
the uses after the next
def use_class source · line 164 · raw
@+hu:Bool -> @+us:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @+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 173 · raw
@cur:Cursor -> @+all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @+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 186 · raw
@kk:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/lex.TokKind -> @cur:Cursor -> @all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @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 208 · raw
@toks:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/lex.Tok> -> Bool
does the token list start with {?
def typ_of source · line 216 · raw
@st:Step -> Maybe<&2, U32>
a step's type
def cur_of source · line 221 · raw
@st:Step -> Cursor
a step's cursor
def put source · line 226 · 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 234 · raw
@toks:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/lex.Tok> -> @cur:Cursor -> @+all:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> List<&2, Sem>
every token, in order, against the cursor
def sent.one source · line 243 · raw
@+ee:0xd96f2ab40f5df4925c42e96d0ba857ff/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 249 · 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 255 · raw
@sems:List<&2, Sem> -> @+ee:0xd96f2ab40f5df4925c42e96d0ba857ff/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 267 · 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 276 · raw
@ee:0xd96f2ab40f5df4925c42e96d0ba857ff/src/lsp/enc.Enc -> @+lines:List<&2, String> -> @bb:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bound -> @toks:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/lex.Tok> -> List<&2, U32>
def data source · line 282 · raw
@ee:0xd96f2ab40f5df4925c42e96d0ba857ff/src/lsp/enc.Enc -> @+text:String -> List<&2, U32>
a document's semantic tokens, encoded, their columns and lengths in the negotiated encoding