@@ -16,7 +16,7 @@ use ide_db::{
1616 helpers:: { item_name, SnippetCap } ,
1717 RootDatabase , SymbolKind ,
1818} ;
19- use syntax:: TextRange ;
19+ use syntax:: { SyntaxKind , TextRange } ;
2020
2121use crate :: {
2222 context:: { PathCompletionContext , PathKind } ,
@@ -91,14 +91,18 @@ pub(crate) fn render_field(
9191 ) ;
9292 item. set_relevance ( CompletionRelevance {
9393 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 ( ) ) ,
9595 ..CompletionRelevance :: default ( )
9696 } ) ;
9797 item. kind ( SymbolKind :: Field )
9898 . detail ( ty. display ( ctx. db ( ) ) . to_string ( ) )
9999 . set_documentation ( field. docs ( ctx. db ( ) ) )
100100 . 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+ }
102106 if let Some ( _ref_match) = compute_ref_match ( ctx. completion , ty) {
103107 // FIXME
104108 // For now we don't properly calculate the edits for ref match
@@ -821,6 +825,23 @@ struct ManualVtable { f: fn(u8, u8) }
821825fn main() -> ManualVtable {
822826 ManualVtable { f: foo }
823827}
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+ }
824845"# ,
825846 ) ;
826847 }
0 commit comments