1
1
use crate :: compositor:: { Component , Context , EventResult } ;
2
2
use crossterm:: event:: { Event , KeyCode , KeyEvent } ;
3
3
use helix_view:: editor:: CompleteAction ;
4
+ use helix_view:: theme:: Modifier ;
5
+ use helix_view:: Theme ;
4
6
use tui:: buffer:: Buffer as Surface ;
5
7
6
8
use std:: borrow:: Cow ;
@@ -27,38 +29,51 @@ impl menu::Item for CompletionItem {
27
29
self . label . as_str ( )
28
30
}
29
31
30
- fn row ( & self ) -> menu:: Row {
32
+ fn row ( & self , theme : Option < & Theme > ) -> menu:: Row {
33
+ let ( lsp_type_label, style) = match self . kind {
34
+ Some ( lsp:: CompletionItemKind :: TEXT ) => ( "text" , Some ( "ui.text" ) ) ,
35
+ Some ( lsp:: CompletionItemKind :: METHOD ) => ( "method" , Some ( "function.method" ) ) ,
36
+ Some ( lsp:: CompletionItemKind :: FUNCTION ) => ( "function" , Some ( "function" ) ) ,
37
+ Some ( lsp:: CompletionItemKind :: CONSTRUCTOR ) => ( "constructor" , Some ( "constructor" ) ) ,
38
+ Some ( lsp:: CompletionItemKind :: FIELD ) => ( "field" , Some ( "variable.other.member" ) ) ,
39
+ Some ( lsp:: CompletionItemKind :: VARIABLE ) => ( "variable" , Some ( "variable" ) ) ,
40
+ Some ( lsp:: CompletionItemKind :: CLASS ) => ( "class" , Some ( "type" ) ) ,
41
+ Some ( lsp:: CompletionItemKind :: INTERFACE ) => ( "interface" , Some ( "type" ) ) ,
42
+ Some ( lsp:: CompletionItemKind :: MODULE ) => ( "module" , Some ( "module" ) ) ,
43
+ Some ( lsp:: CompletionItemKind :: PROPERTY ) => ( "property" , Some ( "attributes" ) ) ,
44
+ Some ( lsp:: CompletionItemKind :: UNIT ) => ( "unit" , Some ( "constant" ) ) ,
45
+ Some ( lsp:: CompletionItemKind :: VALUE ) => ( "value" , Some ( "string" ) ) ,
46
+ Some ( lsp:: CompletionItemKind :: ENUM ) => ( "enum" , Some ( "type" ) ) ,
47
+ Some ( lsp:: CompletionItemKind :: KEYWORD ) => ( "keyword" , Some ( "keyword" ) ) ,
48
+ Some ( lsp:: CompletionItemKind :: SNIPPET ) => ( "snippet" , None ) ,
49
+ Some ( lsp:: CompletionItemKind :: COLOR ) => ( "color" , None ) ,
50
+ Some ( lsp:: CompletionItemKind :: FILE ) => ( "file" , None ) ,
51
+ Some ( lsp:: CompletionItemKind :: REFERENCE ) => ( "reference" , None ) ,
52
+ Some ( lsp:: CompletionItemKind :: FOLDER ) => ( "folder" , None ) ,
53
+ Some ( lsp:: CompletionItemKind :: ENUM_MEMBER ) => {
54
+ ( "enum_member" , Some ( "type.enum.variant" ) )
55
+ }
56
+ Some ( lsp:: CompletionItemKind :: CONSTANT ) => ( "constant" , Some ( "constant" ) ) ,
57
+ Some ( lsp:: CompletionItemKind :: STRUCT ) => ( "struct" , Some ( "type" ) ) ,
58
+ Some ( lsp:: CompletionItemKind :: EVENT ) => ( "event" , None ) ,
59
+ Some ( lsp:: CompletionItemKind :: OPERATOR ) => ( "operator" , Some ( "operator" ) ) ,
60
+ Some ( lsp:: CompletionItemKind :: TYPE_PARAMETER ) => {
61
+ ( "type_param" , Some ( "function.parameter" ) )
62
+ }
63
+ Some ( kind) => unimplemented ! ( "{:?}" , kind) ,
64
+ None => ( "" , None ) ,
65
+ } ;
66
+ let mut lsp_type_style = theme
67
+ . zip ( style)
68
+ . map ( |( theme, style) | theme. get ( style) )
69
+ . unwrap_or_default ( )
70
+ . remove_modifier ( Modifier :: all ( ) )
71
+ . add_modifier ( Modifier :: ITALIC ) ;
72
+ lsp_type_style. bg = None ;
73
+
31
74
menu:: Row :: new ( vec ! [
32
75
menu:: Cell :: from( self . label. as_str( ) ) ,
33
- menu:: Cell :: from( match self . kind {
34
- Some ( lsp:: CompletionItemKind :: TEXT ) => "text" ,
35
- Some ( lsp:: CompletionItemKind :: METHOD ) => "method" ,
36
- Some ( lsp:: CompletionItemKind :: FUNCTION ) => "function" ,
37
- Some ( lsp:: CompletionItemKind :: CONSTRUCTOR ) => "constructor" ,
38
- Some ( lsp:: CompletionItemKind :: FIELD ) => "field" ,
39
- Some ( lsp:: CompletionItemKind :: VARIABLE ) => "variable" ,
40
- Some ( lsp:: CompletionItemKind :: CLASS ) => "class" ,
41
- Some ( lsp:: CompletionItemKind :: INTERFACE ) => "interface" ,
42
- Some ( lsp:: CompletionItemKind :: MODULE ) => "module" ,
43
- Some ( lsp:: CompletionItemKind :: PROPERTY ) => "property" ,
44
- Some ( lsp:: CompletionItemKind :: UNIT ) => "unit" ,
45
- Some ( lsp:: CompletionItemKind :: VALUE ) => "value" ,
46
- Some ( lsp:: CompletionItemKind :: ENUM ) => "enum" ,
47
- Some ( lsp:: CompletionItemKind :: KEYWORD ) => "keyword" ,
48
- Some ( lsp:: CompletionItemKind :: SNIPPET ) => "snippet" ,
49
- Some ( lsp:: CompletionItemKind :: COLOR ) => "color" ,
50
- Some ( lsp:: CompletionItemKind :: FILE ) => "file" ,
51
- Some ( lsp:: CompletionItemKind :: REFERENCE ) => "reference" ,
52
- Some ( lsp:: CompletionItemKind :: FOLDER ) => "folder" ,
53
- Some ( lsp:: CompletionItemKind :: ENUM_MEMBER ) => "enum_member" ,
54
- Some ( lsp:: CompletionItemKind :: CONSTANT ) => "constant" ,
55
- Some ( lsp:: CompletionItemKind :: STRUCT ) => "struct" ,
56
- Some ( lsp:: CompletionItemKind :: EVENT ) => "event" ,
57
- Some ( lsp:: CompletionItemKind :: OPERATOR ) => "operator" ,
58
- Some ( lsp:: CompletionItemKind :: TYPE_PARAMETER ) => "type_param" ,
59
- Some ( kind) => unimplemented!( "{:?}" , kind) ,
60
- None => "" ,
61
- } ) ,
76
+ menu:: Cell :: from( lsp_type_label) . style( lsp_type_style) ,
62
77
// self.detail.as_deref().unwrap_or("")
63
78
// self.label_details
64
79
// .as_ref()
0 commit comments