From aceb9d7fb0809ccf364514d9177342edea144c59 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 12 Dec 2019 21:47:54 +0800 Subject: Add token ids for all tt::Leaf --- crates/ra_hir_expand/src/builtin_derive.rs | 28 ++++++++++++++++++++++++---- crates/ra_hir_expand/src/quote.rs | 13 ++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index b26441253..62c60e336 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs @@ -97,11 +97,24 @@ fn parse_adt(tt: &tt::Subtree) -> Result { fn make_type_args(n: usize, bound: Vec) -> Vec { let mut result = Vec::::new(); - result.push(tt::Leaf::Punct(tt::Punct { char: '<', spacing: tt::Spacing::Alone }).into()); + result.push( + tt::Leaf::Punct(tt::Punct { + char: '<', + spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), + }) + .into(), + ); for i in 0..n { if i > 0 { - result - .push(tt::Leaf::Punct(tt::Punct { char: ',', spacing: tt::Spacing::Alone }).into()); + result.push( + tt::Leaf::Punct(tt::Punct { + char: ',', + spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), + }) + .into(), + ); } result.push( tt::Leaf::Ident(tt::Ident { @@ -112,7 +125,14 @@ fn make_type_args(n: usize, bound: Vec) -> Vec { ); result.extend(bound.iter().cloned()); } - result.push(tt::Leaf::Punct(tt::Punct { char: '>', spacing: tt::Spacing::Alone }).into()); + result.push( + tt::Leaf::Punct(tt::Punct { + char: '>', + spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), + }) + .into(), + ); result } diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs index aa8a5f23f..bce38cc67 100644 --- a/crates/ra_hir_expand/src/quote.rs +++ b/crates/ra_hir_expand/src/quote.rs @@ -29,6 +29,7 @@ macro_rules! __quote { tt::Leaf::Punct(tt::Punct { char: $first, spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), }).into() ] } @@ -40,10 +41,12 @@ macro_rules! __quote { tt::Leaf::Punct(tt::Punct { char: $first, spacing: tt::Spacing::Joint, + id: tt::TokenId::unspecified(), }).into(), tt::Leaf::Punct(tt::Punct { char: $sec, spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), }).into() ] } @@ -179,15 +182,15 @@ macro_rules! impl_to_to_tokentrees { } impl_to_to_tokentrees! { - u32 => self { tt::Literal{text: self.to_string().into()} }; - usize => self { tt::Literal{text: self.to_string().into()}}; - i32 => self { tt::Literal{text: self.to_string().into()}}; + u32 => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()} }; + usize => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()}}; + i32 => self { tt::Literal{text: self.to_string().into(), id: tt::TokenId::unspecified()}}; tt::Leaf => self { self }; tt::Literal => self { self }; tt::Ident => self { self }; tt::Punct => self { self }; - &str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into()}}; - String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into()}} + &str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}}; + String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}} } #[cfg(test)] -- cgit v1.2.3 From 59295854f892b0a8f42a6fbc80b04d1f1c695828 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 13 Dec 2019 01:41:44 +0800 Subject: Add token id to delims --- crates/ra_hir_expand/src/quote.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs index bce38cc67..49155fe62 100644 --- a/crates/ra_hir_expand/src/quote.rs +++ b/crates/ra_hir_expand/src/quote.rs @@ -16,7 +16,10 @@ macro_rules! __quote { { let children = $crate::__quote!($($tt)*); let subtree = tt::Subtree { - delimiter: Some(tt::Delimiter::$delim), + delimiter: Some(tt::Delimiter { + kind: tt::DelimiterKind::$delim, + id: tt::TokenId::unspecified(), + }), token_trees: $crate::quote::IntoTt::to_tokens(children), }; subtree @@ -257,8 +260,13 @@ mod tests { let fields = fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees.clone()).flatten(); - let list = - tt::Subtree { delimiter: Some(tt::Delimiter::Brace), token_trees: fields.collect() }; + let list = tt::Subtree { + delimiter: Some(tt::Delimiter { + kind: tt::DelimiterKind::Brace, + id: tt::TokenId::unspecified(), + }), + token_trees: fields.collect(), + }; let quoted = quote! { impl Clone for #struct_name { -- cgit v1.2.3 From 320416d7561e9926ecbbc392cc2efd48740610e0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 13 Dec 2019 23:55:51 +0800 Subject: Add TokenTextRange --- crates/ra_hir_expand/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index cb4e1950b..720a29ea5 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -227,7 +227,7 @@ impl ExpansionInfo { let token_id = self.macro_arg.1.token_by_range(range)?; let token_id = self.macro_def.0.map_id_down(token_id); - let range = self.exp_map.range_by_token(token_id)?; + let range = self.exp_map.range_by_token(token_id)?.range(token.value.kind())?; let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; @@ -248,7 +248,7 @@ impl ExpansionInfo { } }; - let range = token_map.range_by_token(token_id)?; + let range = token_map.range_by_token(token_id)?.range(token.value.kind())?; let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start()) .into_token()?; Some((tt.with_value(token), origin)) -- cgit v1.2.3 From 2ea1cfd7804dd57d63196e71f66c22e56cfd79a8 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 18 Dec 2019 11:36:10 +0800 Subject: Rename range to by_kind --- crates/ra_hir_expand/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_expand/src') diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 720a29ea5..2fa5d5140 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs @@ -227,7 +227,7 @@ impl ExpansionInfo { let token_id = self.macro_arg.1.token_by_range(range)?; let token_id = self.macro_def.0.map_id_down(token_id); - let range = self.exp_map.range_by_token(token_id)?.range(token.value.kind())?; + let range = self.exp_map.range_by_token(token_id)?.by_kind(token.value.kind())?; let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; @@ -248,7 +248,7 @@ impl ExpansionInfo { } }; - let range = token_map.range_by_token(token_id)?.range(token.value.kind())?; + let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?; let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start()) .into_token()?; Some((tt.with_value(token), origin)) -- cgit v1.2.3