From 6112e8a8e35c5138f44c6a452e415bf5ae302d3b Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Mon, 4 Nov 2024 10:56:43 -0800 Subject: [PATCH] feat: allow renames to begin with "@" --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0ddf896..6eea697 100644 --- a/src/main.rs +++ b/src/main.rs @@ -666,9 +666,13 @@ impl LanguageServer for Backend { }; let query = Query::new(&QUERY_LANGUAGE, "(capture) @cap").unwrap(); let mut cursor = QueryCursor::new(); - let new_name = params.new_name; + // Allow the new name to begin with "@" + let new_name = params + .new_name + .strip_prefix('@') + .unwrap_or(params.new_name.as_str()); let identifier_pattern = Regex::new(r#"^[a-zA-Z0-9.\-_\$]+$"#).unwrap(); - if !identifier_pattern.is_match(new_name.as_str()) { + if !identifier_pattern.is_match(new_name) { return Err(jsonrpc::Error::invalid_params( "New name is not a valid identifier", )); @@ -694,7 +698,7 @@ impl LanguageServer for Backend { }, edits: vec![OneOf::Left(TextEdit { range: elem.range, - new_text: new_name.clone(), + new_text: new_name.to_owned(), })], }); });