From bc94bf95ce858ef247ebee006d50cfdc33f6bf5f Mon Sep 17 00:00:00 2001 From: darksv Date: Fri, 14 Sep 2018 19:26:48 +0200 Subject: correctly handle IDENTs when changed to contextual keywords --- crates/libsyntax2/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/src/lib.rs') diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index d124d3284..7c9fbc421 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -100,7 +100,12 @@ impl File { | RAW_STRING => { let text = get_text_after_edit(node, &edit); let tokens = tokenize(&text); - if tokens.len() != 1 || tokens[0].kind != node.kind() { + let token = match tokens[..] { + [token] if token.kind == node.kind() => token, + _ => return None, + }; + + if token.kind == IDENT && is_contextual_kw(&text) { return None; } @@ -167,6 +172,15 @@ fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomEdit) -> String { ) } +fn is_contextual_kw(text: &str) -> bool { + match text { + | "auto" + | "default" + | "union" => true, + _ => false, + } +} + fn find_reparsable_node(node: SyntaxNodeRef, range: TextRange) -> Option<(SyntaxNodeRef, fn(&mut Parser))> { let node = algo::find_covering_node(node, range); return algo::ancestors(node) -- cgit v1.2.3