aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src')
-rw-r--r--crates/rust-analyzer/src/config.rs3
-rw-r--r--crates/rust-analyzer/src/handlers.rs19
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs22
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--crates/rust-analyzer/src/to_proto.rs18
5 files changed, 59 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8f541976e..5c88c3a9b 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -10,10 +10,9 @@
10use std::{ffi::OsString, iter, path::PathBuf}; 10use std::{ffi::OsString, iter, path::PathBuf};
11 11
12use flycheck::FlycheckConfig; 12use flycheck::FlycheckConfig;
13use hir::PrefixKind;
14use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig}; 13use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig};
15use ide_db::helpers::{ 14use ide_db::helpers::{
16 insert_use::{InsertUseConfig, MergeBehavior}, 15 insert_use::{InsertUseConfig, MergeBehavior, PrefixKind},
17 SnippetCap, 16 SnippetCap,
18}; 17};
19use lsp_types::{ClientCapabilities, MarkupKind}; 18use lsp_types::{ClientCapabilities, MarkupKind};
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 880fea622..85e67554c 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1427,6 +1427,25 @@ pub(crate) fn handle_open_cargo_toml(
1427 Ok(Some(res)) 1427 Ok(Some(res))
1428} 1428}
1429 1429
1430pub(crate) fn handle_move_item(
1431 snap: GlobalStateSnapshot,
1432 params: lsp_ext::MoveItemParams,
1433) -> Result<Option<lsp_types::TextDocumentEdit>> {
1434 let _p = profile::span("handle_move_item");
1435 let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
1436 let range = from_proto::file_range(&snap, params.text_document, params.range)?;
1437
1438 let direction = match params.direction {
1439 lsp_ext::MoveItemDirection::Up => ide::Direction::Up,
1440 lsp_ext::MoveItemDirection::Down => ide::Direction::Down,
1441 };
1442
1443 match snap.analysis.move_item(range, direction)? {
1444 Some(text_edit) => Ok(Some(to_proto::text_document_edit(&snap, file_id, text_edit)?)),
1445 None => Ok(None),
1446 }
1447}
1448
1430fn to_command_link(command: lsp_types::Command, tooltip: String) -> lsp_ext::CommandLink { 1449fn to_command_link(command: lsp_types::Command, tooltip: String) -> lsp_ext::CommandLink {
1431 lsp_ext::CommandLink { tooltip: Some(tooltip), command } 1450 lsp_ext::CommandLink { tooltip: Some(tooltip), command }
1432} 1451}
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index efcdcd1d9..0e1fec209 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -402,3 +402,25 @@ pub(crate) enum CodeLensResolveData {
402pub fn supports_utf8(caps: &lsp_types::ClientCapabilities) -> bool { 402pub fn supports_utf8(caps: &lsp_types::ClientCapabilities) -> bool {
403 caps.offset_encoding.as_deref().unwrap_or_default().iter().any(|it| it == "utf-8") 403 caps.offset_encoding.as_deref().unwrap_or_default().iter().any(|it| it == "utf-8")
404} 404}
405
406pub enum MoveItem {}
407
408impl Request for MoveItem {
409 type Params = MoveItemParams;
410 type Result = Option<lsp_types::TextDocumentEdit>;
411 const METHOD: &'static str = "experimental/moveItem";
412}
413
414#[derive(Serialize, Deserialize, Debug)]
415#[serde(rename_all = "camelCase")]
416pub struct MoveItemParams {
417 pub direction: MoveItemDirection,
418 pub text_document: TextDocumentIdentifier,
419 pub range: Range,
420}
421
422#[derive(Serialize, Deserialize, Debug)]
423pub enum MoveItemDirection {
424 Up,
425 Down,
426}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index c63a0eaea..e88f16cc1 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -504,6 +504,7 @@ impl GlobalState {
504 .on::<lsp_ext::HoverRequest>(handlers::handle_hover) 504 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)
505 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs) 505 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)
506 .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml) 506 .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
507 .on::<lsp_ext::MoveItem>(handlers::handle_move_item)
507 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting) 508 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
508 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol) 509 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
509 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol) 510 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 1ddea9278..25169005f 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -658,6 +658,18 @@ pub(crate) fn goto_definition_response(
658 } 658 }
659} 659}
660 660
661pub(crate) fn text_document_edit(
662 snap: &GlobalStateSnapshot,
663 file_id: FileId,
664 edit: TextEdit,
665) -> Result<lsp_types::TextDocumentEdit> {
666 let text_document = optional_versioned_text_document_identifier(snap, file_id);
667 let line_index = snap.file_line_index(file_id)?;
668 let edits =
669 edit.into_iter().map(|it| lsp_types::OneOf::Left(text_edit(&line_index, it))).collect();
670 Ok(lsp_types::TextDocumentEdit { text_document, edits })
671}
672
661pub(crate) fn snippet_text_document_edit( 673pub(crate) fn snippet_text_document_edit(
662 snap: &GlobalStateSnapshot, 674 snap: &GlobalStateSnapshot,
663 is_snippet: bool, 675 is_snippet: bool,
@@ -1073,9 +1085,11 @@ pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
1073mod tests { 1085mod tests {
1074 use std::sync::Arc; 1086 use std::sync::Arc;
1075 1087
1076 use hir::PrefixKind;
1077 use ide::Analysis; 1088 use ide::Analysis;
1078 use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap}; 1089 use ide_db::helpers::{
1090 insert_use::{InsertUseConfig, PrefixKind},
1091 SnippetCap,
1092 };
1079 1093
1080 use super::*; 1094 use super::*;
1081 1095