mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Move identifier check to analysis
This commit is contained in:
parent
f081c9d94d
commit
be9ba2b392
2 changed files with 9 additions and 12 deletions
|
@ -56,7 +56,7 @@ use ra_db::{
|
||||||
salsa::{self, ParallelDatabase},
|
salsa::{self, ParallelDatabase},
|
||||||
CheckCanceled, Env, FileLoader, SourceDatabase,
|
CheckCanceled, Env, FileLoader, SourceDatabase,
|
||||||
};
|
};
|
||||||
use ra_syntax::{SourceFile, TextRange, TextUnit};
|
use ra_syntax::{tokenize, SourceFile, SyntaxKind, TextRange, TextUnit};
|
||||||
|
|
||||||
use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol};
|
use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol};
|
||||||
|
|
||||||
|
@ -470,6 +470,13 @@ impl Analysis {
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
new_name: &str,
|
new_name: &str,
|
||||||
) -> Cancelable<Option<RangeInfo<SourceChange>>> {
|
) -> Cancelable<Option<RangeInfo<SourceChange>>> {
|
||||||
|
let tokens = tokenize(new_name);
|
||||||
|
if tokens.len() != 1
|
||||||
|
|| (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
self.with_db(|db| references::rename(db, position, new_name))
|
self.with_db(|db| references::rename(db, position, new_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{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;
|
||||||
|
@ -480,8 +480,6 @@ pub fn handle_prepare_rename(
|
||||||
let _p = profile("handle_prepare_rename");
|
let _p = profile("handle_prepare_rename");
|
||||||
let position = params.try_conv_with(&world)?;
|
let position = params.try_conv_with(&world)?;
|
||||||
|
|
||||||
// We support renaming references like handle_rename does.
|
|
||||||
// In the future we may want to reject the renaming of things like keywords here too.
|
|
||||||
let optional_change = world.analysis().rename(position, "dummy")?;
|
let optional_change = world.analysis().rename(position, "dummy")?;
|
||||||
let range = match optional_change {
|
let range = match optional_change {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
|
@ -506,14 +504,6 @@ 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 && tokens[0].kind != SyntaxKind::UNDERSCORE)
|
|
||||||
{
|
|
||||||
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