diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-13 12:09:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-13 12:09:26 +0000 |
commit | f84f5cb0ea3c1b10fbe96038d0201975913425cc (patch) | |
tree | efabf4ed9338b7081ff2ceb4546c39c789275492 /crates | |
parent | e41b36302784fc2661b4be2e13cb9a54cfa08ac9 (diff) | |
parent | f0e802f4903cee864b193beb2ddcd50d6d9f60c7 (diff) |
Merge #7262
7262: Don't show internal server error on rename r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
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 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 |
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 | ||
@@ -35,8 +34,6 @@ impl fmt::Display for RenameError { | |||
35 | } | 34 | } |
36 | } | 35 | } |
37 | 36 | ||
38 | impl Error for RenameError {} | ||
39 | |||
40 | macro_rules! format_err { | 37 | macro_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 | }; |
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; |