mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Item up and down movers
This commit is contained in:
parent
d704750ba9
commit
7d60458495
11 changed files with 536 additions and 1 deletions
|
@ -1424,6 +1424,25 @@ pub(crate) fn handle_open_cargo_toml(
|
|||
Ok(Some(res))
|
||||
}
|
||||
|
||||
pub(crate) fn handle_move_item(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::MoveItemParams,
|
||||
) -> Result<Option<lsp_types::TextDocumentEdit>> {
|
||||
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)?;
|
||||
|
||||
let direction = match params.direction {
|
||||
lsp_ext::MoveItemDirection::Up => ide::Direction::Up,
|
||||
lsp_ext::MoveItemDirection::Down => ide::Direction::Down,
|
||||
};
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_command_link(command: lsp_types::Command, tooltip: String) -> lsp_ext::CommandLink {
|
||||
lsp_ext::CommandLink { tooltip: Some(tooltip), command }
|
||||
}
|
||||
|
|
|
@ -402,3 +402,25 @@ pub(crate) enum CodeLensResolveData {
|
|||
pub fn supports_utf8(caps: &lsp_types::ClientCapabilities) -> bool {
|
||||
caps.offset_encoding.as_deref().unwrap_or_default().iter().any(|it| it == "utf-8")
|
||||
}
|
||||
|
||||
pub enum MoveItem {}
|
||||
|
||||
impl Request for MoveItem {
|
||||
type Params = MoveItemParams;
|
||||
type Result = Option<lsp_types::TextDocumentEdit>;
|
||||
const METHOD: &'static str = "experimental/moveItem";
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MoveItemParams {
|
||||
pub direction: MoveItemDirection,
|
||||
pub text_document: TextDocumentIdentifier,
|
||||
pub range: Range,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum MoveItemDirection {
|
||||
Up,
|
||||
Down,
|
||||
}
|
||||
|
|
|
@ -507,6 +507,7 @@ impl GlobalState {
|
|||
.on::<lsp_ext::HoverRequest>(handlers::handle_hover)
|
||||
.on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)
|
||||
.on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
|
||||
.on::<lsp_ext::MoveItem>(handlers::handle_move_item)
|
||||
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
|
||||
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
|
||||
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)
|
||||
|
|
|
@ -658,6 +658,18 @@ 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