mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Push identifier check to rename function
This commit is contained in:
parent
645df2b5f5
commit
b3856568af
2 changed files with 9 additions and 9 deletions
|
@ -56,7 +56,7 @@ use ra_db::{
|
|||
salsa::{self, ParallelDatabase},
|
||||
CheckCanceled, Env, FileLoader, SourceDatabase,
|
||||
};
|
||||
use ra_syntax::{tokenize, SourceFile, SyntaxKind, TextRange, TextUnit};
|
||||
use ra_syntax::{SourceFile, TextRange, TextUnit};
|
||||
|
||||
use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol};
|
||||
|
||||
|
@ -470,13 +470,6 @@ impl Analysis {
|
|||
position: FilePosition,
|
||||
new_name: &str,
|
||||
) -> 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))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use hir::ModuleSource;
|
||||
use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt};
|
||||
use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode};
|
||||
use ra_syntax::{algo::find_node_at_offset, ast, tokenize, AstNode, SyntaxKind, SyntaxNode};
|
||||
use ra_text_edit::TextEdit;
|
||||
|
||||
use crate::{
|
||||
|
@ -17,6 +17,13 @@ pub(crate) fn rename(
|
|||
position: FilePosition,
|
||||
new_name: &str,
|
||||
) -> Option<RangeInfo<SourceChange>> {
|
||||
let tokens = tokenize(new_name);
|
||||
if tokens.len() != 1
|
||||
|| (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let parse = db.parse(position.file_id);
|
||||
if let Some((ast_name, ast_module)) =
|
||||
find_name_and_module_at_offset(parse.tree().syntax(), position)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue