From c55a2dbc1de8ba42df57b70f652eb6a0c0bbc9f6 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 25 Apr 2019 23:12:57 +0800 Subject: Fix more bugs --- crates/ra_mbe/src/syntax_bridge.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/ra_mbe/src/syntax_bridge.rs') diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 9cca19dbb..e0f228ce9 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -123,6 +123,11 @@ fn convert_tt( global_offset: TextUnit, tt: &SyntaxNode, ) -> Option { + // This tree is empty + if tt.first_child_or_token().is_none() { + return Some(tt::Subtree { token_trees: vec![], delimiter: tt::Delimiter::None }); + } + let first_child = tt.first_child_or_token()?; let last_child = tt.last_child_or_token()?; let (delimiter, skip_first) = match (first_child.kind(), last_child.kind()) { @@ -233,7 +238,16 @@ impl<'a, Q: Querier> TreeSink for TtTreeSink<'a, Q> { self.text_pos += TextUnit::of_str(&self.buf); let text = SmolStr::new(self.buf.as_str()); self.buf.clear(); - self.inner.token(kind, text) + self.inner.token(kind, text); + + // // Add a white space to token + // let (last_kind, _, last_joint_to_next ) = self.src_querier.token(self.token_pos-n_tokens as usize); + // if !last_joint_to_next && last_kind.is_punct() { + // let (cur_kind, _, _ ) = self.src_querier.token(self.token_pos); + // if cur_kind.is_punct() { + // self.inner.token(WHITESPACE, " ".into()); + // } + // } } fn start_node(&mut self, kind: SyntaxKind) { -- cgit v1.2.3