diff options
-rw-r--r-- | crates/ra_ide/src/lib.rs | 9 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 12 |
2 files changed, 9 insertions, 12 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index d1bff4a76..1f88791d7 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -56,7 +56,7 @@ use ra_db::{ | |||
56 | salsa::{self, ParallelDatabase}, | 56 | salsa::{self, ParallelDatabase}, |
57 | CheckCanceled, Env, FileLoader, SourceDatabase, | 57 | CheckCanceled, Env, FileLoader, SourceDatabase, |
58 | }; | 58 | }; |
59 | use ra_syntax::{SourceFile, TextRange, TextUnit}; | 59 | use ra_syntax::{tokenize, SourceFile, SyntaxKind, TextRange, TextUnit}; |
60 | 60 | ||
61 | use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol}; | 61 | use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol}; |
62 | 62 | ||
@@ -470,6 +470,13 @@ impl Analysis { | |||
470 | position: FilePosition, | 470 | position: FilePosition, |
471 | new_name: &str, | 471 | new_name: &str, |
472 | ) -> Cancelable<Option<RangeInfo<SourceChange>>> { | 472 | ) -> Cancelable<Option<RangeInfo<SourceChange>>> { |
473 | let tokens = tokenize(new_name); | ||
474 | if tokens.len() != 1 | ||
475 | || (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE) | ||
476 | { | ||
477 | return Ok(None); | ||
478 | } | ||
479 | |||
473 | self.with_db(|db| references::rename(db, position, new_name)) | 480 | self.with_db(|db| references::rename(db, position, new_name)) |
474 | } | 481 | } |
475 | 482 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 0380788ac..ca47ff5e1 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::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit}; | 16 | use ra_syntax::{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; |
@@ -480,8 +480,6 @@ pub fn handle_prepare_rename( | |||
480 | let _p = profile("handle_prepare_rename"); | 480 | let _p = profile("handle_prepare_rename"); |
481 | let position = params.try_conv_with(&world)?; | 481 | let position = params.try_conv_with(&world)?; |
482 | 482 | ||
483 | // We support renaming references like handle_rename does. | ||
484 | // In the future we may want to reject the renaming of things like keywords here too. | ||
485 | let optional_change = world.analysis().rename(position, "dummy")?; | 483 | let optional_change = world.analysis().rename(position, "dummy")?; |
486 | let range = match optional_change { | 484 | let range = match optional_change { |
487 | None => return Ok(None), | 485 | None => return Ok(None), |
@@ -506,14 +504,6 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio | |||
506 | .into()); | 504 | .into()); |
507 | } | 505 | } |
508 | 506 | ||
509 | // Only rename to valid identifiers | ||
510 | let tokens = tokenize(¶ms.new_name); | ||
511 | if tokens.len() != 1 | ||
512 | || (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE) | ||
513 | { | ||
514 | return Ok(None); | ||
515 | } | ||
516 | |||
517 | let optional_change = world.analysis().rename(position, &*params.new_name)?; | 507 | let optional_change = world.analysis().rename(position, &*params.new_name)?; |
518 | let change = match optional_change { | 508 | let change = match optional_change { |
519 | None => return Ok(None), | 509 | None => return Ok(None), |