From be9ba2b392aaada4b0ce72f61fd664fc3d4021b5 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Fri, 29 Nov 2019 15:52:12 +0100 Subject: Move identifier check to analysis --- crates/ra_ide/src/lib.rs | 9 ++++++++- crates/ra_lsp_server/src/main_loop/handlers.rs | 12 +----------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'crates') 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::{ salsa::{self, ParallelDatabase}, 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}; @@ -470,6 +470,13 @@ impl Analysis { position: FilePosition, new_name: &str, ) -> Cancelable>> { + 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)) } 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::{ AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope, }; use ra_prof::profile; -use ra_syntax::{tokenize, AstNode, SyntaxKind, TextRange, TextUnit}; +use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use serde_json::to_value; @@ -480,8 +480,6 @@ pub fn handle_prepare_rename( let _p = profile("handle_prepare_rename"); 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 range = match optional_change { None => return Ok(None), @@ -506,14 +504,6 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result return Ok(None), -- cgit v1.2.3