~/bend-docscommunity

bolt/lsp/semantic.bend checks

raw source on the hub · import 0x729eecea86ea5a2cdba3a2856a313bca/bolt/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.

3 imports
import Base
import ../../syntax/lex.bend as Lex
import ../../syntax/bind.bend as Bind

Types

type Sem source · line 19 · raw

Data

a classified token: where, how long, which type of the legend

type Cursor source · line 80 · 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

type Step source · line 159 · raw

Data

a token's class, when it has one, and the cursor after it

Definitions

def legend source · line 14 · 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 23 · raw

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

does the name start with a capital?

def last_segment source · line 31 · raw

@cs:List<&2, Char> -> @+acc:List<&2, Char> -> List<&2, Char>

the last segment of a dotted name

def of_kind source · line 42 · raw

@k:0x729eecea86ea5a2cdba3a2856a313bca/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 64 · raw

@m:Maybe<&2, 0x729eecea86ea5a2cdba3a2856a313bca/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 73 · 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 84 · raw

@binds:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> @+line:U32 -> @+col:U32 -> Bool

does the next binder sit at this position?

def at_head_use source · line 92 · raw

@uses:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool

does the next use sit at this position?

def behind_bind source · line 101 · raw

@binds:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/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 109 · raw

@uses:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool

is the next use behind this position?

def head_bind_kind source · line 117 · raw

@binds:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> U32

the type of the next binder

def of_target source · line 125 · raw

@tg:0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Target -> @all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> @name:String -> @braced:Bool -> U32

the type of a use, from what it refers to

def head_use_class source · line 135 · raw

@uses:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use> -> @all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> @braced:Bool -> U32

the type of the next use

def tail_binds source · line 143 · raw

@binds:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind>

the binders after the next

def tail_uses source · line 151 · raw

@uses:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use> -> List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use>

the uses after the next

def use_class source · line 163 · raw

@+hu:Bool -> @+us:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Use> -> @+all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/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 172 · raw

@cur:Cursor -> @+all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/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 185 · raw

@k:0x729eecea86ea5a2cdba3a2856a313bca/syntax/lex.TokKind -> @cur:Cursor -> @all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/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 200 · raw

@toks:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/lex.Tok> -> Bool

does the token list start with {?

def typ_of source · line 208 · raw

@st:Step -> Maybe<&2, U32>

a step's type

def cur_of source · line 213 · raw

@st:Step -> Cursor

a step's cursor

def put source · line 218 · raw

@m: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 226 · raw

@toks:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/lex.Tok> -> @cur:Cursor -> @+all:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bind> -> List<&2, Sem>

every token, in order, against the cursor

def encode source · line 237 · 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 246 · raw

@b:0x729eecea86ea5a2cdba3a2856a313bca/syntax/bind.Bound -> @toks:List<&2, 0x729eecea86ea5a2cdba3a2856a313bca/syntax/lex.Tok> -> List<&2, U32>

def data source · line 251 · raw

@+text:String -> List<&2, U32>

a document's semantic tokens, encoded