Skip to content

Commit be9ba2b

Browse files
committed
Move identifier check to analysis
1 parent f081c9d commit be9ba2b

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

crates/ra_ide/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use ra_db::{
5656
salsa::{self, ParallelDatabase},
5757
CheckCanceled, Env, FileLoader, SourceDatabase,
5858
};
59-
use ra_syntax::{SourceFile, TextRange, TextUnit};
59+
use ra_syntax::{tokenize, SourceFile, SyntaxKind, TextRange, TextUnit};
6060

6161
use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol};
6262

@@ -470,6 +470,13 @@ impl Analysis {
470470
position: FilePosition,
471471
new_name: &str,
472472
) -> 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+
473480
self.with_db(|db| references::rename(db, position, new_name))
474481
}
475482

crates/ra_lsp_server/src/main_loop/handlers.rs

Lines changed: 1 addition & 11 deletions
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::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit};
16+
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
1717
use rustc_hash::FxHashMap;
1818
use serde::{Deserialize, Serialize};
1919
use serde_json::to_value;
@@ -480,8 +480,6 @@ pub fn handle_prepare_rename(
480480
let _p = profile("handle_prepare_rename");
481481
let position = params.try_conv_with(&world)?;
482482

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.
485483
let optional_change = world.analysis().rename(position, "dummy")?;
486484
let range = match optional_change {
487485
None => return Ok(None),
@@ -506,14 +504,6 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
506504
.into());
507505
}
508506

509-
// Only rename to valid identifiers
510-
let tokens = tokenize(&params.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-
517507
let optional_change = world.analysis().rename(position, &*params.new_name)?;
518508
let change = match optional_change {
519509
None => return Ok(None),

0 commit comments

Comments
 (0)