@@ -7,74 +7,78 @@ use vhdl_lang::ast::{Designator, ObjectClass};
77use vhdl_lang:: { kind_str, AnyEntKind , Design , EntRef , InterfaceEnt , Overloaded } ;
88
99impl VHDLServer {
10- fn completion_item_to_lsp_item (
11- & self ,
12- item : vhdl_lang:: CompletionItem ,
13- ) -> lsp_types:: CompletionItem {
10+ fn insert_text ( & self , val : impl ToString ) -> String {
11+ let mut val = val. to_string ( ) ;
12+ if let Some ( case) = & self . case_transform {
13+ case. convert ( & mut val)
14+ }
15+ val
16+ }
17+
18+ fn completion_item_to_lsp_item ( & self , item : vhdl_lang:: CompletionItem ) -> CompletionItem {
1419 match item {
15- vhdl_lang:: CompletionItem :: Simple ( ent) => entity_to_completion_item ( ent) ,
20+ vhdl_lang:: CompletionItem :: Simple ( ent) => self . entity_to_completion_item ( ent) ,
1621 vhdl_lang:: CompletionItem :: Work => CompletionItem {
17- label : "work" . to_string ( ) ,
22+ label : self . insert_text ( "work" ) ,
1823 detail : Some ( "work library" . to_string ( ) ) ,
1924 kind : Some ( CompletionItemKind :: MODULE ) ,
20- insert_text : Some ( "work" . to_string ( ) ) ,
2125 ..Default :: default ( )
2226 } ,
2327 vhdl_lang:: CompletionItem :: Formal ( ent) => {
24- let mut item = entity_to_completion_item ( ent) ;
28+ let mut item = self . entity_to_completion_item ( ent) ;
2529 if self . client_supports_snippets ( ) {
2630 item. insert_text_format = Some ( InsertTextFormat :: SNIPPET ) ;
2731 item. insert_text = Some ( format ! ( "{} => $1," , item. insert_text. unwrap( ) ) ) ;
2832 }
2933 item
3034 }
31- vhdl_lang:: CompletionItem :: Overloaded ( desi, count) => CompletionItem {
32- label : desi. to_string ( ) ,
33- detail : Some ( format ! ( "+{count} overloaded" ) ) ,
34- kind : match desi {
35+ vhdl_lang:: CompletionItem :: Overloaded ( desi, count) => {
36+ let kind = match desi {
3537 Designator :: Identifier ( _) => Some ( CompletionItemKind :: FUNCTION ) ,
3638 Designator :: OperatorSymbol ( _) => Some ( CompletionItemKind :: OPERATOR ) ,
3739 _ => None ,
38- } ,
39- insert_text : Some ( desi. to_string ( ) ) ,
40- ..Default :: default ( )
41- } ,
40+ } ;
41+ CompletionItem {
42+ label : self . insert_text ( desi) ,
43+ detail : Some ( format ! ( "+{count} overloaded" ) ) ,
44+ kind,
45+ ..Default :: default ( )
46+ }
47+ }
4248 vhdl_lang:: CompletionItem :: Keyword ( kind) => CompletionItem {
43- label : kind_str ( kind) . to_string ( ) ,
49+ label : self . insert_text ( kind_str ( kind) ) ,
4450 detail : Some ( kind_str ( kind) . to_string ( ) ) ,
45- insert_text : Some ( kind_str ( kind) . to_string ( ) ) ,
4651 kind : Some ( CompletionItemKind :: KEYWORD ) ,
4752 ..Default :: default ( )
4853 } ,
4954 vhdl_lang:: CompletionItem :: Instantiation ( ent, architectures) => {
50- let work_name = "work" ;
55+ let work_name = self . insert_text ( "work" ) ;
5156
5257 let library_names = if let Some ( lib_name) = ent. library_name ( ) {
53- vec ! [ work_name. to_string ( ) , lib_name. name( ) . to_string ( ) ]
58+ vec ! [ work_name, self . insert_text ( lib_name. name( ) ) ]
5459 } else {
55- vec ! [ work_name. to_string ( ) ]
60+ vec ! [ work_name]
5661 } ;
5762 let ( region, is_component_instantiation) = match ent. kind ( ) {
5863 AnyEntKind :: Design ( Design :: Entity ( _, region) ) => ( region, false ) ,
5964 AnyEntKind :: Component ( region) => ( region, true ) ,
6065 // should never happen but better return some value instead of crashing
61- _ => return entity_to_completion_item ( ent) ,
66+ _ => return self . entity_to_completion_item ( ent) ,
6267 } ;
68+ let designator = self . insert_text ( & ent. designator ) ;
6369 let template = if self . client_supports_snippets ( ) {
6470 let mut line = if is_component_instantiation {
65- format ! ( "${{1:{}_inst}}: {}" , ent . designator , ent . designator )
71+ format ! ( "${{1:{designator }_inst}}: {designator }" , )
6672 } else {
6773 format ! (
68- "${{1:{}_inst}}: entity ${{2|{}|}}.{}" ,
69- ent. designator,
74+ "${{1:{designator}_inst}}: entity ${{2|{}|}}.{designator}" ,
7075 library_names. join( "," ) ,
71- ent. designator
7276 )
7377 } ;
7478 if architectures. len ( ) > 1 {
7579 line. push_str ( "(${3|" ) ;
7680 for ( i, architecture) in architectures. iter ( ) . enumerate ( ) {
77- line. push_str ( & architecture. designator ( ) . to_string ( ) ) ;
81+ line. push_str ( & self . insert_text ( architecture. designator ( ) ) ) ;
7882 if i != architectures. len ( ) - 1 {
7983 line. push ( ',' )
8084 }
@@ -84,11 +88,11 @@ impl VHDLServer {
8488 let ( ports, generics) = region. ports_and_generics ( ) ;
8589 let mut idx = 4 ;
8690 let mut interface_ent = |elements : Vec < InterfaceEnt > , purpose : & str | {
87- line += & * format ! ( "\n {purpose} map (\n " ) ;
91+ line += & * format ! ( "\n {purpose} {} (\n " , self . insert_text ( "map" ) ) ;
8892 for ( i, generic) in elements. iter ( ) . enumerate ( ) {
93+ let generic_designator = self . insert_text ( & generic. designator ) ;
8994 line += & * format ! (
90- " {} => ${{{}:{}}}" ,
91- generic. designator, idx, generic. designator
95+ " {generic_designator} => ${{{idx}:{generic_designator}}}" ,
9296 ) ;
9397 idx += 1 ;
9498 if i != elements. len ( ) - 1 {
@@ -99,28 +103,26 @@ impl VHDLServer {
99103 line += ")" ;
100104 } ;
101105 if !generics. is_empty ( ) {
102- interface_ent ( generics, "generic" ) ;
106+ interface_ent ( generics, & self . insert_text ( "generic" ) ) ;
103107 }
104108 if !ports. is_empty ( ) {
105- interface_ent ( ports, "port" ) ;
109+ interface_ent ( ports, & self . insert_text ( "port" ) ) ;
106110 }
107111 line += ";" ;
108112 line
109113 } else {
110- format ! ( "{}" , ent . designator)
114+ designator. clone ( )
111115 } ;
112116 CompletionItem {
113- label : format ! ( "{} instantiation" , ent . designator ) ,
117+ label : format ! ( "{designator } instantiation" ) ,
114118 insert_text : Some ( template) ,
115119 insert_text_format : Some ( InsertTextFormat :: SNIPPET ) ,
116120 kind : Some ( CompletionItemKind :: MODULE ) ,
117121 ..Default :: default ( )
118122 }
119123 }
120124 vhdl_lang:: CompletionItem :: Attribute ( attribute) => CompletionItem {
121- label : format ! ( "{attribute}" ) ,
122- detail : Some ( format ! ( "{attribute}" ) ) ,
123- insert_text : Some ( format ! ( "{attribute}" ) ) ,
125+ label : self . insert_text ( attribute) ,
124126 kind : Some ( CompletionItemKind :: REFERENCE ) ,
125127 ..Default :: default ( )
126128 } ,
@@ -177,16 +179,15 @@ impl VHDLServer {
177179 }
178180 params
179181 }
180- }
181182
182- fn entity_to_completion_item ( ent : EntRef ) -> CompletionItem {
183- CompletionItem {
184- label : ent. designator . to_string ( ) ,
185- detail : Some ( ent. describe ( ) ) ,
186- kind : Some ( entity_kind_to_completion_kind ( ent. kind ( ) ) ) ,
187- data : serde_json:: to_value ( ent. id . to_raw ( ) ) . ok ( ) ,
188- insert_text : Some ( ent . designator . to_string ( ) ) ,
189- .. Default :: default ( )
183+ fn entity_to_completion_item ( & self , ent : EntRef ) -> CompletionItem {
184+ CompletionItem {
185+ label : self . insert_text ( & ent. designator ) ,
186+ detail : Some ( ent. describe ( ) ) ,
187+ kind : Some ( entity_kind_to_completion_kind ( ent. kind ( ) ) ) ,
188+ data : serde_json:: to_value ( ent. id . to_raw ( ) ) . ok ( ) ,
189+ .. Default :: default ( )
190+ }
190191 }
191192}
192193
0 commit comments