diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/references/rename.rs | 3 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 7 |
3 files changed, 10 insertions, 14 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 3edc43e08..3db08e84c 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 |
2 | use std::{ | 2 | use std::{ |
3 | convert::TryInto, | 3 | convert::TryInto, |
4 | error::Error, | ||
5 | fmt::{self, Display}, | 4 | fmt::{self, Display}, |
6 | }; | 5 | }; |
7 | 6 | ||
@@ -34,8 +33,6 @@ impl fmt::Display for RenameError { | |||
34 | } | 33 | } |
35 | } | 34 | } |
36 | 35 | ||
37 | impl Error for RenameError {} | ||
38 | |||
39 | macro_rules! format_err { | 36 | macro_rules! format_err { |
40 | ($fmt:expr) => {RenameError(format!($fmt))}; | 37 | ($fmt:expr) => {RenameError(format!($fmt))}; |
41 | ($fmt:expr, $($arg:tt)+) => {RenameError(format!($fmt, $($arg)+))} | 38 | ($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 29cc9051e..a21571eea 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 | }; |
13 | use itertools::Itertools; | 14 | use 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 | ||
859 | pub(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)] |
859 | mod tests { | 864 | mod tests { |
860 | use ide::Analysis; | 865 | use ide::Analysis; |