Skip to content

Commit

Permalink
feat: allow renames to begin with "@"
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed Nov 4, 2024
1 parent 0c3615b commit 6112e8a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
));
Expand All @@ -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(),
})],
});
});
Expand Down

0 comments on commit 6112e8a

Please sign in to comment.