@@ -306,8 +306,7 @@ pub struct Config {
306
306
pub completion_replace : bool ,
307
307
/// The completion item kind text to display in the completion menu. Leave kind empty to use
308
308
/// the kind's name.
309
- #[ serde( deserialize_with = "deserialize_completion_item_kinds" ) ]
310
- pub completion_item_kinds : HashMap < lsp:: CompletionItemKind , String > ,
309
+ pub completion_item_kinds : HashMap < String , String > ,
311
310
/// Whether to display infoboxes. Defaults to true.
312
311
pub auto_info : bool ,
313
312
pub file_picker : FilePickerConfig ,
@@ -852,58 +851,6 @@ where
852
851
}
853
852
}
854
853
855
- fn deserialize_completion_item_kinds < ' de , D > (
856
- deserializer : D ,
857
- ) -> Result < HashMap < lsp:: CompletionItemKind , String > , D :: Error >
858
- where
859
- D : serde:: Deserializer < ' de > ,
860
- {
861
- let raw = HashMap :: < String , String > :: deserialize ( deserializer) ?;
862
- let mut ret = HashMap :: with_capacity ( raw. len ( ) ) ;
863
-
864
- for ( kind, text) in raw {
865
- // NOTE: Doing manual string check since CompletionItemKind::from_str uses
866
- // PascalCase while the configuration is in kebab-case
867
- let kind = match kind. as_str ( ) {
868
- "text" => lsp:: CompletionItemKind :: TEXT ,
869
- "method" => lsp:: CompletionItemKind :: METHOD ,
870
- "function" => lsp:: CompletionItemKind :: FUNCTION ,
871
- "constructor" => lsp:: CompletionItemKind :: CONSTRUCTOR ,
872
- "field" => lsp:: CompletionItemKind :: FIELD ,
873
- "variable" => lsp:: CompletionItemKind :: VARIABLE ,
874
- "class" => lsp:: CompletionItemKind :: CLASS ,
875
- "interface" => lsp:: CompletionItemKind :: INTERFACE ,
876
- "module" => lsp:: CompletionItemKind :: MODULE ,
877
- "property" => lsp:: CompletionItemKind :: PROPERTY ,
878
- "unit" => lsp:: CompletionItemKind :: UNIT ,
879
- "value" => lsp:: CompletionItemKind :: VALUE ,
880
- "enum" => lsp:: CompletionItemKind :: ENUM ,
881
- "keyword" => lsp:: CompletionItemKind :: KEYWORD ,
882
- "snippet" => lsp:: CompletionItemKind :: SNIPPET ,
883
- "color" => lsp:: CompletionItemKind :: COLOR ,
884
- "file" => lsp:: CompletionItemKind :: FILE ,
885
- "reference" => lsp:: CompletionItemKind :: REFERENCE ,
886
- "folder" => lsp:: CompletionItemKind :: FOLDER ,
887
- "enum-member" => lsp:: CompletionItemKind :: ENUM_MEMBER ,
888
- "constant" => lsp:: CompletionItemKind :: CONSTANT ,
889
- "struct" => lsp:: CompletionItemKind :: STRUCT ,
890
- "event" => lsp:: CompletionItemKind :: EVENT ,
891
- "operator" => lsp:: CompletionItemKind :: OPERATOR ,
892
- "type-parameter" => lsp:: CompletionItemKind :: TYPE_PARAMETER ,
893
- _ => {
894
- return Err ( <D :: Error as serde:: de:: Error >:: invalid_value (
895
- serde:: de:: Unexpected :: Str ( kind. as_str ( ) ) ,
896
- & "CompletionItemKind" ,
897
- ) ) ;
898
- }
899
- } ;
900
-
901
- ret. insert ( kind, text) ;
902
- }
903
-
904
- Ok ( ret)
905
- }
906
-
907
854
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
908
855
#[ serde( default ) ]
909
856
pub struct WhitespaceCharacters {
@@ -1131,7 +1078,7 @@ pub struct Editor {
1131
1078
1132
1079
pub config : Arc < dyn DynAccess < Config > > ,
1133
1080
pub auto_pairs : Option < AutoPairs > ,
1134
- pub completion_item_kind_styles : Arc < HashMap < lsp :: CompletionItemKind , CompletionItemKindStyle > > ,
1081
+ pub completion_item_kind_styles : Arc < HashMap < & ' static str , CompletionItemKindStyle > > ,
1135
1082
1136
1083
pub idle_timer : Pin < Box < Sleep > > ,
1137
1084
redraw_timer : Pin < Box < Sleep > > ,
@@ -1322,6 +1269,10 @@ impl Editor {
1322
1269
pub fn refresh_config ( & mut self ) {
1323
1270
let config = self . config ( ) ;
1324
1271
self . auto_pairs = ( & config. auto_pairs ) . into ( ) ;
1272
+ self . completion_item_kind_styles = Arc :: new ( compute_completion_item_kind_styles (
1273
+ & self . theme ,
1274
+ & self . config ( ) ,
1275
+ ) ) ;
1325
1276
self . reset_idle_timer ( ) ;
1326
1277
self . _refresh ( ) ;
1327
1278
}
@@ -2292,39 +2243,42 @@ fn try_restore_indent(doc: &mut Document, view: &mut View) {
2292
2243
fn compute_completion_item_kind_styles (
2293
2244
theme : & Theme ,
2294
2245
config : & DynGuard < Config > ,
2295
- ) -> HashMap < lsp :: CompletionItemKind , CompletionItemKindStyle > {
2246
+ ) -> HashMap < & ' static str , CompletionItemKindStyle > {
2296
2247
let mut ret = HashMap :: new ( ) ;
2297
- for ( scope_name, kind) in [
2298
- ( "text" , lsp:: CompletionItemKind :: TEXT ) ,
2299
- ( "method" , lsp:: CompletionItemKind :: METHOD ) ,
2300
- ( "function" , lsp:: CompletionItemKind :: FUNCTION ) ,
2301
- ( "constructor" , lsp:: CompletionItemKind :: CONSTRUCTOR ) ,
2302
- ( "field" , lsp:: CompletionItemKind :: FIELD ) ,
2303
- ( "variable" , lsp:: CompletionItemKind :: VARIABLE ) ,
2304
- ( "class" , lsp:: CompletionItemKind :: CLASS ) ,
2305
- ( "interface" , lsp:: CompletionItemKind :: INTERFACE ) ,
2306
- ( "module" , lsp:: CompletionItemKind :: MODULE ) ,
2307
- ( "property" , lsp:: CompletionItemKind :: PROPERTY ) ,
2308
- ( "unit" , lsp:: CompletionItemKind :: UNIT ) ,
2309
- ( "value" , lsp:: CompletionItemKind :: VALUE ) ,
2310
- ( "enum" , lsp:: CompletionItemKind :: ENUM ) ,
2311
- ( "keyword" , lsp:: CompletionItemKind :: KEYWORD ) ,
2312
- ( "snippet" , lsp:: CompletionItemKind :: SNIPPET ) ,
2313
- ( "color" , lsp:: CompletionItemKind :: COLOR ) ,
2314
- ( "file" , lsp:: CompletionItemKind :: FILE ) ,
2315
- ( "reference" , lsp:: CompletionItemKind :: REFERENCE ) ,
2316
- ( "folder" , lsp:: CompletionItemKind :: FOLDER ) ,
2317
- ( "enum-member" , lsp:: CompletionItemKind :: ENUM_MEMBER ) ,
2318
- ( "constant" , lsp:: CompletionItemKind :: CONSTANT ) ,
2319
- ( "struct" , lsp:: CompletionItemKind :: STRUCT ) ,
2320
- ( "event" , lsp:: CompletionItemKind :: EVENT ) ,
2321
- ( "operator" , lsp:: CompletionItemKind :: OPERATOR ) ,
2322
- ( "type-parameter" , lsp:: CompletionItemKind :: TYPE_PARAMETER ) ,
2248
+ // We populate with LSP kinds and additionally file+folder for path completion
2249
+ for name in [
2250
+ "text" ,
2251
+ "method" ,
2252
+ "function" ,
2253
+ "constructor" ,
2254
+ "field" ,
2255
+ "variable" ,
2256
+ "class" ,
2257
+ "interface" ,
2258
+ "module" ,
2259
+ "property" ,
2260
+ "unit" ,
2261
+ "value" ,
2262
+ "enum" ,
2263
+ "keyword" ,
2264
+ "snippet" ,
2265
+ "color" ,
2266
+ "file" ,
2267
+ "reference" ,
2268
+ "folder" ,
2269
+ "enum-member" ,
2270
+ "constant" ,
2271
+ "struct" ,
2272
+ "event" ,
2273
+ "operator" ,
2274
+ "type-parameter" ,
2275
+ "file" ,
2276
+ "folder" ,
2323
2277
] {
2324
- let style = theme. try_get ( & dbg ! ( format!( "ui.completion.kind.{scope_name}" ) ) ) ;
2325
- let text = config. completion_item_kinds . get ( & kind ) . cloned ( ) ;
2278
+ let style = theme. try_get ( & format ! ( "ui.completion.kind.{name}" ) ) ;
2279
+ let text = config. completion_item_kinds . get ( name ) . cloned ( ) ;
2326
2280
if style. is_some ( ) || text. is_some ( ) {
2327
- ret. insert ( kind , CompletionItemKindStyle { text, style } ) ;
2281
+ ret. insert ( name , CompletionItemKindStyle { text, style } ) ;
2328
2282
}
2329
2283
}
2330
2284
0 commit comments