Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
; Function calls

(call_expression
  function: (identifier) @function)

(call_expression
  function: (selector_expression
    field: (field_identifier) @function))


; ; Function definitions

(function_declaration
  name: (identifier) @function)

(proc_group
  (identifier) @function)

; ; Identifiers

(type_identifier) @type
(field_identifier) @variable.other.member
(identifier) @variable

(const_declaration
  (identifier) @constant)
(const_declaration_with_type
  (identifier) @constant)

"any" @type

(directive_identifier) @constant

; ; Operators

[
  "?"
  "-"
  "-="
  ":="
  "!"
  "!="
  "*"
  "*"
  "*="
  "/"
  "/="
  "&"
  "&&"
  "&="
  "%"
  "%="
  "^"
  "+"
  "+="
  "<-"
  "<"
  "<<"
  "<<="
  "<="
  "="
  "=="
  ">"
  ">="
  ">>"
  ">>="
  "|"
  "|="
  "||"
  "~"
  ".."
  "..<"
  "..="
  "::"
] @operator

; ; Keywords

[
  ; "asm"
  "auto_cast"
  ; "bit_set"
  "cast"
  ; "context"
  ; "or_else"
  ; "or_return"
  "in"
  ; "not_in"
  "distinct"
  "foreign"
  "transmute"
  ; "typeid"

  "break"
  "case"
  "continue"
  "defer"
  "else"
  "using"
  "when"
  "where"
  "fallthrough"
  "for"
  "proc"
  "if"
  "import"
  "map"
  "package"
  "return"
  "struct"
  "union"
  "enum"
  "switch"
  "dynamic"
] @keyword

; ; Literals

[
  (interpreted_string_literal)
  (raw_string_literal)
  (rune_literal)
] @string

(escape_sequence) @constant.character.escape

(int_literal) @constant.numeric.integer
(float_literal) @constant.numeric.float
(imaginary_literal) @constant.numeric

[
  (true)
  (false)
] @constant.builtin.boolean

[
use std::sync::Arc;

use arc_swap::ArcSwap;
use helix_core::syntax;
sp_signature, signatures, } } pub fn active_signature(&self) -> usize { self.active_signature } pub fn lsp_signature(&self) -> Option<usize> { self.lsp_signature } pub fn visible_popup(compositor: &mut Compositor) -> Option<&mut Popup<Self>> { compositor.find_id::<Popup<Self>>(Self::ID) } fn signature_index(&self) -> String { format!("({}/{})", self.active_signature + 1, self.signatures.len()) } } impl Component for SignatureHelp { fn handle_event(&mut self, event: &Event, _cx: &mut Context) -> EventResult { let Event::Key(event) = event else { return EventResult::Ignored(None); }; if self.signatures.len() <= 1 { return EventResult::Ignored(None); } match event { alt!('p') => { self.active_signature = self .active_signature .checked_sub(1) .unwrap_or(self.signatures.len() - 1); EventResult::Consumed(None) } alt!('n') => { self.active_signature = (self.active_signature + 1) % self.signatures.len(); EventResult::Consumed(None) } _ => EventResult::Ignored(None), } } fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) { let margin = Margin::horizontal(1); let signature = self .signatures .get(self.active_signature) .unwrap_or_else(|| &self.signatures[0]); let active_param_span = signature.active_param_range.map(|(start, end)| { vec![( cx.editor .theme .find_scope_index_exact("ui.selection") .unwrap(), start..end, )] }); let signature = self .signatures .get(self.active_signature) .unwrap_or_else(|| &self.signatures[0]); let sig_text = crate::ui::markdown::highlighted_code_block( signature.signature.as_str(), &self.language, Some(&cx.editor.theme), Arc::clone(&self.config_loader), active_param_span, ); if self.signatures.len() > 1 { let signature_index = self.signature_index(); let text = Text::from(signature_index); let paragraph = Paragraph::new(&text).alignment(Alignment::Right); paragraph.render(area.clip_top(1).with_height(1).clip_right(1), surface); } let (_, sig_text_height) = crate::ui::text::required_size(&sig_text, area.width); let sig_text_area = area.clip_top(1).with_height(sig_text_height); let sig_text_area = sig_text_area.inner(margin).intersection(surface.area); let sig_text_para = Paragraph::new(&sig_text).wrap(Wrap { trim: false }); sig_text_para.render(sig_text_area, surface); if signature.signature_doc.is_none() { return; } let sep_style = Style::default(); let borders = BorderType::line_symbols(BorderType::Plain); for x in sig_text_area.left()..sig_text_area.right() { if let Some(cell) = surface.get_mut(x, sig_text_area.bottom()) { cell.set_symbol(borders.horizontal).set_style(sep_style); } } let sig_doc = match &signature.signature_doc { None => return, Some(doc) => Markdown::new(doc.clone(), Arc::clone(&self.config_loader)), }; let sig_doc = sig_doc.parse(Some(&cx.editor.theme)); let sig_doc_area = area .clip_top(sig_text_area.height + 2) .clip_bottom(u16::from(cx.editor.popup_border())); let sig_doc_para = Paragraph::new(&sig_doc) .wrap(Wrap { trim: false }) .scroll((cx.scroll.unwrap_or_default() as u16, 0)); sig_doc_para.render(sig_doc_area.inner(margin), surface); } fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { const PADDING: u16 = 2; const SEPARATOR_HEIGHT: u16 = 1; let signature = self .signatures .get(self.active_signature) .unwrap_or_else(|| &self.signatures[0]); let max_text_width = viewport.0.saturating_sub(PADDING).clamp(10, 120); let signature_text = crate::ui::markdown::highlighted_code_block( signature.signature.as_str(), &self.language, None, Arc::clone(&self.config_loader), None, ); let (sig_width, sig_height) = crate::ui::text::required_size(&signature_text, max_text_width); let (width, height) = match signature.signature_doc { Some(ref doc) => { let doc_md = Markdown::new(doc.clone(), Arc::clone(&self.config_loader)); let doc_text = doc_md.parse(None); let (doc_width, doc_height) = crate::ui::text::required_size(&doc_text, max_text_width); ( sig_width.max(doc_width), sig_height + SEPARATOR_HEIGHT + doc_height, ) } None => (sig_width, sig_height), }; let sig_index_width = if self.signatures.len() > 1 { self.signature_index().len() + 1 } else { 0 }; Some((width + PADDING + sig_index_width as u16, height + PADDING)) } }