@@ -9,10 +9,13 @@ use helix_view::{
9
9
document:: SavePoint ,
10
10
editor:: CompleteAction ,
11
11
handlers:: lsp:: SignatureHelpInvoked ,
12
- theme:: { Modifier , Style } ,
12
+ theme:: { Color , Modifier , Style } ,
13
13
ViewId ,
14
14
} ;
15
- use tui:: { buffer:: Buffer as Surface , text:: Span } ;
15
+ use tui:: {
16
+ buffer:: Buffer as Surface ,
17
+ text:: { Span , Spans } ,
18
+ } ;
16
19
17
20
use std:: { borrow:: Cow , sync:: Arc } ;
18
21
@@ -64,53 +67,69 @@ impl menu::Item for CompletionItem {
64
67
65
68
let kind = match self {
66
69
CompletionItem :: Lsp ( LspCompletionItem { item, .. } ) => match item. kind {
67
- Some ( lsp:: CompletionItemKind :: TEXT ) => "text" ,
68
- Some ( lsp:: CompletionItemKind :: METHOD ) => "method" ,
69
- Some ( lsp:: CompletionItemKind :: FUNCTION ) => "function" ,
70
- Some ( lsp:: CompletionItemKind :: CONSTRUCTOR ) => "constructor" ,
71
- Some ( lsp:: CompletionItemKind :: FIELD ) => "field" ,
72
- Some ( lsp:: CompletionItemKind :: VARIABLE ) => "variable" ,
73
- Some ( lsp:: CompletionItemKind :: CLASS ) => "class" ,
74
- Some ( lsp:: CompletionItemKind :: INTERFACE ) => "interface" ,
75
- Some ( lsp:: CompletionItemKind :: MODULE ) => "module" ,
76
- Some ( lsp:: CompletionItemKind :: PROPERTY ) => "property" ,
77
- Some ( lsp:: CompletionItemKind :: UNIT ) => "unit" ,
78
- Some ( lsp:: CompletionItemKind :: VALUE ) => "value" ,
79
- Some ( lsp:: CompletionItemKind :: ENUM ) => "enum" ,
80
- Some ( lsp:: CompletionItemKind :: KEYWORD ) => "keyword" ,
81
- Some ( lsp:: CompletionItemKind :: SNIPPET ) => "snippet" ,
82
- Some ( lsp:: CompletionItemKind :: COLOR ) => "color" ,
83
- Some ( lsp:: CompletionItemKind :: FILE ) => "file" ,
84
- Some ( lsp:: CompletionItemKind :: REFERENCE ) => "reference" ,
85
- Some ( lsp:: CompletionItemKind :: FOLDER ) => "folder" ,
86
- Some ( lsp:: CompletionItemKind :: ENUM_MEMBER ) => "enum_member" ,
87
- Some ( lsp:: CompletionItemKind :: CONSTANT ) => "constant" ,
88
- Some ( lsp:: CompletionItemKind :: STRUCT ) => "struct" ,
89
- Some ( lsp:: CompletionItemKind :: EVENT ) => "event" ,
90
- Some ( lsp:: CompletionItemKind :: OPERATOR ) => "operator" ,
91
- Some ( lsp:: CompletionItemKind :: TYPE_PARAMETER ) => "type_param" ,
70
+ Some ( lsp:: CompletionItemKind :: TEXT ) => "text" . into ( ) ,
71
+ Some ( lsp:: CompletionItemKind :: METHOD ) => "method" . into ( ) ,
72
+ Some ( lsp:: CompletionItemKind :: FUNCTION ) => "function" . into ( ) ,
73
+ Some ( lsp:: CompletionItemKind :: CONSTRUCTOR ) => "constructor" . into ( ) ,
74
+ Some ( lsp:: CompletionItemKind :: FIELD ) => "field" . into ( ) ,
75
+ Some ( lsp:: CompletionItemKind :: VARIABLE ) => "variable" . into ( ) ,
76
+ Some ( lsp:: CompletionItemKind :: CLASS ) => "class" . into ( ) ,
77
+ Some ( lsp:: CompletionItemKind :: INTERFACE ) => "interface" . into ( ) ,
78
+ Some ( lsp:: CompletionItemKind :: MODULE ) => "module" . into ( ) ,
79
+ Some ( lsp:: CompletionItemKind :: PROPERTY ) => "property" . into ( ) ,
80
+ Some ( lsp:: CompletionItemKind :: UNIT ) => "unit" . into ( ) ,
81
+ Some ( lsp:: CompletionItemKind :: VALUE ) => "value" . into ( ) ,
82
+ Some ( lsp:: CompletionItemKind :: ENUM ) => "enum" . into ( ) ,
83
+ Some ( lsp:: CompletionItemKind :: KEYWORD ) => "keyword" . into ( ) ,
84
+ Some ( lsp:: CompletionItemKind :: SNIPPET ) => "snippet" . into ( ) ,
85
+ Some ( lsp:: CompletionItemKind :: COLOR ) => item
86
+ . documentation
87
+ . as_ref ( )
88
+ . and_then ( |docs| {
89
+ let text = match docs {
90
+ lsp:: Documentation :: String ( text) => text,
91
+ lsp:: Documentation :: MarkupContent ( lsp:: MarkupContent {
92
+ value, ..
93
+ } ) => value,
94
+ } ;
95
+ Color :: from_hex ( text)
96
+ } )
97
+ . map_or ( "color" . into ( ) , |color| {
98
+ Spans :: from ( vec ! [
99
+ Span :: raw( "color " ) ,
100
+ Span :: styled( "■" , Style :: default ( ) . fg( color) ) ,
101
+ ] )
102
+ } ) ,
103
+ Some ( lsp:: CompletionItemKind :: FILE ) => "file" . into ( ) ,
104
+ Some ( lsp:: CompletionItemKind :: REFERENCE ) => "reference" . into ( ) ,
105
+ Some ( lsp:: CompletionItemKind :: FOLDER ) => "folder" . into ( ) ,
106
+ Some ( lsp:: CompletionItemKind :: ENUM_MEMBER ) => "enum_member" . into ( ) ,
107
+ Some ( lsp:: CompletionItemKind :: CONSTANT ) => "constant" . into ( ) ,
108
+ Some ( lsp:: CompletionItemKind :: STRUCT ) => "struct" . into ( ) ,
109
+ Some ( lsp:: CompletionItemKind :: EVENT ) => "event" . into ( ) ,
110
+ Some ( lsp:: CompletionItemKind :: OPERATOR ) => "operator" . into ( ) ,
111
+ Some ( lsp:: CompletionItemKind :: TYPE_PARAMETER ) => "type_param" . into ( ) ,
92
112
Some ( kind) => {
93
113
log:: error!( "Received unknown completion item kind: {:?}" , kind) ;
94
- ""
114
+ "" . into ( )
95
115
}
96
- None => "" ,
116
+ None => "" . into ( ) ,
97
117
} ,
98
- CompletionItem :: Other ( core:: CompletionItem { kind, .. } ) => kind,
118
+ CompletionItem :: Other ( core:: CompletionItem { kind, .. } ) => kind. as_ref ( ) . into ( ) ,
99
119
} ;
100
120
101
- menu:: Row :: new ( [
102
- menu:: Cell :: from ( Span :: styled (
103
- label,
104
- if deprecated {
105
- Style :: default ( ) . add_modifier ( Modifier :: CROSSED_OUT )
106
- } else if kind == "folder" {
107
- * dir_style
108
- } else {
109
- Style :: default ( )
110
- } ,
111
- ) ) ,
112
- menu:: Cell :: from ( kind) ,
113
- ] )
121
+ let label = Span :: styled (
122
+ label,
123
+ if deprecated {
124
+ Style :: default ( ) . add_modifier ( Modifier :: CROSSED_OUT )
125
+ } else if kind. 0 [ 0 ] . content == "folder" {
126
+ * dir_style
127
+ } else {
128
+ Style :: default ( )
129
+ } ,
130
+ ) ;
131
+
132
+ menu:: Row :: new ( [ menu:: Cell :: from ( label) , menu:: Cell :: from ( kind) ] )
114
133
}
115
134
}
116
135
0 commit comments