Skip to content

Commit 9c764cb

Browse files
committed
Only allow renames to valid identifiers
1 parent 8b278b1 commit 9c764cb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/ra_lsp_server/src/main_loop/handlers.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ra_ide::{
1313
AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope,
1414
};
1515
use ra_prof::profile;
16-
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
16+
use ra_syntax::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit};
1717
use rustc_hash::FxHashMap;
1818
use serde::{Deserialize, Serialize};
1919
use serde_json::to_value;
@@ -506,6 +506,12 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
506506
.into());
507507
}
508508

509+
// Only rename to valid identifiers
510+
let tokens = tokenize(&params.new_name);
511+
if tokens.len() != 1 || tokens[0].kind != SyntaxKind::IDENT {
512+
return Ok(None);
513+
}
514+
509515
let optional_change = world.analysis().rename(position, &*params.new_name)?;
510516
let change = match optional_change {
511517
None => return Ok(None),

0 commit comments

Comments
 (0)