aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/references/rename.rs3
-rw-r--r--crates/rust-analyzer/src/handlers.rs14
-rw-r--r--crates/rust-analyzer/src/to_proto.rs7
3 files changed, 10 insertions, 14 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 5207388b5..c3ae568c2 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -1,7 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use std::{ 2use std::{
3 convert::TryInto, 3 convert::TryInto,
4 error::Error,
5 fmt::{self, Display}, 4 fmt::{self, Display},
6}; 5};
7 6
@@ -35,8 +34,6 @@ impl fmt::Display for RenameError {
35 } 34 }
36} 35}
37 36
38impl Error for RenameError {}
39
40macro_rules! format_err { 37macro_rules! format_err {
41 ($fmt:expr) => {RenameError(format!($fmt))}; 38 ($fmt:expr) => {RenameError(format!($fmt))};
42 ($fmt:expr, $($arg:tt)+) => {RenameError(format!($fmt, $($arg)+))} 39 ($fmt:expr, $($arg:tt)+) => {RenameError(format!($fmt, $($arg)+))}
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 2cc57f022..70dd51911 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -773,7 +773,8 @@ pub(crate) fn handle_prepare_rename(
773 let _p = profile::span("handle_prepare_rename"); 773 let _p = profile::span("handle_prepare_rename");
774 let position = from_proto::file_position(&snap, params)?; 774 let position = from_proto::file_position(&snap, params)?;
775 775
776 let change = snap.analysis.prepare_rename(position)??; 776 let change = snap.analysis.prepare_rename(position)?.map_err(to_proto::rename_error)?;
777
777 let line_index = snap.analysis.file_line_index(position.file_id)?; 778 let line_index = snap.analysis.file_line_index(position.file_id)?;
778 let range = to_proto::range(&line_index, change.range); 779 let range = to_proto::range(&line_index, change.range);
779 Ok(Some(PrepareRenameResponse::Range(range))) 780 Ok(Some(PrepareRenameResponse::Range(range)))
@@ -786,15 +787,8 @@ pub(crate) fn handle_rename(
786 let _p = profile::span("handle_rename"); 787 let _p = profile::span("handle_rename");
787 let position = from_proto::file_position(&snap, params.text_document_position)?; 788 let position = from_proto::file_position(&snap, params.text_document_position)?;
788 789
789 if params.new_name.is_empty() { 790 let change =
790 return Err(LspError::new( 791 snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?;
791 ErrorCode::InvalidParams as i32,
792 "New Name cannot be empty".into(),
793 )
794 .into());
795 }
796
797 let change = snap.analysis.rename(position, &*params.new_name)??;
798 let workspace_edit = to_proto::workspace_edit(&snap, change.info)?; 792 let workspace_edit = to_proto::workspace_edit(&snap, change.info)?;
799 Ok(Some(workspace_edit)) 793 Ok(Some(workspace_edit))
800} 794}
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index bdddca9da..a7ff8975a 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -8,7 +8,8 @@ use ide::{
8 Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId, 8 Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel, 9 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
10 InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess, 10 InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
11 Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize, 11 RenameError, Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange,
12 TextSize,
12}; 13};
13use itertools::Itertools; 14use itertools::Itertools;
14 15
@@ -855,6 +856,10 @@ pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent {
855 lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value } 856 lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value }
856} 857}
857 858
859pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
860 crate::LspError { code: lsp_server::ErrorCode::InvalidParams as i32, message: err.to_string() }
861}
862
858#[cfg(test)] 863#[cfg(test)]
859mod tests { 864mod tests {
860 use ide::Analysis; 865 use ide::Analysis;