@@ -6,8 +6,8 @@ use flb_schema::section::FlbSectionType;
6
6
#[ allow( unused_imports) ]
7
7
use once_cell:: sync:: Lazy ;
8
8
use tower_lsp:: lsp_types:: {
9
- CompletionItem , CompletionItemKind , CompletionItemLabelDetails , Documentation ,
10
- InsertTextFormat , InsertTextMode , MarkupContent , MarkupKind ,
9
+ CompletionItem , CompletionItemKind , CompletionItemLabelDetails , Documentation , Hover ,
10
+ HoverContents , InsertTextFormat , InsertTextMode , MarkupContent , MarkupKind ,
11
11
} ;
12
12
13
13
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -16,16 +16,19 @@ pub(crate) struct FlbConfigParameterInfo {
16
16
pub ( crate ) description : String ,
17
17
}
18
18
19
- impl From < FlbConfigParameterInfo > for MarkupContent {
20
- fn from ( info : FlbConfigParameterInfo ) -> Self {
21
- let mut value = info . description . clone ( ) ;
22
- if let Some ( default_value) = info . default_value {
19
+ impl FlbConfigParameterInfo {
20
+ pub fn to_hover ( & self , markup_kind : MarkupKind ) -> Hover {
21
+ let mut value = self . description . clone ( ) ;
22
+ if let Some ( default_value) = & self . default_value {
23
23
value. push_str ( format ! ( "\n \n (Default: `{}`)" , default_value) . as_str ( ) ) ;
24
24
}
25
25
26
- MarkupContent {
27
- kind : MarkupKind :: Markdown ,
28
- value,
26
+ Hover {
27
+ contents : HoverContents :: Markup ( MarkupContent {
28
+ kind : markup_kind,
29
+ value,
30
+ } ) ,
31
+ range : None ,
29
32
}
30
33
}
31
34
}
@@ -106,13 +109,30 @@ impl FlbCompletionSnippet {
106
109
107
110
ret
108
111
}
112
+
113
+ // TODO: cache
114
+ pub fn documentation_plaintext ( & self ) -> String {
115
+ let mut ret = format ! ( "{}: {}\n \n " , self . plugin_name, self . label) ;
116
+
117
+ ret. push_str ( "[parameters]\n " ) ;
118
+ for param in & self . config_params {
119
+ ret. push_str ( format ! ( "- {}: {}\n " , param. key, param. info. description) . as_str ( ) ) ;
120
+ }
121
+
122
+ ret
123
+ }
109
124
}
110
125
111
126
pub fn snippet_to_completion (
112
127
snippet : FlbCompletionSnippet ,
113
128
section_type : & FlbSectionType ,
129
+ markup_kind : MarkupKind ,
114
130
) -> CompletionItem {
115
131
let insert_text = snippet. props_to_insert_text ( ) ;
132
+ let documentation_string = match markup_kind {
133
+ MarkupKind :: PlainText => snippet. documentation_plaintext ( ) ,
134
+ MarkupKind :: Markdown => snippet. documentation_markdown ,
135
+ } ;
116
136
117
137
CompletionItem {
118
138
kind : Some ( CompletionItemKind :: SNIPPET ) ,
@@ -122,8 +142,8 @@ pub fn snippet_to_completion(
122
142
description : Some ( format ! ( "{} plugin" , section_type) ) ,
123
143
} ) ,
124
144
documentation : Some ( Documentation :: MarkupContent ( MarkupContent {
125
- kind : MarkupKind :: Markdown ,
126
- value : snippet . documentation_markdown ,
145
+ kind : markup_kind ,
146
+ value : documentation_string ,
127
147
} ) ) ,
128
148
insert_text_mode : Some ( InsertTextMode :: ADJUST_INDENTATION ) ,
129
149
insert_text_format : Some ( InsertTextFormat :: SNIPPET ) ,
@@ -234,12 +254,15 @@ macro_rules! add_snippet {
234
254
235
255
include ! ( "schema.generated.rs" ) ;
236
256
237
- pub fn get_completion ( section_type : & FlbSectionType ) -> Vec < CompletionItem > {
257
+ pub fn get_completion (
258
+ section_type : & FlbSectionType ,
259
+ markup_kind : MarkupKind ,
260
+ ) -> Vec < CompletionItem > {
238
261
FLB_DATA
239
262
. get_snippets ( section_type)
240
263
. unwrap_or ( & vec ! [ ] )
241
264
. iter ( )
242
- . map ( |snippet| snippet_to_completion ( snippet. clone ( ) , section_type) )
265
+ . map ( |snippet| snippet_to_completion ( snippet. clone ( ) , section_type, markup_kind . clone ( ) ) )
243
266
. collect ( )
244
267
}
245
268
0 commit comments