diff options
author | Wilco Kusee <[email protected]> | 2019-11-29 14:14:42 +0000 |
---|---|---|
committer | Wilco Kusee <[email protected]> | 2019-11-29 14:14:53 +0000 |
commit | 9c764cb966cd62d8eaa83fbb7d91646a850dc256 (patch) | |
tree | 46f572272a2567f90c5b8e004bb75998df155bd2 /crates | |
parent | 8b278b1ab660df0728508e45e88ac769a2e03a58 (diff) |
Only allow renames to valid identifiers
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c81fa7f67..137f26302 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -13,7 +13,7 @@ use ra_ide::{ | |||
13 | AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope, | 13 | AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope, |
14 | }; | 14 | }; |
15 | use ra_prof::profile; | 15 | use ra_prof::profile; |
16 | use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; | 16 | use ra_syntax::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit}; |
17 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::FxHashMap; |
18 | use serde::{Deserialize, Serialize}; | 18 | use serde::{Deserialize, Serialize}; |
19 | use serde_json::to_value; | 19 | use serde_json::to_value; |
@@ -506,6 +506,12 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio | |||
506 | .into()); | 506 | .into()); |
507 | } | 507 | } |
508 | 508 | ||
509 | // Only rename to valid identifiers | ||
510 | let tokens = tokenize(¶ms.new_name); | ||
511 | if tokens.len() != 1 || tokens[0].kind != SyntaxKind::IDENT { | ||
512 | return Ok(None); | ||
513 | } | ||
514 | |||
509 | let optional_change = world.analysis().rename(position, &*params.new_name)?; | 515 | let optional_change = world.analysis().rename(position, &*params.new_name)?; |
510 | let change = match optional_change { | 516 | let change = match optional_change { |
511 | None => return Ok(None), | 517 | None => return Ok(None), |