ui/code_assist.rs#
Source: lib/ui/code_assist.rs
code_assist -- what a language gives ui.code_editor beyond highlighting: completion, hover
texts and signature help (CodeAssist, through ui.code_editor_with), the requests of the
editor that the app answers (CodeEv, ui.code_events), and the popups that show them
trait CodeAssist complete(doc, at, explicit) -> Option<CompList> the items for
the word at the caret (explicit: Ctrl+Space; else typing a word or
a trigger character of triggers(), "." by default)
hover(doc, at) -> Option<String> the text of a tooltip over the
word at a position (lines by '\n'; long ones are wrapped)
signature(doc, at) -> Option<SigHelp> inside a call's parentheses
Every method has a default that offers nothing.
CompItem { label, detail, doc, kind: CI_*, insert } an item: what the list shows, a short
line beside it (a signature), a description (shown under the list
for the selected item), its kind (a letter in a badge), the text
it inserts ("": the label)
CompList { start, items } the items replace the word from start to the end of the word
at the caret
SigHelp { label, params, active, doc } "split(sep, n)", the byte ranges of the
parameters in it, the one at the caret (drawn bold), a description
CodeEv Definition(pos) (Ctrl+click, F12), Rename(pos) (F2), Format
(Shift+Alt+F), Breakpoint(line) (a click in the breakpoints' column)
The completion popup opens while a word is typed (once per word: a word without items keeps
it closed until it ends), after a trigger character and on Ctrl+Space; it filters as one
types (the items whose label starts with the typed part, ignoring case, those that match
the case first, otherwise in the order of the assist). Up / Down / PgUp / PgDn choose, Enter
or Tab insert (the word from the list's start to the end of the word at the caret becomes
the item's text, one undo step, the caret after it; Enter after a word typed out in full
closes the list and breaks the line), Esc closes, a click on an item inserts
it; leaving the word, a character that is no part of a word, a click elsewhere or the focus
leaving close it. At most POP_ROWS rows show, the wheel scrolls them. Signature help opens
when ( or , is typed and on Ctrl+Shift+Space, follows the caret and closes outside a call or
on Esc. Both are drawn on the popup layer below / above the caret line within the window,
in the code theme's colours (high contrast too), and recorded for screen readers: the list
as a K_LIST (id + 14) with a K_LISTITEM per visible row (the chosen one SS_SELECTED, label
and detail), signature help as a K_TEXT.
/// completion item kinds: plain text
CI_TEXT: u8 = 0
CI_KEYWORD: u8 = 1
/// a variable (let, loop, catch)
CI_VARIABLE: u8 = 2
CI_PARAM: u8 = 3
CI_FUNCTION: u8 = 4
CI_METHOD: u8 = 5
/// a module or namespace
CI_MODULE: u8 = 6
CI_CONSTANT: u8 = 7
CI_FIELD: u8 = 8
/// a value of the host (a configuration)
CI_VALUE: u8 = 9
/// the rows the completion popup shows at most
POP_ROWS: usize = 10
struct CompItema completion item (see the module header)label: Stringdetail: Stringdoc: Stringkind: u8insert: String-- the text it inserts ("": the label)
impl CompItem
fn new(label: &str, kind: u8, detail: &str) -> CompItemstruct CompListwhat complete() offers: the items replace the word from start onstart: TextPositems: Vec<CompItem>
struct SigHelpsignature help inside a calllabel: String-- "split(sep, n)"params: Vec<(usize, usize)>-- the bytes of each parameter in labelactive: usize-- the parameter at the caret (params.len(): none)doc: String
trait CodeAssista language's services for ui.code_editor_with (see the module header)fn complete(&mut self, doc: &CodeDoc, at: TextPos, explicit: bool) -> Option<CompList>the items for the word at the caretat(explicit: Ctrl+Space)fn hover(&mut self, doc: &CodeDoc, at: TextPos) -> Option<String>the tooltip text for the word atatfn signature(&mut self, doc: &CodeDoc, at: TextPos) -> Option<SigHelp>signature help at the caretfn triggers(&self) -> &strcharacters after which completion opens
enum CodeEvwhat the user asked of a code editor in its last pass (ui.code_events)Definition(TextPos)-- go to the definition of the word at the position (Ctrl+click, F12)Rename(TextPos)-- rename the word at the position (F2)Format-- format the document (Shift+Alt+F)Breakpoint(usize)-- a click in the breakpoints' column of line (from 0)