diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 8f91f64a69..15f4978367 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -123,6 +123,14 @@ pub(crate) fn handle_view_hir( Ok(res) } +pub(crate) fn handle_view_file_text( + snap: GlobalStateSnapshot, + params: lsp_types::TextDocumentIdentifier, +) -> Result { + let file_id = from_proto::file_id(&snap, ¶ms.uri)?; + Ok(snap.analysis.file_text(file_id)?.to_string()) +} + pub(crate) fn handle_view_item_tree( snap: GlobalStateSnapshot, params: lsp_ext::ViewItemTreeParams, diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 2e131eeac9..b638a57111 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -70,6 +70,14 @@ impl Request for ViewHir { const METHOD: &'static str = "rust-analyzer/viewHir"; } +pub enum ViewFileText {} + +impl Request for ViewFileText { + type Params = lsp_types::TextDocumentIdentifier; + type Result = String; + const METHOD: &'static str = "rust-analyzer/viewFileText"; +} + #[derive(Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct ViewCrateGraphParams { diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index b62a830803..2d898d76a6 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -590,6 +590,7 @@ impl GlobalState { .on::(handlers::handle_analyzer_status) .on::(handlers::handle_syntax_tree) .on::(handlers::handle_view_hir) + .on::(handlers::handle_view_file_text) .on::(handlers::handle_view_crate_graph) .on::(handlers::handle_view_item_tree) .on::(handlers::handle_expand_macro) diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 3091bdcbf0..516d1caccc 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@