mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 12:43:36 +00:00
Don't show internal server error on rename
Doesn't quite work due to https://github.com/microsoft/vscode-languageserver-node/issues/730 Note that this intentionally removes `impl std::Error for RenameError` -- we nether want to blindly bubble the rename error.
This commit is contained in:
parent
52fa926f00
commit
f0e802f490
@ -1,7 +1,6 @@
|
||||
//! FIXME: write short doc here
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
error::Error,
|
||||
fmt::{self, Display},
|
||||
};
|
||||
|
||||
@ -34,8 +33,6 @@ impl fmt::Display for RenameError {
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for RenameError {}
|
||||
|
||||
macro_rules! format_err {
|
||||
($fmt:expr) => {RenameError(format!($fmt))};
|
||||
($fmt:expr, $($arg:tt)+) => {RenameError(format!($fmt, $($arg)+))}
|
||||
|
@ -773,7 +773,8 @@ pub(crate) fn handle_prepare_rename(
|
||||
let _p = profile::span("handle_prepare_rename");
|
||||
let position = from_proto::file_position(&snap, params)?;
|
||||
|
||||
let change = snap.analysis.prepare_rename(position)??;
|
||||
let change = snap.analysis.prepare_rename(position)?.map_err(to_proto::rename_error)?;
|
||||
|
||||
let line_index = snap.analysis.file_line_index(position.file_id)?;
|
||||
let range = to_proto::range(&line_index, change.range);
|
||||
Ok(Some(PrepareRenameResponse::Range(range)))
|
||||
@ -786,15 +787,8 @@ pub(crate) fn handle_rename(
|
||||
let _p = profile::span("handle_rename");
|
||||
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
||||
|
||||
if params.new_name.is_empty() {
|
||||
return Err(LspError::new(
|
||||
ErrorCode::InvalidParams as i32,
|
||||
"New Name cannot be empty".into(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
let change = snap.analysis.rename(position, &*params.new_name)??;
|
||||
let change =
|
||||
snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?;
|
||||
let workspace_edit = to_proto::workspace_edit(&snap, change.info)?;
|
||||
Ok(Some(workspace_edit))
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ use ide::{
|
||||
Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
|
||||
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
|
||||
InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
|
||||
Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize,
|
||||
RenameError, Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange,
|
||||
TextSize,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
@ -855,6 +856,10 @@ pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent {
|
||||
lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value }
|
||||
}
|
||||
|
||||
pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
|
||||
crate::LspError { code: lsp_server::ErrorCode::InvalidParams as i32, message: err.to_string() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ide::Analysis;
|
||||
|
Loading…
Reference in New Issue
Block a user