@@ -16,7 +16,7 @@ use ide_db::{
16
16
helpers:: { item_name, SnippetCap } ,
17
17
RootDatabase , SymbolKind ,
18
18
} ;
19
- use syntax:: TextRange ;
19
+ use syntax:: { SyntaxKind , TextRange } ;
20
20
21
21
use crate :: {
22
22
context:: { PathCompletionContext , PathKind } ,
@@ -91,14 +91,18 @@ pub(crate) fn render_field(
91
91
) ;
92
92
item. set_relevance ( CompletionRelevance {
93
93
type_match : compute_type_match ( ctx. completion , ty) ,
94
- exact_name_match : compute_exact_name_match ( ctx. completion , & name) ,
94
+ exact_name_match : compute_exact_name_match ( ctx. completion , name. as_str ( ) ) ,
95
95
..CompletionRelevance :: default ( )
96
96
} ) ;
97
97
item. kind ( SymbolKind :: Field )
98
98
. detail ( ty. display ( ctx. db ( ) ) . to_string ( ) )
99
99
. set_documentation ( field. docs ( ctx. db ( ) ) )
100
100
. set_deprecated ( is_deprecated)
101
- . lookup_by ( name) ;
101
+ . lookup_by ( name. as_str ( ) ) ;
102
+ let is_keyword = SyntaxKind :: from_keyword ( name. as_str ( ) ) . is_some ( ) ;
103
+ if is_keyword && !matches ! ( name. as_str( ) , "self" | "crate" | "super" | "Self" ) {
104
+ item. insert_text ( String :: from ( "r#" ) + name. as_str ( ) ) ;
105
+ }
102
106
if let Some ( _ref_match) = compute_ref_match ( ctx. completion , ty) {
103
107
// FIXME
104
108
// For now we don't properly calculate the edits for ref match
@@ -821,6 +825,23 @@ struct ManualVtable { f: fn(u8, u8) }
821
825
fn main() -> ManualVtable {
822
826
ManualVtable { f: foo }
823
827
}
828
+ "# ,
829
+ ) ;
830
+ check_edit (
831
+ "type" ,
832
+ r#"
833
+ struct RawIdentTable { r#type: u32 }
834
+
835
+ fn main() -> RawIdentTable {
836
+ RawIdentTable { t$0: 42 }
837
+ }
838
+ "# ,
839
+ r#"
840
+ struct RawIdentTable { r#type: u32 }
841
+
842
+ fn main() -> RawIdentTable {
843
+ RawIdentTable { r#type: 42 }
844
+ }
824
845
"# ,
825
846
) ;
826
847
}
0 commit comments