mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Only allow renames to valid identifiers
This commit is contained in:
parent
8b278b1ab6
commit
9c764cb966
1 changed files with 7 additions and 1 deletions
|
@ -13,7 +13,7 @@ use ra_ide::{
|
||||||
AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope,
|
AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope,
|
||||||
};
|
};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
|
@ -506,6 +506,12 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only rename to valid identifiers
|
||||||
|
let tokens = tokenize(¶ms.new_name);
|
||||||
|
if tokens.len() != 1 || tokens[0].kind != SyntaxKind::IDENT {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
let optional_change = world.analysis().rename(position, &*params.new_name)?;
|
let optional_change = world.analysis().rename(position, &*params.new_name)?;
|
||||||
let change = match optional_change {
|
let change = match optional_change {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue