mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Move cursor position when using item movers
This commit is contained in:
parent
10a243ea55
commit
30aae2cefb
7 changed files with 83 additions and 74 deletions
|
@ -1410,7 +1410,7 @@ pub(crate) fn handle_open_cargo_toml(
|
|||
pub(crate) fn handle_move_item(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::MoveItemParams,
|
||||
) -> Result<Option<lsp_types::TextDocumentEdit>> {
|
||||
) -> Result<Vec<lsp_ext::SnippetTextEdit>> {
|
||||
let _p = profile::span("handle_move_item");
|
||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let range = from_proto::file_range(&snap, params.text_document, params.range)?;
|
||||
|
@ -1421,8 +1421,11 @@ pub(crate) fn handle_move_item(
|
|||
};
|
||||
|
||||
match snap.analysis.move_item(range, direction)? {
|
||||
Some(text_edit) => Ok(Some(to_proto::text_document_edit(&snap, file_id, text_edit)?)),
|
||||
None => Ok(None),
|
||||
Some(text_edit) => {
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
Ok(to_proto::snippet_text_edit_vec(&line_index, true, text_edit))
|
||||
}
|
||||
None => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -407,7 +407,7 @@ pub enum MoveItem {}
|
|||
|
||||
impl Request for MoveItem {
|
||||
type Params = MoveItemParams;
|
||||
type Result = Option<lsp_types::TextDocumentEdit>;
|
||||
type Result = Vec<SnippetTextEdit>;
|
||||
const METHOD: &'static str = "experimental/moveItem";
|
||||
}
|
||||
|
||||
|
|
|
@ -688,18 +688,6 @@ pub(crate) fn goto_definition_response(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn text_document_edit(
|
||||
snap: &GlobalStateSnapshot,
|
||||
file_id: FileId,
|
||||
edit: TextEdit,
|
||||
) -> Result<lsp_types::TextDocumentEdit> {
|
||||
let text_document = optional_versioned_text_document_identifier(snap, file_id);
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let edits =
|
||||
edit.into_iter().map(|it| lsp_types::OneOf::Left(text_edit(&line_index, it))).collect();
|
||||
Ok(lsp_types::TextDocumentEdit { text_document, edits })
|
||||
}
|
||||
|
||||
pub(crate) fn snippet_text_document_edit(
|
||||
snap: &GlobalStateSnapshot,
|
||||
is_snippet: bool,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue